Skip to content
ConsoleMonster

API Reference

Class

Terminal

Namespace ConsoleMonster
Assembly ConsoleMonster
Modifiers static

The print-once entry point: Terminal.Write(table). Detects the terminal once (overridable through Terminal.Profile or the CONSOLEMONSTER_* environment variables) and writes widgets in the right mode. Calls are serialized, so concurrent writers never interleave inside a block.

Inheritance

  • Object
  • Terminal

Methods

public static Void Clear() #
Returns: Void

Clears the screen and its scrollback and puts the cursor at the top left, as Console.Clear and Spectre's AnsiConsole.Clear do. A no-op where clearing makes no sense: redirected output, CI logs, plain or stream mode, and while a live session owns the console (its area would be lost).

public static RenderContext CreateContext(TerminalProfile? profile = null, ITheme? theme = null) #
Returns: RenderContext

Creates a render context for a profile and theme.

Parameters

profile ConsoleMonster.Capabilities.TerminalProfile? = null optionalposition: 0
The profile, or null for the detected one.
theme ConsoleMonster.Styling.ITheme? = null optionalposition: 1
The theme, or null for Terminal.Theme.

Returns

The context.

public static ITerminalOutput CreateInlineOutput(TerminalProfile? profile = null, ITerminalWriter? writer = null) #
Returns: ITerminalOutput

Creates the output for an inline live area (InlineOutput) on a VT console, or stream lines where in-place drawing is not possible (CI, redirected output, no VT).

Parameters

profile ConsoleMonster.Capabilities.TerminalProfile? = null optionalposition: 0
The profile, or null for Terminal.Profile.
writer ConsoleMonster.Output.ITerminalWriter? = null optionalposition: 1
The sink, or null for the console (then owned by the output).

Returns

The output.

public static ITerminalOutput CreateOutput(TerminalProfile? profile = null, ITerminalWriter? writer = null) #
Returns: ITerminalOutput

Creates the output for a profile: VT when live rendering is possible, line-based otherwise.

Parameters

profile ConsoleMonster.Capabilities.TerminalProfile? = null optionalposition: 0
The profile, or null for the detected one.
writer ConsoleMonster.Output.ITerminalWriter? = null optionalposition: 1
The sink, or null for the console (the output then owns it).

Returns

The output; dispose it when done.

public static TerminalProfile GetCurrentProfile() #
Returns: TerminalProfile

The cached Terminal.Profile with the current window size: after the user resizes the console, print-once output lays out for the new width while every other detected capability stays cached. An assigned profile, redirected output and non-interactive modes keep their size.

Returns

The profile for a write happening now.

public static IDisposable HideCursor() #
Returns: IDisposable

Hides the cursor until the returned handle is disposed or Terminal.ShowCursor is called. The cursor is also shown again when the process exits or Ctrl+C ends it. A no-op in redirected output, CI logs and plain mode.

Returns

A handle that shows the cursor again when disposed.

public static Boolean IsConsole(ITerminalTarget target) #
Returns: Boolean

Whether a target is the process console (live redraw, keyboard input, console ownership).

Parameters

target ConsoleMonster.Output.ITerminalTarget requiredposition: 0
The target.

Returns

True for ConsoleTarget.

public static Void Refresh() #
Returns: Void

Discards the cached profile so the next use detects the terminal again (after a resize or font change).

public static CellBuffer Render(IWidget widget, TerminalProfile profile, ITheme? theme = null) #
Returns: CellBuffer

Renders a widget to a cell buffer (for tests, snapshots and custom outputs).

Parameters

widget ConsoleMonster.Layout.IWidget requiredposition: 0
The widget.
profile ConsoleMonster.Capabilities.TerminalProfile requiredposition: 1
The profile.
theme ConsoleMonster.Styling.ITheme? = null optionalposition: 2
The theme, or null for Terminal.Theme.

Returns

The rendered block.

public static IEnumerable<CellBuffer> RenderChunks(IWidget widget, Int32 width, RenderContext context, Int32 chunkLines = 500) #
Returns: IEnumerable<CellBuffer>

Renders a widget for print-once output as one or more blocks written one after another: a long table comes as a sequence of blocks with stable column widths (see Terminal.StreamingRowThreshold), anything else as one block.

Parameters

widget ConsoleMonster.Layout.IWidget requiredposition: 0
The widget.
width System.Int32 requiredposition: 1
The width in cells.
context ConsoleMonster.Canvas.RenderContext requiredposition: 2
The render context.
chunkLines System.Int32 = 500 optionalposition: 3
Lines per block for long tables (default 500).

Returns

The blocks, top to bottom.

public static String RenderEncoded(IWidget widget, TerminalProfile profile, ITheme? theme = null) #
Returns: String

Renders a widget to the exact text the output for profile would write (including VT sequences).

Parameters

widget ConsoleMonster.Layout.IWidget requiredposition: 0
The widget.
profile ConsoleMonster.Capabilities.TerminalProfile requiredposition: 1
The profile.
theme ConsoleMonster.Styling.ITheme? = null optionalposition: 2
The theme, or null.

Returns

The encoded text.

public static String RenderText(IWidget widget, TerminalProfile profile, ITheme? theme = null) #
Returns: String

Renders a widget to plain text lines (trailing spaces trimmed).

Parameters

widget ConsoleMonster.Layout.IWidget requiredposition: 0
The widget.
profile ConsoleMonster.Capabilities.TerminalProfile requiredposition: 1
The profile.
theme ConsoleMonster.Styling.ITheme? = null optionalposition: 2
The theme, or null.

Returns

The text.

public static ITheme ResolveTheme(TerminalProfile profile) #
Returns: ITheme

Chooses the light or dark theme: CONSOLEMONSTER_THEME=light|dark wins; otherwise interactive consoles use the detected background (console colour table, COLORFGBG) and everything else the dark theme.

Parameters

profile ConsoleMonster.Capabilities.TerminalProfile requiredposition: 0
The terminal profile.

Returns

The theme.

public static Void ShowCursor() #
Returns: Void

Shows the cursor (after Terminal.HideCursor). A no-op in redirected output, CI logs and plain mode.

public static Void Status(String markup, Action<StatusContext> action) #
Returns: Void

Runs work under a one-line status with a spinner (Spectre's AnsiConsole.Status().Start): Terminal.Status("Resolving…", ctx => { … ctx.Update("Querying [accent]dc01[/]"); }). The line is a transient inline live area: output written meanwhile scrolls above it, and it is removed when the work ends, even when it throws. Redirected output, CI logs and plain mode get each status text once as a plain line instead (see StatusContext).

Parameters

markup System.String requiredposition: 0
The first status text, as markup.
action System.Action<ConsoleMonster.Output.StatusContext> requiredposition: 1
The work.
public static async Task StatusAsync(String markup, Func<StatusContext, Task> action) #
Returns: Task

Runs asynchronous work under a status (see Terminal.Status).

Parameters

markup System.String requiredposition: 0
The first status text, as markup.
action System.Func<ConsoleMonster.Output.StatusContext, System.Threading.Tasks.Task> requiredposition: 1
The work.

Returns

A task that completes when the work has finished and the status is removed.

public static async Task<T?> StatusAsync<T>(String markup, Func<StatusContext, Task<T?>> func) #
Returns: Task<T?>

Runs asynchronous work that returns a value under a status.

Type Parameters

T
The result type.

Parameters

markup System.String requiredposition: 0
The first status text, as markup.
func System.Func<ConsoleMonster.Output.StatusContext, System.Threading.Tasks.Task<T?>> requiredposition: 1
The work.

Returns

The work's result.

public static T? Status<T>(String markup, Func<StatusContext, T?> func) #
Returns: T?

Runs work that returns a value under a status (see Terminal.Status).

Type Parameters

T
The result type.

Parameters

markup System.String requiredposition: 0
The first status text, as markup.
func System.Func<ConsoleMonster.Output.StatusContext, T?> requiredposition: 1
The work.

Returns

The work's result.

public static IDisposable Use(ITerminalTarget target) #
Returns: IDisposable

Sends the static methods' output (and prompts, live sessions and status helpers without an explicit target) to target until the returned scope is disposed. The scope flows with async calls and is local to them, so parallel tests and requests do not see each other's target.

Parameters

target ConsoleMonster.Output.ITerminalTarget requiredposition: 0
The target.

Returns

The scope; dispose it to restore the previous target.

Write 3 overloads
public static Void Write(IWidget widget) #
Returns: Void

Writes a widget once, as wide as the terminal.

Parameters

widget ConsoleMonster.Layout.IWidget requiredposition: 0
The widget.
public static Void Write(IWidget widget, TerminalProfile? profile) #
Returns: Void

Writes a widget once with an explicit profile.

Parameters

widget ConsoleMonster.Layout.IWidget requiredposition: 0
The widget.
profile ConsoleMonster.Capabilities.TerminalProfile? requiredposition: 1
The profile, or null for the detected one.
public static Void Write(IWidget widget, TerminalProfile? profile, ITerminalWriter? writer) #
Returns: Void

Writes a widget once to an explicit sink: a PowerShell host, a log, a string. With a writer, the output is laid out for the profile but goes to the writer instead of the console.

Parameters

widget ConsoleMonster.Layout.IWidget requiredposition: 0
The widget.
profile ConsoleMonster.Capabilities.TerminalProfile? requiredposition: 1
The profile, or null for Terminal.GetCurrentProfile.
writer ConsoleMonster.Output.ITerminalWriter? requiredposition: 2
The sink, or null for the console. The caller keeps ownership of a given writer.
public static Void WriteLines(IReadOnlyList<StyledLine> lines, Boolean newLine = true, TerminalProfile? profile = null, ITerminalWriter? writer = null) #
Returns: Void

Writes styled lines; with newLine false the last line is left open.

Parameters

lines System.Collections.Generic.IReadOnlyList<ConsoleMonster.Text.StyledLine> requiredposition: 0
The lines.
newLine System.Boolean = true optionalposition: 1
Whether to end the last line.
profile ConsoleMonster.Capabilities.TerminalProfile? = null optionalposition: 2
The profile, or null for Terminal.GetCurrentProfile.
writer ConsoleMonster.Output.ITerminalWriter? = null optionalposition: 3
The sink, or null for the console. The caller keeps ownership of a given writer.
WriteMarkup 2 overloads
public static Void WriteMarkup(String markup) #
Returns: Void

Writes Spectre-compatible markup without ending the line (Spectre's Markup), for example a prompt prefix; line breaks inside the markup still start new lines.

Parameters

markup System.String requiredposition: 0
The markup.
public static Void WriteMarkup(String markup, Boolean newLine, TerminalProfile? profile = null, ITerminalWriter? writer = null) #
Returns: Void

Writes markup to an explicit sink; with newLine false the last line is left open. Redirected and CI output gets plain text either way.

Parameters

markup System.String requiredposition: 0
The markup.
newLine System.Boolean requiredposition: 1
Whether to end the last line.
profile ConsoleMonster.Capabilities.TerminalProfile? = null optionalposition: 2
The profile, or null for Terminal.GetCurrentProfile.
writer ConsoleMonster.Output.ITerminalWriter? = null optionalposition: 3
The sink, or null for the console. The caller keeps ownership of a given writer.
WriteMarkupLine 2 overloads
public static Void WriteMarkupLine(String markup) #
Returns: Void

Writes one line of Spectre-compatible markup (Spectre's MarkupLine), for example [pass]Done[/] in [muted]3s[/].

Parameters

markup System.String requiredposition: 0
The markup.
public static Void WriteMarkupLine(String markup, TerminalProfile? profile, ITerminalWriter? writer) #
Returns: Void

Writes one line of markup to an explicit sink.

Parameters

markup System.String requiredposition: 0
The markup.
profile ConsoleMonster.Capabilities.TerminalProfile? requiredposition: 1
The profile, or null for Terminal.GetCurrentProfile.
writer ConsoleMonster.Output.ITerminalWriter? requiredposition: 2
The sink, or null for the console. The caller keeps ownership of a given writer.
public static Void WriteRich(RichText text, Boolean newLine = true, TerminalProfile? profile = null, ITerminalWriter? writer = null) #
Returns: Void

Writes rich text as lines (not as a laid-out block): line breaks inside it start new lines, nothing is wrapped or padded, and with newLine false the last line is left open, as Write-Host -NoNewline does.

Parameters

text ConsoleMonster.Text.RichText requiredposition: 0
The rich text.
newLine System.Boolean = true optionalposition: 1
Whether to end the last line.
profile ConsoleMonster.Capabilities.TerminalProfile? = null optionalposition: 2
The profile, or null for Terminal.GetCurrentProfile.
writer ConsoleMonster.Output.ITerminalWriter? = null optionalposition: 3
The sink, or null for the console. The caller keeps ownership of a given writer.

Properties

public static ICapabilityProvider CapabilityProvider { get; set; } #

The capability provider used for detection.

public static TerminalProfile Profile { get; set; } #

The active profile; detected on first use and cached (including the size at detection time). Assign to override detection for the process. Print-once writes use Terminal.GetCurrentProfile, which refreshes the size.

public static ITheme Theme { get; set; } #

The active theme: the target's (see Terminal.Target), or the console's.

public static Int32 StreamingRowThreshold { get; set; } #

The rows above which a table is printed in blocks (default 2000): column widths are still computed from every row, but cells are rendered and written a block at a time, so memory stays flat for very long tables.

public static Boolean IsCursorHidden { get; } #

Whether Terminal.HideCursor has hidden the cursor and it has not been shown again.

public static ITerminalTarget Target { get; } #

The target the static methods write to: the one set by Terminal.Use for the current asynchronous flow, or Terminal.DefaultTarget. Writes with an explicit writer, live sessions and prompts with an explicit target keep theirs.

public static ITerminalTarget DefaultTarget { get; set; } #

The process-wide target when no scope is active (default ConsoleTarget). Prefer Terminal.Use, which affects only the current asynchronous flow; this is for hosts that own the whole process.