#nullable enable using System.Collections.Concurrent; namespace Terminal.Gui.App; /// /// Interface for the main application loop that runs the core Terminal.Gui UI rendering and event processing. /// /// /// This interface defines the contract for the main loop that coordinates: /// /// Processing input events from the console /// Running user timeout callbacks /// Detecting UI changes that need redrawing /// Rendering UI updates to the console /// /// /// Type of raw input events processed by the loop, e.g. for cross-platform .NET driver public interface IApplicationMainLoop : IDisposable where TInputRecord : struct { /// /// Gets the implementation that manages user-defined timeouts and periodic events. /// public ITimedEvents TimedEvents { get; } /// /// Gets the representing the desired screen state for console rendering. /// public IOutputBuffer OutputBuffer { get; } /// /// Gets the implementation responsible for rendering the to the console using platform specific methods. /// public IOutput Output { get; } /// /// Gets implementation that processes the mouse and keyboard input populated by /// implementations on the input thread and translating to events on the UI thread. /// public IInputProcessor InputProcessor { get; } /// /// Gets the class responsible for sending ANSI escape requests which expect a response /// from the remote terminal e.g. Device Attribute Request /// public AnsiRequestScheduler AnsiRequestScheduler { get; } /// /// Gets the implementation that tracks terminal size changes. /// public ISizeMonitor SizeMonitor { get; } /// /// Initializes the main loop with its required dependencies. /// /// /// The implementation for managing user-defined timeouts and periodic callbacks /// (e.g., ). /// /// /// The thread-safe queue containing raw input events populated by on /// the input thread. This queue is drained by during each . /// /// /// The that translates raw input records (e.g., ) /// into Terminal.Gui events (, ) and raises them on the main UI thread. /// /// /// The implementation responsible for rendering the to the /// console using platform-specific methods (e.g., Win32 APIs, ANSI escape sequences). /// /// /// The factory for creating driver-specific components. Used here to create the /// that tracks terminal size changes. /// /// /// /// This method is called by during application startup /// to wire up all the components needed for the main loop to function. It must be called before /// can be invoked. /// /// /// Initialization order: /// /// /// Store references to , , /// , and /// Create for managing ANSI requests/responses /// Initialize size to match current console dimensions /// Create using the /// /// /// After initialization, the main loop is ready to process events via . /// /// void Initialize ( ITimedEvents timedEvents, ConcurrentQueue inputQueue, IInputProcessor inputProcessor, IOutput output, IComponentFactory componentFactory ); /// /// Perform a single iteration of the main loop then blocks for a fixed length /// of time, this method is designed to be run in a loop. /// public void Iteration (); }