Skip to content
ConsoleMonster
Class

TestTerminal

ConsoleMonster.Testing

Namespace
ConsoleMonster.Testing
Assembly
ConsoleMonster
Modifiers
static

Helpers for testing console output in any test framework: render a widget at a fixed size, glyph tier, colour depth and culture (so results do not depend on the machine), drive prompts, menus and forms with scripted keys, and capture the screens they draw. Pair with GoldenFile for snapshot tests.

Inheritance

  • object
  • TestTerminal

Methods

public static InteractiveOptions Interactive(string keys, ScreenCapture capture, GlyphTier glyphs = Full) #

Options that run a prompt, menu or form against scripted keys and draw into capture (rich mode, dark theme, no colour, invariant culture, the capture's size).

Parameters

keys string required
The keys (see TestTerminal.Keys).
capture ConsoleMonster.Interactive.ScreenCapture required
Where the screens go.
glyphs ConsoleMonster.Capabilities.GlyphTier = Full optional
The glyph tier.

Returns

InteractiveOptions The options.
public static ScriptedInput Keys(string script) #

Scripted keys for prompts and menus, for example "Down Down Space Enter", "\"typed text\" Tab", "Ctrl+K paste:'x' wait:200". Paced, so every step draws a frame.

Parameters

script string required
The keys.

Returns

ScriptedInput The input source.
public static TerminalProfile Profile(int width = 80, int height = 24, GlyphTier glyphs = Full, ColorDepth colors = None, CultureInfo? culture = null) #

A fixed terminal profile: no detection, the given size, tier, depth and culture (invariant by default).

Parameters

width int = 80 optional
Width in cells.
height int = 24 optional
Height in cells.
glyphs ConsoleMonster.Capabilities.GlyphTier = Full optional
The glyph tier.
colors ConsoleMonster.Capabilities.ColorDepth = None optional
The colour depth (none by default, so text is plain).
culture System.Globalization.CultureInfo? = null optional
The culture; null for the invariant culture.

Returns

TerminalProfile The profile.
public static CellBuffer Render(IWidget widget, int width = 80, int height = 0, GlyphTier glyphs = Full, CultureInfo? culture = null, ITheme? theme = null) #

Renders a widget into cells: as tall as it measures, or exactly height rows.

Parameters

widget ConsoleMonster.Layout.IWidget required
The widget.
width int = 80 optional
Width in cells.
height int = 0 optional
Height in cells; 0 measures the widget.
glyphs ConsoleMonster.Capabilities.GlyphTier = Full optional
The glyph tier.
culture System.Globalization.CultureInfo? = null optional
The culture; null for the invariant culture.
theme ConsoleMonster.Styling.ITheme? = null optional
The theme; null for the dark theme.

Returns

CellBuffer The cells.
public static string RenderText(IWidget widget, int width = 80, int height = 0, GlyphTier glyphs = Full, CultureInfo? culture = null) #

Renders a widget to plain text: rows joined with \n, trailing spaces trimmed.

Parameters

widget ConsoleMonster.Layout.IWidget required
The widget.
width int = 80 optional
Width in cells.
height int = 0 optional
Height in cells; 0 measures the widget.
glyphs ConsoleMonster.Capabilities.GlyphTier = Full optional
The glyph tier.
culture System.Globalization.CultureInfo? = null optional
The culture; null for the invariant culture.

Returns

string The text.
public static RecordingTarget Target(int width = 80, int height = 24, GlyphTier glyphs = Full, ColorDepth colors = None, CultureInfo? culture = null, string? keys = null) #

An in-memory target with a fixed profile (append-only output, no detection): pass it to code that takes an ITerminalTarget, or scope the static Terminal methods to it with Terminal.Use. Its RecordingTarget.Text goes to GoldenFile through RecordingTarget.MatchGolden; scripted keys answer prompts, which draw into RecordingTarget.Screens.

Parameters

width int = 80 optional
Width in cells.
height int = 24 optional
Height in cells (the screen size for prompts).
glyphs ConsoleMonster.Capabilities.GlyphTier = Full optional
The glyph tier.
colors ConsoleMonster.Capabilities.ColorDepth = None optional
The colour depth (none by default, so the text is plain).
culture System.Globalization.CultureInfo? = null optional
The culture for numbers, dates and labels; null for the invariant culture (English labels).
keys string? = null optional
Scripted keys for prompts (see TestTerminal.Keys), or null so prompts use their defaults.

Returns

RecordingTarget The target.