AnsiEscapeSequenceRequest.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. /// <para>
  24. /// The terminator that uniquely identifies the type of response as responded
  25. /// by the console. e.g. for
  26. /// <see>
  27. /// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Request</cref>
  28. /// </see>
  29. /// the terminator is
  30. /// <see>
  31. /// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Terminator</cref>
  32. /// </see>
  33. /// .
  34. /// </para>
  35. /// <para>
  36. /// After sending a request, the first response with matching terminator will be matched
  37. /// to the oldest outstanding request.
  38. /// </para>
  39. /// </summary>
  40. public required string Terminator { get; init; }
  41. /// <summary>
  42. /// Sends the <see cref="Request"/> to the raw output stream of the current <see cref="ConsoleDriver"/>.
  43. /// Only call this method from the main UI thread. You should use <see cref="AnsiRequestScheduler"/> if
  44. /// sending many requests.
  45. /// </summary>
  46. public void Send () { Application.Driver?.RawWrite (Request); }
  47. /// <summary>
  48. /// The value expected in the response e.g.
  49. /// <see>
  50. /// <cref>EscSeqUtils.CSI_ReportTerminalSizeInChars.Value</cref>
  51. /// </see>
  52. /// which will have a 't' as terminator but also other different request may return the same terminator with a
  53. /// different value.
  54. /// </summary>
  55. public string? Value { get; init; }
  56. }