IAnsiResponseParser.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. /// Called when parser is told to <see cref="StopExpecting"/> a response for a given request
  11. /// </summary>
  12. public event EventHandler<EventArgs<string>> StoppedExpecting;
  13. /// <summary>
  14. /// Current state of the parser based on what sequence of characters it has
  15. /// read from the console input stream.
  16. /// </summary>
  17. AnsiResponseParserState State { get; }
  18. /// <summary>
  19. /// Notifies the parser that you are expecting a response to come in
  20. /// with the given <paramref name="terminator"/> (i.e. because you have
  21. /// sent an ANSI request out).
  22. /// </summary>
  23. /// <param name="terminator">The terminator you expect to see on response.</param>
  24. /// <param name="response">Callback to invoke when the response is seen in console input.</param>
  25. /// <param name="abandoned"></param>
  26. /// <param name="persistent">
  27. /// <see langword="true"/> if you want this to persist permanently
  28. /// and be raised for every event matching the <paramref name="terminator"/>.
  29. /// </param>
  30. /// <exception cref="ArgumentException">
  31. /// If trying to register a persistent request for a terminator
  32. /// that already has one.
  33. /// exists.
  34. /// </exception>
  35. void ExpectResponse (string terminator, Action<string> response,Action? abandoned, bool persistent);
  36. /// <summary>
  37. /// Returns true if there is an existing expectation (i.e. we are waiting a response
  38. /// from console) for the given <paramref name="terminator"/>.
  39. /// </summary>
  40. /// <param name="terminator"></param>
  41. /// <returns></returns>
  42. bool IsExpecting (string terminator);
  43. /// <summary>
  44. /// Removes callback and expectation that we will get a response for the
  45. /// given <pararef name="requestTerminator"/>. Use to give up on very old
  46. /// requests e.g. if you want to send a different one with the same terminator.
  47. /// </summary>
  48. /// <param name="requestTerminator"></param>
  49. /// <param name="persistent">
  50. /// <see langword="true"/> if you want to remove a persistent
  51. /// request listener.
  52. /// </param>
  53. void StopExpecting (string requestTerminator, bool persistent);
  54. }