AnsiEscapeSequenceRequest.cs 2.4 KB

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