IAnsiResponseParser.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. void ExpectResponse (string terminator, Action<string> response);
  22. /// <summary>
  23. /// Returns true if there is an existing expectation (i.e. we are waiting a response
  24. /// from console) for the given <paramref name="requestTerminator"/>.
  25. /// </summary>
  26. /// <param name="requestTerminator"></param>
  27. /// <returns></returns>
  28. bool IsExpecting (string requestTerminator);
  29. /// <summary>
  30. /// Removes callback and expectation that we will get a response for the
  31. /// given <pararef name="requestTerminator"/>. Use to give up on very old
  32. /// requests e.g. if you want to send a different one with the same terminator.
  33. /// </summary>
  34. /// <param name="requestTerminator"></param>
  35. void StopExpecting (string requestTerminator);
  36. }