IInputProcessor.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. namespace Terminal.Gui.Drivers;
  2. /// <summary>
  3. /// Interface for main loop class that will process the queued input.
  4. /// Is responsible for <see cref="ProcessQueue"/> and translating into common Terminal.Gui
  5. /// events and data models.
  6. /// </summary>
  7. public interface IInputProcessor
  8. {
  9. /// <summary>Event raised when a terminal sequence read from input is not recognized and therefore ignored.</summary>
  10. public event EventHandler<string>? AnsiSequenceSwallowed;
  11. /// <summary>
  12. /// Gets the name of the driver associated with this input processor.
  13. /// </summary>
  14. string? DriverName { get; init; }
  15. /// <summary>
  16. /// Drains the input queue, processing all available keystrokes. To be called on the main loop thread.
  17. /// </summary>
  18. void ProcessQueue ();
  19. /// <summary>
  20. /// Gets the response parser currently configured on this input processor.
  21. /// </summary>
  22. /// <returns></returns>
  23. public IAnsiResponseParser GetParser ();
  24. /// <summary>
  25. /// Handles surrogate pairs in the input stream.
  26. /// </summary>
  27. /// <param name="key">The key from input.</param>
  28. /// <param name="result">Get the surrogate pair or the key.</param>
  29. /// <returns>
  30. /// <see langword="true"/> if the result is a valid surrogate pair or a valid key, otherwise
  31. /// <see langword="false"/>.
  32. /// </returns>
  33. bool IsValidInput (Key key, out Key result);
  34. /// <summary>
  35. /// Called when a key down event has been dequeued. Raises the <see cref="KeyDown"/> event. This is a precursor to
  36. /// <see cref="RaiseKeyUpEvent"/>.
  37. /// </summary>
  38. /// <param name="key">The key event data.</param>
  39. void RaiseKeyDownEvent (Key key);
  40. /// <summary>Event raised when a key down event has been dequeued. This is a precursor to <see cref="KeyUp"/>.</summary>
  41. event EventHandler<Key>? KeyDown;
  42. /// <summary>
  43. /// Adds a key up event to the input queue. For unit tests.
  44. /// </summary>
  45. /// <param name="key"></param>
  46. void EnqueueKeyDownEvent (Key key);
  47. /// <summary>
  48. /// Called when a key up event has been dequeued. Raises the <see cref="KeyUp"/> event.
  49. /// </summary>
  50. /// <remarks>
  51. /// Drivers that do not support key release events will call this method after <see cref="RaiseKeyDownEvent"/>
  52. /// 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="app">
  79. /// The application instance to use. Used to use Invoke to raise the mouse
  80. /// event in the case where this method is not called on the main thread.
  81. /// </param>
  82. /// <param name="mouseEvent"></param>
  83. void EnqueueMouseEvent (IApplication? app, MouseEventArgs mouseEvent);
  84. }