Class TestTerminal
In-memory terminal implementation intended for tests of semi-interactive TUI flows.
public sealed class TestTerminal : ICliTerminal
- Inheritance
-
TestTerminal
- Implements
- Inherited Members
Constructors
TestTerminal(int, int)
Creates an in-memory terminal with the specified simulated window size.
public TestTerminal(int windowWidth = 80, int windowHeight = 24)
Parameters
Properties
BackgroundColor
Current background colour.
public CliColor BackgroundColor { get; set; }
Property Value
ClearCount
The number of line-clear requests received by the terminal.
public int ClearCount { get; }
Property Value
CursorLeft
Current cursor column.
public int CursorLeft { get; }
Property Value
CursorTop
Current cursor row.
public int CursorTop { get; }
Property Value
CursorVisible
Cursor visibility.
public bool CursorVisible { get; set; }
Property Value
CursorVisibleAtLastRender
The value of CursorVisible captured at the moment the most recent
RenderGrid(int, int, CliGrid) call began drawing. Lets tests assert the cursor was hidden while the
grid was being written (it should only be made visible again after a render completes).
public bool CursorVisibleAtLastRender { get; }
Property Value
ForegroundColor
Current foreground colour.
public CliColor ForegroundColor { get; set; }
Property Value
KeyAvailable
Whether a key press is available without blocking.
public bool KeyAvailable { get; }
Property Value
LastRenderedGrid
The most recently captured grid, or
null before the first render.public CliGrid? LastRenderedGrid { get; }
Property Value
LastRenderedLines
A snapshot of the most recently rendered text lines.
public IReadOnlyList<string> LastRenderedLines { get; }
Property Value
LastRenderedText
The most recently rendered lines joined with line-feed characters.
public string LastRenderedText { get; }
Property Value
ReadCount
The number of simulated keys read from the input queue.
public int ReadCount { get; }
Property Value
RenderCount
The number of grids captured by RenderGrid(int, int, CliGrid).
public int RenderCount { get; }
Property Value
Sink
Gets the render sink associated with this terminal.
public ICliRenderSink Sink { get; }
Property Value
State
Captures the terminal state needed for later restoration.
public ITerminalState State { get; }
Property Value
WindowHeight
Gets or sets the simulated window height in cells.
public int WindowHeight { get; set; }
Property Value
WindowTitle
The most recently captured sanitized window title.
public string? WindowTitle { get; }
Property Value
WindowTitleWriteCount
The number of window-title writes captured by the terminal.
public int WindowTitleWriteCount { get; }
Property Value
WindowWidth
Gets or sets the simulated window width in cells.
public int WindowWidth { get; set; }
Property Value
Methods
ClearLines(int, int, CliColor)
Records a line-clear request and increments ClearCount.
public void ClearLines(int fromRow, int count, CliColor bgColor)
Parameters
fromRowint- The first row requested for clearing.
countint- The number of rows requested for clearing.
bgColorCliColor- The requested background colour.
EnqueueKey(ConsoleKey, ConsoleModifiers, char)
Queues a simulated key press for the modal loop to read.
public void EnqueueKey(ConsoleKey key, ConsoleModifiers modifiers = ConsoleModifiers.None, char keyChar = '\0')
Parameters
keyConsoleKey- The console key.
modifiersConsoleModifiers- The modifier keys held during the key press.
keyCharchar- The character produced by the key press.
EnqueueKey(ConsoleKeyInfo)
Queues a fully specified simulated key press.
public void EnqueueKey(ConsoleKeyInfo key)
Parameters
keyConsoleKeyInfo- The key information to queue.
EnqueueKeys(params ConsoleKey[])
Queues a sequence of simulated key presses without modifiers or character values.
public void EnqueueKeys(params ConsoleKey[] keys)
Parameters
keysConsoleKey[]- The keys to queue in read order.
ReadKey(bool)
Dequeues the next simulated key and increments ReadCount.
public ConsoleKeyInfo ReadKey(bool intercept)
Parameters
interceptbool- Accepted for terminal compatibility; simulated input is not echoed.
Returns
- ConsoleKeyInfo
- The next queued key.
RenderGrid(int, int, CliGrid)
Captures a grid as plain text and increments RenderCount.
public void RenderGrid(int x, int y, CliGrid grid)
Parameters
xint- The requested starting column.
yint- The requested starting row.
gridCliGrid- The grid to capture.
RestoreState(ITerminalState, int, int)
Restores a captured terminal state and clears the rendered region.
public void RestoreState(ITerminalState terminalState, int startRow, int height)
Parameters
terminalStateITerminalStatestartRowintheightint
SetCursorPosition(int, int)
Moves the cursor.
public void SetCursorPosition(int left, int top)
Parameters
WaitForInputDrainedAsync(TimeSpan?, CancellationToken)
Waits until the modal loop has observed the queued input as drained.
public Task WaitForInputDrainedAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
timeoutTimeSpan?- The optional maximum time to wait.
cancellationTokenCancellationToken- A token that cancels the wait.
Returns
- Task
- A task that completes when the current input batch has drained.
WaitForReadCountAsync(int, TimeSpan?, CancellationToken)
Waits until at least the specified number of simulated keys has been read.
public Task WaitForReadCountAsync(int readCount, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
readCountint- The minimum read count.
timeoutTimeSpan?- The optional maximum time to wait.
cancellationTokenCancellationToken- A token that cancels the wait.
Returns
- Task
- A task that completes when the count is reached.
WaitForRenderCountAsync(int, TimeSpan?, CancellationToken)
Waits until at least the specified number of renders has been captured.
public Task WaitForRenderCountAsync(int renderCount, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
renderCountint- The minimum render count.
timeoutTimeSpan?- The optional maximum time to wait.
cancellationTokenCancellationToken- A token that cancels the wait.
Returns
- Task
- A task that completes when the count is reached.