IAnsiResponseParser.cs 2.3 KB

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