API Reference
Terminal
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() #VoidClears 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) #RenderContextCreates a render context for a profile and theme.
Parameters
- profile ConsoleMonster.Capabilities.TerminalProfile? = null
- The profile, or null for the detected one.
- theme ConsoleMonster.Styling.ITheme? = null
- The theme, or null for Terminal.Theme.
Returns
The context.
public static ITerminalOutput CreateInlineOutput(TerminalProfile? profile = null, ITerminalWriter? writer = null) #ITerminalOutputCreates 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
- The profile, or null for Terminal.Profile.
- writer ConsoleMonster.Output.ITerminalWriter? = null
- 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) #ITerminalOutputCreates the output for a profile: VT when live rendering is possible, line-based otherwise.
Parameters
- profile ConsoleMonster.Capabilities.TerminalProfile? = null
- The profile, or null for the detected one.
- writer ConsoleMonster.Output.ITerminalWriter? = null
- The sink, or null for the console (the output then owns it).
Returns
The output; dispose it when done.
public static TerminalProfile GetCurrentProfile() #TerminalProfileThe 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() #IDisposableHides 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) #BooleanWhether a target is the process console (live redraw, keyboard input, console ownership).
Parameters
- target ConsoleMonster.Output.ITerminalTarget
- The target.
Returns
True for ConsoleTarget.
public static Void Refresh() #VoidDiscards 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) #CellBufferRenders a widget to a cell buffer (for tests, snapshots and custom outputs).
Parameters
- widget ConsoleMonster.Layout.IWidget
- The widget.
- profile ConsoleMonster.Capabilities.TerminalProfile
- The profile.
- theme ConsoleMonster.Styling.ITheme? = null
- 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) #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
- The widget.
- width System.Int32
- The width in cells.
- context ConsoleMonster.Canvas.RenderContext
- The render context.
- chunkLines System.Int32 = 500
- 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) #StringRenders a widget to the exact text the output for profile would write (including VT sequences).
Parameters
- widget ConsoleMonster.Layout.IWidget
- The widget.
- profile ConsoleMonster.Capabilities.TerminalProfile
- The profile.
- theme ConsoleMonster.Styling.ITheme? = null
- The theme, or null.
Returns
The encoded text.
public static String RenderText(IWidget widget, TerminalProfile profile, ITheme? theme = null) #StringRenders a widget to plain text lines (trailing spaces trimmed).
Parameters
- widget ConsoleMonster.Layout.IWidget
- The widget.
- profile ConsoleMonster.Capabilities.TerminalProfile
- The profile.
- theme ConsoleMonster.Styling.ITheme? = null
- The theme, or null.
Returns
The text.
public static ITheme ResolveTheme(TerminalProfile profile) #IThemeChooses 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
- The terminal profile.
Returns
The theme.
public static Void ShowCursor() #VoidShows 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) #VoidRuns 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
- The first status text, as markup.
- action System.Action<ConsoleMonster.Output.StatusContext>
- The work.
public static async Task StatusAsync(String markup, Func<StatusContext, Task> action) #TaskRuns asynchronous work under a status (see Terminal.Status).
Parameters
- markup System.String
- The first status text, as markup.
- action System.Func<ConsoleMonster.Output.StatusContext, System.Threading.Tasks.Task>
- 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) #Task<T?>Runs asynchronous work that returns a value under a status.
Type Parameters
- T
- The result type.
Parameters
- markup System.String
- The first status text, as markup.
- func System.Func<ConsoleMonster.Output.StatusContext, System.Threading.Tasks.Task<T?>>
- The work.
Returns
The work's result.
public static T? Status<T>(String markup, Func<StatusContext, T?> func) #T?Runs work that returns a value under a status (see Terminal.Status).
Type Parameters
- T
- The result type.
Parameters
- markup System.String
- The first status text, as markup.
- func System.Func<ConsoleMonster.Output.StatusContext, T?>
- The work.
Returns
The work's result.
public static IDisposable Use(ITerminalTarget target) #IDisposableSends 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
- The target.
Returns
The scope; dispose it to restore the previous target.
public static Void Write(IWidget widget) #VoidWrites a widget once, as wide as the terminal.
Parameters
- widget ConsoleMonster.Layout.IWidget
- The widget.
public static Void Write(IWidget widget, TerminalProfile? profile) #VoidWrites a widget once with an explicit profile.
Parameters
- widget ConsoleMonster.Layout.IWidget
- The widget.
- profile ConsoleMonster.Capabilities.TerminalProfile?
- The profile, or null for the detected one.
public static Void Write(IWidget widget, TerminalProfile? profile, ITerminalWriter? writer) #VoidWrites 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
- The widget.
- profile ConsoleMonster.Capabilities.TerminalProfile?
- The profile, or null for Terminal.GetCurrentProfile.
- writer ConsoleMonster.Output.ITerminalWriter?
- 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) #VoidWrites styled lines; with newLine false the last line is left open.
Parameters
- lines System.Collections.Generic.IReadOnlyList<ConsoleMonster.Text.StyledLine>
- The lines.
- newLine System.Boolean = true
- Whether to end the last line.
- profile ConsoleMonster.Capabilities.TerminalProfile? = null
- The profile, or null for Terminal.GetCurrentProfile.
- writer ConsoleMonster.Output.ITerminalWriter? = null
- The sink, or null for the console. The caller keeps ownership of a given writer.
public static Void WriteMarkup(String markup) #VoidWrites 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
- The markup.
public static Void WriteMarkup(String markup, Boolean newLine, TerminalProfile? profile = null, ITerminalWriter? writer = null) #VoidWrites 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
- The markup.
- newLine System.Boolean
- Whether to end the last line.
- profile ConsoleMonster.Capabilities.TerminalProfile? = null
- The profile, or null for Terminal.GetCurrentProfile.
- writer ConsoleMonster.Output.ITerminalWriter? = null
- The sink, or null for the console. The caller keeps ownership of a given writer.
public static Void WriteMarkupLine(String markup) #VoidWrites one line of Spectre-compatible markup (Spectre's MarkupLine), for example [pass]Done[/] in [muted]3s[/].
Parameters
- markup System.String
- The markup.
public static Void WriteMarkupLine(String markup, TerminalProfile? profile, ITerminalWriter? writer) #VoidWrites one line of markup to an explicit sink.
Parameters
- markup System.String
- The markup.
- profile ConsoleMonster.Capabilities.TerminalProfile?
- The profile, or null for Terminal.GetCurrentProfile.
- writer ConsoleMonster.Output.ITerminalWriter?
- 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) #VoidWrites 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
- The rich text.
- newLine System.Boolean = true
- Whether to end the last line.
- profile ConsoleMonster.Capabilities.TerminalProfile? = null
- The profile, or null for Terminal.GetCurrentProfile.
- writer ConsoleMonster.Output.ITerminalWriter? = null
- The sink, or null for the console. The caller keeps ownership of a given writer.
Inherited Methods
public virtual Boolean Equals(Object? obj) #BooleanParameters
- obj Object?
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 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.