IInputProcessor.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. 
  2. namespace Terminal.Gui.Drivers;
  3. /// <summary>
  4. /// Interface for main loop class that will process the queued input.
  5. /// Is responsible for <see cref="ProcessQueue"/> and translating into common Terminal.Gui
  6. /// events and data models.
  7. /// </summary>
  8. public interface IInputProcessor
  9. {
  10. /// <summary>Event raised when a terminal sequence read from input is not recognized and therefore ignored.</summary>
  11. public event EventHandler<string>? AnsiSequenceSwallowed;
  12. /// <summary>
  13. /// Gets the name of the driver associated with this input processor.
  14. /// </summary>
  15. string? DriverName { get; init; }
  16. /// <summary>
  17. /// Drains the input queue, processing all available keystrokes. To be called on the main loop thread.
  18. /// </summary>
  19. void ProcessQueue ();
  20. /// <summary>
  21. /// Gets the response parser currently configured on this input processor.
  22. /// </summary>
  23. /// <returns></returns>
  24. public IAnsiResponseParser GetParser ();
  25. /// <summary>
  26. /// Handles surrogate pairs in the input stream.
  27. /// </summary>
  28. /// <param name="key">The key from input.</param>
  29. /// <param name="result">Get the surrogate pair or the key.</param>
  30. /// <returns>
  31. /// <see langword="true"/> if the result is a valid surrogate pair or a valid key, otherwise
  32. /// <see langword="false"/>.
  33. /// </returns>
  34. bool IsValidInput (Key key, out Key result);
  35. /// <summary>
  36. /// Called when a key down event has been dequeued. Raises the <see cref="KeyDown"/> event. This is a precursor to
  37. /// <see cref="RaiseKeyUpEvent"/>.
  38. /// </summary>
  39. /// <param name="key">The key event data.</param>
  40. void RaiseKeyDownEvent (Key key);
  41. /// <summary>Event raised when a key down event has been dequeued. This is a precursor to <see cref="KeyUp"/>.</summary>
  42. event EventHandler<Key>? KeyDown;
  43. /// <summary>
  44. /// Adds a key up event to the input queue. For unit tests.
  45. /// </summary>
  46. /// <param name="key"></param>
  47. void EnqueueKeyDownEvent (Key key);
  48. /// <summary>
  49. /// Called when a key up event has been dequeued. Raises the <see cref="KeyUp"/> event.
  50. /// </summary>
  51. /// <remarks>
  52. /// Drivers that do not support key release events will call this method after <see cref="RaiseKeyDownEvent"/> processing
  53. /// is complete.
  54. /// </remarks>
  55. /// <param name="key">The key event data.</param>
  56. void RaiseKeyUpEvent (Key key);
  57. /// <summary>Event raised when a key up event has been dequeued.</summary>
  58. /// <remarks>
  59. /// Drivers that do not support key release events will fire this event after <see cref="KeyDown"/> processing is
  60. /// complete.
  61. /// </remarks>
  62. event EventHandler<Key>? KeyUp;
  63. /// <summary>
  64. /// Adds a key up event to the input queue. For unit tests.
  65. /// </summary>
  66. /// <param name="key"></param>
  67. void EnqueueKeyUpEvent (Key key);
  68. /// <summary>
  69. /// Called when a mouse event has been dequeued. Raises the <see cref="MouseEvent"/> event.
  70. /// </summary>
  71. /// <param name="mouseEventArgs">The mouse event data.</param>
  72. void RaiseMouseEvent (MouseEventArgs mouseEventArgs);
  73. /// <summary>Event raised when a mouse event has been dequeued.</summary>
  74. event EventHandler<MouseEventArgs>? MouseEvent;
  75. /// <summary>
  76. /// Adds a mouse input event to the input queue. For unit tests.
  77. /// </summary>
  78. /// <param name="mouseEvent"></param>
  79. void EnqueueMouseEvent (MouseEventArgs mouseEvent);
  80. }