AnsiEscapeSequenceRequest.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// Describes an ongoing ANSI request sent to the console.
  5. /// Use <see cref="ResponseReceived"/> to handle the response
  6. /// when console answers the request.
  7. /// </summary>
  8. public class AnsiEscapeSequenceRequest
  9. {
  10. /// <summary>
  11. /// Request to send e.g. see
  12. /// <see>
  13. /// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Request</cref>
  14. /// </see>
  15. /// </summary>
  16. public required string Request { get; init; }
  17. /// <summary>
  18. /// Invoked when the console responds with an ANSI response code that matches the
  19. /// <see cref="Terminator"/>
  20. /// </summary>
  21. public Action<string> ResponseReceived;
  22. /// <summary>
  23. /// Invoked if the console fails to responds to the ANSI response code
  24. /// </summary>
  25. public Action? Abandoned;
  26. /// <summary>
  27. /// <para>
  28. /// The terminator that uniquely identifies the type of response as responded
  29. /// by the console. e.g. for
  30. /// <see>
  31. /// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Request</cref>
  32. /// </see>
  33. /// the terminator is
  34. /// <see>
  35. /// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Terminator</cref>
  36. /// </see>
  37. /// .
  38. /// </para>
  39. /// <para>
  40. /// After sending a request, the first response with matching terminator will be matched
  41. /// to the oldest outstanding request.
  42. /// </para>
  43. /// </summary>
  44. public required string Terminator { get; init; }
  45. /// <summary>
  46. /// Sends the <see cref="Request"/> to the raw output stream of the current <see cref="ConsoleDriver"/>.
  47. /// Only call this method from the main UI thread. You should use <see cref="AnsiRequestScheduler"/> if
  48. /// sending many requests.
  49. /// </summary>
  50. public void Send () { Application.Driver?.RawWrite (Request); }
  51. /// <summary>
  52. /// The value expected in the response e.g.
  53. /// <see>
  54. /// <cref>EscSeqUtils.CSI_ReportTerminalSizeInChars.Value</cref>
  55. /// </see>
  56. /// which will have a 't' as terminator but also other different request may return the same terminator with a
  57. /// different value.
  58. /// </summary>
  59. public string? Value { get; init; }
  60. }