IAnsiResponseParser.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. namespace Terminal.Gui.Drivers;
  2. /// <summary>
  3. /// When implemented in a derived class, allows watching an input stream of characters
  4. /// (i.e. console input) for ANSI response sequences (mouse input, cursor, query responses etc.).
  5. /// </summary>
  6. public interface IAnsiResponseParser
  7. {
  8. /// <summary>
  9. /// Current state of the parser based on what sequence of characters it has
  10. /// read from the console input stream.
  11. /// </summary>
  12. AnsiResponseParserState State { get; }
  13. /// <summary>
  14. /// Notifies the parser that you are expecting a response to come in
  15. /// with the given <paramref name="terminator"/> (i.e. because you have
  16. /// sent an ANSI request out).
  17. /// </summary>
  18. /// <param name="terminator">The terminator you expect to see on response.</param>
  19. /// <param name="response">Callback to invoke when the response is seen in console input.</param>
  20. /// <param name="abandoned"></param>
  21. /// <param name="persistent">
  22. /// <see langword="true"/> if you want this to persist permanently
  23. /// and be raised for every event matching the <paramref name="terminator"/>.
  24. /// </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, Action? abandoned, 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. }