AnsiEscapeSequenceRequest.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 ()
  47. {
  48. Application.Driver?.RawWrite (Request);
  49. }
  50. }