IApplicationMainLoop.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #nullable enable
  2. using System.Collections.Concurrent;
  3. namespace Terminal.Gui.App;
  4. /// <summary>
  5. /// Interface for the main application loop that runs the core Terminal.Gui UI rendering and event processing.
  6. /// </summary>
  7. /// <remarks>
  8. /// This interface defines the contract for the main loop that coordinates:
  9. /// <list type="bullet">
  10. /// <item>Processing input events from the console</item>
  11. /// <item>Running user timeout callbacks</item>
  12. /// <item>Detecting UI changes that need redrawing</item>
  13. /// <item>Rendering UI updates to the console</item>
  14. /// </list>
  15. /// </remarks>
  16. /// <typeparam name="T">Type of raw input events processed by the loop, e.g. <see cref="ConsoleKeyInfo"/> for cross-platform .NET driver</typeparam>
  17. public interface IApplicationMainLoop<T> : IDisposable
  18. {
  19. /// <summary>
  20. /// Gets the class responsible for servicing user timeouts
  21. /// </summary>
  22. public ITimedEvents TimedEvents { get; }
  23. /// <summary>
  24. /// Gets the class responsible for writing final rendered output to the console
  25. /// </summary>
  26. public IOutputBuffer OutputBuffer { get; }
  27. /// <summary>
  28. /// Class for writing output to the console.
  29. /// </summary>
  30. public IConsoleOutput Out { get; }
  31. /// <summary>
  32. /// Gets the class responsible for processing buffered console input and translating
  33. /// it into events on the UI thread.
  34. /// </summary>
  35. public IInputProcessor InputProcessor { get; }
  36. /// <summary>
  37. /// Gets the class responsible for sending ANSI escape requests which expect a response
  38. /// from the remote terminal e.g. Device Attribute Request
  39. /// </summary>
  40. public AnsiRequestScheduler AnsiRequestScheduler { get; }
  41. /// <summary>
  42. /// Gets the class responsible for determining the current console size
  43. /// </summary>
  44. public IWindowSizeMonitor WindowSizeMonitor { get; }
  45. /// <summary>
  46. /// Initializes the loop with a buffer from which data can be read
  47. /// </summary>
  48. /// <param name="timedEvents"></param>
  49. /// <param name="inputBuffer"></param>
  50. /// <param name="inputProcessor"></param>
  51. /// <param name="consoleOutput"></param>
  52. /// <param name="componentFactory"></param>
  53. void Initialize (
  54. ITimedEvents timedEvents,
  55. ConcurrentQueue<T> inputBuffer,
  56. IInputProcessor inputProcessor,
  57. IConsoleOutput consoleOutput,
  58. IComponentFactory<T> componentFactory
  59. );
  60. /// <summary>
  61. /// Perform a single iteration of the main loop then blocks for a fixed length
  62. /// of time, this method is designed to be run in a loop.
  63. /// </summary>
  64. public void Iteration ();
  65. }