Interface IInput<TInputRecord>
Interface for reading console input in a perpetual loop on a dedicated input thread.
public interface IInput<TInputRecord> : IDisposable
Type Parameters
TInputRecordThe platform-specific input record type:
- ConsoleKeyInfo - for .NET and Fake drivers
- WindowsConsole.InputRecord - for Windows driver
- char - for Unix driver
- Inherited Members
Remarks
Implementations run on a separate thread (started by StartInputTaskAsync(IApplication)) and continuously read platform-specific input from the console, placing it into a thread-safe queue for processing by IInputProcessor on the main UI thread.
Architecture:
Input Thread: Main UI Thread:
┌─────────────────┐ ┌──────────────────────┐
│ IInput.Run() │ │ IInputProcessor │
│ ├─ Peek() │ │ ├─ ProcessQueue() │
│ ├─ Read() │──Enqueue──→ │ ├─ Process() │
│ └─ Enqueue │ │ ├─ ToKey() │
└─────────────────┘ │ └─ Raise Events │
└──────────────────────┘
Lifecycle:
- Initialize(ConcurrentQueue<TInputRecord>) - Set the shared input queue
- Run(CancellationToken) - Start the perpetual read loop (blocks until cancelled)
- Loop calls Peek() and Read()
- Cancellation via `runCancellationToken` or ExternalCancellationTokenSource
Implementations:
- Terminal.Gui.Drivers.WindowsInput - Uses Windows Console API (
ReadConsoleInput) - NetInput - Uses .NET Console API
- Terminal.Gui.Drivers.UnixInput - Uses Unix terminal APIs
- FakeInput - For testing, implements ITestableInput<TInputRecord>
Testing Support: See ITestableInput<TInputRecord> for programmatic input injection in test scenarios.
Properties
- ExternalCancellationTokenSource
Gets or sets an external cancellation token source that can stop the Run(CancellationToken) loop in addition to the
runCancellationTokenpassed to Run(CancellationToken).
Methods
- Initialize(ConcurrentQueue<TInputRecord>)
Initializes the input reader with the thread-safe queue where read input will be stored.
- Run(CancellationToken)
Runs the input loop, continuously reading input and placing it into the queue provided by Initialize(ConcurrentQueue<TInputRecord>).