IAnsiResponseParser.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// When implemented in a derived class, allows watching an input stream of characters
  5. /// (i.e. console input) for ANSI response sequences.
  6. /// </summary>
  7. public interface IAnsiResponseParser
  8. {
  9. /// <summary>
  10. /// Current state of the parser based on what sequence of characters it has
  11. /// read from the console input stream.
  12. /// </summary>
  13. AnsiResponseParserState State { get; }
  14. /// <summary>
  15. /// Notifies the parser that you are expecting a response to come in
  16. /// with the given <paramref name="terminator"/> (i.e. because you have
  17. /// sent an ANSI request out).
  18. /// </summary>
  19. /// <param name="terminator">The terminator you expect to see on response.</param>
  20. /// <param name="persistent"><see langword="true"/> if you want this to persist permanently
  21. /// and be raised for every event matching the <paramref name="terminator"/>.</param>
  22. /// <param name="response">Callback to invoke when the response is seen in console input.</param>
  23. /// <exception cref="ArgumentException">If trying to register a persistent request for a terminator
  24. /// that already has one.
  25. /// exists.</exception>
  26. void ExpectResponse (string terminator, Action<string> response, bool persistent);
  27. /// <summary>
  28. /// Returns true if there is an existing expectation (i.e. we are waiting a response
  29. /// from console) for the given <paramref name="terminator"/>.
  30. /// </summary>
  31. /// <param name="terminator"></param>
  32. /// <returns></returns>
  33. bool IsExpecting (string terminator);
  34. /// <summary>
  35. /// Removes callback and expectation that we will get a response for the
  36. /// given <pararef name="requestTerminator"/>. Use to give up on very old
  37. /// requests e.g. if you want to send a different one with the same terminator.
  38. /// </summary>
  39. /// <param name="requestTerminator"></param>
  40. /// <param name="persistent"><see langword="true"/> if you want to remove a persistent
  41. /// request listener.</param>
  42. void StopExpecting (string requestTerminator, bool persistent);
  43. }