Table of Contents

Class TestTerminal

Namespace
ItTiger.TigerCli.Tui.Testing
Assembly
ItTiger.TigerCli.dll
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

windowWidth int
The window width in cells.
windowHeight int
The window height in cells.

Properties

BackgroundColor

Current background colour.
public CliColor BackgroundColor { get; set; }

Property Value

CliColor

ClearCount

The number of line-clear requests received by the terminal.
public int ClearCount { get; }

Property Value

int

CursorLeft

Current cursor column.
public int CursorLeft { get; }

Property Value

int

CursorTop

Current cursor row.
public int CursorTop { get; }

Property Value

int

CursorVisible

Cursor visibility.
public bool CursorVisible { get; set; }

Property Value

bool

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

bool

ForegroundColor

Current foreground colour.
public CliColor ForegroundColor { get; set; }

Property Value

CliColor

KeyAvailable

Whether a key press is available without blocking.
public bool KeyAvailable { get; }

Property Value

bool

LastRenderedGrid

The most recently captured grid, or null before the first render.
public CliGrid? LastRenderedGrid { get; }

Property Value

CliGrid

LastRenderedLines

A snapshot of the most recently rendered text lines.
public IReadOnlyList<string> LastRenderedLines { get; }

Property Value

IReadOnlyList<string>

LastRenderedText

The most recently rendered lines joined with line-feed characters.
public string LastRenderedText { get; }

Property Value

string

ReadCount

The number of simulated keys read from the input queue.
public int ReadCount { get; }

Property Value

int

RenderCount

The number of grids captured by RenderGrid(int, int, CliGrid).
public int RenderCount { get; }

Property Value

int

Sink

Gets the render sink associated with this terminal.
public ICliRenderSink Sink { get; }

Property Value

ICliRenderSink

State

Captures the terminal state needed for later restoration.
public ITerminalState State { get; }

Property Value

ITerminalState

WindowHeight

Gets or sets the simulated window height in cells.
public int WindowHeight { get; set; }

Property Value

int

WindowTitle

The most recently captured sanitized window title.
public string? WindowTitle { get; }

Property Value

string

WindowTitleWriteCount

The number of window-title writes captured by the terminal.
public int WindowTitleWriteCount { get; }

Property Value

int

WindowWidth

Gets or sets the simulated window width in cells.
public int WindowWidth { get; set; }

Property Value

int

Methods

ClearLines(int, int, CliColor)

Records a line-clear request and increments ClearCount.
public void ClearLines(int fromRow, int count, CliColor bgColor)

Parameters

fromRow int
The first row requested for clearing.
count int
The number of rows requested for clearing.
bgColor CliColor
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

key ConsoleKey
The console key.
modifiers ConsoleModifiers
The modifier keys held during the key press.
keyChar char
The character produced by the key press.

EnqueueKey(ConsoleKeyInfo)

Queues a fully specified simulated key press.
public void EnqueueKey(ConsoleKeyInfo key)

Parameters

key ConsoleKeyInfo
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

keys ConsoleKey[]
The keys to queue in read order.

ReadKey(bool)

Dequeues the next simulated key and increments ReadCount.
public ConsoleKeyInfo ReadKey(bool intercept)

Parameters

intercept bool
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

x int
The requested starting column.
y int
The requested starting row.
grid CliGrid
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

terminalState ITerminalState
startRow int
height int

SetCursorPosition(int, int)

Moves the cursor.
public void SetCursorPosition(int left, int top)

Parameters

left int
top int

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

timeout TimeSpan?
The optional maximum time to wait.
cancellationToken CancellationToken
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

readCount int
The minimum read count.
timeout TimeSpan?
The optional maximum time to wait.
cancellationToken CancellationToken
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

renderCount int
The minimum render count.
timeout TimeSpan?
The optional maximum time to wait.
cancellationToken CancellationToken
A token that cancels the wait.

Returns

Task
A task that completes when the count is reached.