IAnsiResponseParser.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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">
  21. /// <see langword="true"/> if you want this to persist permanently
  22. /// and be raised for every event matching the <paramref name="terminator"/>.
  23. /// </param>
  24. /// <param name="response">Callback to invoke when the response is seen in console input.</param>
  25. /// <exception cref="ArgumentException">
  26. /// If trying to register a persistent request for a terminator
  27. /// that already has one.
  28. /// exists.
  29. /// </exception>
  30. void ExpectResponse (string terminator, Action<string> response, bool persistent);
  31. /// <summary>
  32. /// Returns true if there is an existing expectation (i.e. we are waiting a response
  33. /// from console) for the given <paramref name="terminator"/>.
  34. /// </summary>
  35. /// <param name="terminator"></param>
  36. /// <returns></returns>
  37. bool IsExpecting (string terminator);
  38. /// <summary>
  39. /// Removes callback and expectation that we will get a response for the
  40. /// given <pararef name="requestTerminator"/>. Use to give up on very old
  41. /// requests e.g. if you want to send a different one with the same terminator.
  42. /// </summary>
  43. /// <param name="requestTerminator"></param>
  44. /// <param name="persistent">
  45. /// <see langword="true"/> if you want to remove a persistent
  46. /// request listener.
  47. /// </param>
  48. void StopExpecting (string requestTerminator, bool persistent);
  49. }