IInputProcessor.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #nullable enable
  2. namespace Terminal.Gui.Drivers;
  3. /// <summary>
  4. /// Interface for main loop class that will process the queued input buffer contents.
  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 fired when a key is pressed down. This is a precursor to <see cref="KeyUp"/>.</summary>
  11. event EventHandler<Key>? KeyDown;
  12. /// <summary>Event fired when a key is released.</summary>
  13. /// <remarks>
  14. /// Drivers that do not support key release events will fire this event after <see cref="KeyDown"/> processing is
  15. /// complete.
  16. /// </remarks>
  17. event EventHandler<Key>? KeyUp;
  18. /// <summary>Event fired when a terminal sequence read from input is not recognized and therefore ignored.</summary>
  19. public event EventHandler<string>? AnsiSequenceSwallowed;
  20. /// <summary>Event fired when a mouse event occurs.</summary>
  21. event EventHandler<MouseEventArgs>? MouseEvent;
  22. /// <summary>
  23. /// Gets the name of the driver associated with this input processor.
  24. /// </summary>
  25. string? DriverName { get; init; }
  26. /// <summary>
  27. /// Called when a key is pressed down. Fires the <see cref="KeyDown"/> event. This is a precursor to
  28. /// <see cref="OnKeyUp"/>.
  29. /// </summary>
  30. /// <param name="key">The key event data.</param>
  31. void OnKeyDown (Key key);
  32. /// <summary>
  33. /// Called when a key is released. Fires the <see cref="KeyUp"/> event.
  34. /// </summary>
  35. /// <remarks>
  36. /// Drivers that do not support key release events will call this method after <see cref="OnKeyDown"/> processing
  37. /// is complete.
  38. /// </remarks>
  39. /// <param name="key">The key event data.</param>
  40. void OnKeyUp (Key key);
  41. /// <summary>
  42. /// Called when a mouse event occurs. Fires the <see cref="MouseEvent"/> event.
  43. /// </summary>
  44. /// <param name="mouseEventArgs">The mouse event data.</param>
  45. void OnMouseEvent (MouseEventArgs mouseEventArgs);
  46. /// <summary>
  47. /// Drains the input buffer, processing all available keystrokes
  48. /// </summary>
  49. void ProcessQueue ();
  50. /// <summary>
  51. /// Gets the response parser currently configured on this input processor.
  52. /// </summary>
  53. /// <returns></returns>
  54. public IAnsiResponseParser GetParser ();
  55. /// <summary>
  56. /// Handles surrogate pairs in the input stream.
  57. /// </summary>
  58. /// <param name="key">The key from input.</param>
  59. /// <param name="result">Get the surrogate pair or the key.</param>
  60. /// <returns>
  61. /// <see langword="true"/> if the result is a valid surrogate pair or a valid key, otherwise
  62. /// <see langword="false"/>.
  63. /// </returns>
  64. bool IsValidInput (Key key, out Key result);
  65. }