Table of Contents

Interface IInput<TInputRecord>

Namespace
Terminal.Gui.Drivers
Assembly
Terminal.Gui.dll

Interface for reading console input in a perpetual loop on a dedicated input thread.

public interface IInput<TInputRecord> : IDisposable

Type Parameters

TInputRecord

The platform-specific input record type:

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:

  1. Initialize(ConcurrentQueue<TInputRecord>) - Set the shared input queue
  2. Run(CancellationToken) - Start the perpetual read loop (blocks until cancelled)
  3. Loop calls Peek() and Read()
  4. Cancellation via `runCancellationToken` or ExternalCancellationTokenSource

Implementations:

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 runCancellationToken passed 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>).