AnsiConsole

A console capable of writing ANSI escape sequences.

A console capable of writing ANSI escape sequences.

Properties

Console : IAnsiConsole

Gets or sets the underlying IAnsiConsole.

Cursor : IAnsiConsoleCursor

Gets the IAnsiConsoleCursor.

Profile : Profile

Gets the console profile.

Methods

public static void AlternateScreen(Action action)

Switches to an alternate screen buffer if the terminal supports it.

Parameters:

action (Action)
The action to execute within the alternate screen buffer.
public static T Ask<T>(string prompt)

Displays a prompt to the user.

Parameters:

prompt (string)
The prompt markup text.

Returns:

The prompt input result.

public static T Ask<T>(string prompt, T defaultValue)

Displays a prompt to the user with a given default.

Parameters:

prompt (string)
The prompt markup text.
defaultValue (T)
The default value.

Returns:

The prompt input result.

public static Task<T> AskAsync<T>(string prompt, CancellationToken cancellationToken = default)

Displays a prompt to the user.

Parameters:

prompt (string)
The prompt markup text.
cancellationToken (CancellationToken)
The token to monitor for cancellation requests.

Returns:

The prompt input result.

public static Task<T> AskAsync<T>(string prompt, T defaultValue, CancellationToken cancellationToken = default)

Displays a prompt to the user with a given default.

Parameters:

prompt (string)
The prompt markup text.
defaultValue (T)
The default value.
cancellationToken (CancellationToken)
The token to monitor for cancellation requests.

Returns:

The prompt input result.

public static void Clear()

Clears the console.

public static bool Confirm(string prompt, bool defaultValue = true)

Displays a prompt with two choices, yes or no.

Parameters:

prompt (string)
The prompt markup text.
defaultValue (bool)
Specifies the default answer.

Returns:

true if the user selected "yes", otherwise false.

public static Task<bool> ConfirmAsync(string prompt, bool defaultValue = true, CancellationToken cancellationToken = default)

Displays a prompt with two choices, yes or no.

Parameters:

prompt (string)
The prompt markup text.
defaultValue (bool)
Specifies the default answer.
cancellationToken (CancellationToken)
The token to monitor for cancellation requests.

Returns:

true if the user selected "yes", otherwise false.

public static IAnsiConsole Create(AnsiConsoleSettings settings)

Creates a new IAnsiConsole instance from the provided settings.

Parameters:

settings (AnsiConsoleSettings)
The settings to use.

Returns:

An IAnsiConsole instance.

public static string ExportCustom(IAnsiConsoleEncoder encoder)

Exports all recorded console output using a custom encoder.

Parameters:

encoder (IAnsiConsoleEncoder)
The encoder to use.

Returns:

The recorded output.

public static string ExportHtml()

Exports all recorded console output as HTML text.

Returns:

The recorded output as HTML text.

public static string ExportText()

Exports all recorded console output as text.

Returns:

The recorded output as text.

public static LiveDisplay Live(IRenderable target)

Creates a new LiveDisplay instance.

Parameters:

target (IRenderable)
The target renderable to update.

Returns:

A LiveDisplay instance.

public static void Markup(string value)

Writes the specified markup to the console.

Parameters:

value (string)
The value to write.
public static void Markup(string format, object[] args)

Writes the specified markup to the console.

Parameters:

format (string)
A composite format string.
args (object[])
An array of objects to write.
public static void Markup(IFormatProvider provider, string format, object[] args)

Writes the specified markup to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
format (string)
A composite format string.
args (object[])
An array of objects to write.
public static void MarkupInterpolated(FormattableString value)

Writes the specified markup to the console. All interpolation holes which contain a string are automatically escaped.

Parameters:

value (FormattableString)
The interpolated string value to write.
public static void MarkupInterpolated(IFormatProvider provider, FormattableString value)

Writes the specified markup to the console. All interpolation holes which contain a string are automatically escaped.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (FormattableString)
The interpolated string value to write.
public static void MarkupLine(string value)

Writes the specified markup, followed by the current line terminator, to the console.

Parameters:

value (string)
The value to write.
public static void MarkupLine(string format, object[] args)

Writes the specified markup, followed by the current line terminator, to the console.

Parameters:

format (string)
A composite format string.
args (object[])
An array of objects to write.
public static void MarkupLine(IFormatProvider provider, string format, object[] args)

Writes the specified markup, followed by the current line terminator, to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
format (string)
A composite format string.
args (object[])
An array of objects to write.
public static void MarkupLineInterpolated(FormattableString value)

Writes the specified markup, followed by the current line terminator, to the console. All interpolation holes which contain a string are automatically escaped.

Parameters:

value (FormattableString)
The interpolated string value to write.
public static void MarkupLineInterpolated(IFormatProvider provider, FormattableString value)

Writes the specified markup, followed by the current line terminator, to the console. All interpolation holes which contain a string are automatically escaped.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (FormattableString)
The interpolated string value to write.
public static Progress Progress()

Creates a new Progress instance.

Returns:

A Progress instance.

public static T Prompt<T>(IPrompt<T> prompt)

Displays a prompt to the user.

Parameters:

prompt (IPrompt<T>)
The prompt to display.

Returns:

The prompt input result.

public static Task<T> PromptAsync<T>(IPrompt<T> prompt, CancellationToken cancellationToken = default)

Displays a prompt to the user.

Parameters:

prompt (IPrompt<T>)
The prompt to display.
cancellationToken (CancellationToken)
The token to monitor for cancellation requests.

Returns:

The prompt input result.

public static void Record()

Starts recording the console output.

public static void Reset()

Resets colors and text decorations.

public static void ResetColors()

Resets the current applied foreground and background colors.

public static void ResetDecoration()

Resets the current applied text decorations.

public static Status Status()

Creates a new Status instance.

Returns:

A Status instance.

public static void Write(IRenderable renderable)

Renders the specified IRenderable to the console.

Parameters:

renderable (IRenderable)
The object to render.
public static void Write(string value)

Writes the specified string value to the console.

Parameters:

value (string)
The value to write.
public static void Write(int value)

Writes the text representation of the specified 32-bit signed integer value to the console.

Parameters:

value (int)
The value to write.
public static void Write(IFormatProvider provider, int value)

Writes the text representation of the specified 32-bit signed integer value to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (int)
The value to write.
public static void Write(uint value)

Writes the text representation of the specified 32-bit unsigned integer value to the console.

Parameters:

value (uint)
The value to write.
public static void Write(IFormatProvider provider, uint value)

Writes the text representation of the specified 32-bit unsigned integer value to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (uint)
The value to write.
public static void Write(long value)

Writes the text representation of the specified 64-bit signed integer value to the console.

Parameters:

value (long)
The value to write.
public static void Write(IFormatProvider provider, long value)

Writes the text representation of the specified 64-bit signed integer value to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (long)
The value to write.
public static void Write(ulong value)

Writes the text representation of the specified 64-bit unsigned integer value to the console.

Parameters:

value (ulong)
The value to write.
public static void Write(IFormatProvider provider, ulong value)

Writes the text representation of the specified 64-bit unsigned integer value to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (ulong)
The value to write.
public static void Write(float value)

Writes the text representation of the specified single-precision floating-point value to the console.

Parameters:

value (float)
The value to write.
public static void Write(IFormatProvider provider, float value)

Writes the text representation of the specified single-precision floating-point value to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (float)
The value to write.
public static void Write(double value)

Writes the text representation of the specified double-precision floating-point value to the console.

Parameters:

value (double)
The value to write.
public static void Write(IFormatProvider provider, double value)

Writes the text representation of the specified double-precision floating-point value to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (double)
The value to write.
public static void Write(decimal value)

Writes the text representation of the specified decimal value, to the console.

Parameters:

value (decimal)
The value to write.
public static void Write(IFormatProvider provider, decimal value)

Writes the text representation of the specified decimal value, to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (decimal)
The value to write.
public static void Write(bool value)

Writes the text representation of the specified boolean value to the console.

Parameters:

value (bool)
The value to write.
public static void Write(IFormatProvider provider, bool value)

Writes the text representation of the specified boolean value to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (bool)
The value to write.
public static void Write(char value)

Writes the specified Unicode character to the console.

Parameters:

value (char)
The value to write.
public static void Write(IFormatProvider provider, char value)

Writes the specified Unicode character to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (char)
The value to write.
public static void Write(char[] value)

Writes the specified array of Unicode characters to the console.

Parameters:

value (char[])
The value to write.
public static void Write(IFormatProvider provider, char[] value)

Writes the specified array of Unicode characters to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (char[])
The value to write.
public static void Write(string format, object[] args)

Writes the text representation of the specified array of objects, to the console using the specified format information.

Parameters:

format (string)
A composite format string.
args (object[])
An array of objects to write.
public static void Write(IFormatProvider provider, string format, object[] args)

Writes the text representation of the specified array of objects, to the console using the specified format information.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
format (string)
A composite format string.
args (object[])
An array of objects to write.
public static void WriteException(Exception exception, ExceptionFormats format = 0)

Writes an exception to the console.

Parameters:

exception (Exception)
The exception to write to the console.
format (ExceptionFormats)
The exception format options.
public static void WriteException(Exception exception, ExceptionSettings settings)

Writes an exception to the console.

Parameters:

exception (Exception)
The exception to write to the console.
settings (ExceptionSettings)
The exception settings.
public static void WriteLine()

Writes an empty line to the console.

public static void WriteLine(string value)

Writes the specified string value, followed by the current line terminator, to the console.

Parameters:

value (string)
The value to write.
public static void WriteLine(int value)

Writes the text representation of the specified 32-bit signed integer value, followed by the current line terminator, to the console.

Parameters:

value (int)
The value to write.
public static void WriteLine(IFormatProvider provider, int value)

Writes the text representation of the specified 32-bit signed integer value, followed by the current line terminator, to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (int)
The value to write.
public static void WriteLine(uint value)

Writes the text representation of the specified 32-bit unsigned integer value, followed by the current line terminator, to the console.

Parameters:

value (uint)
The value to write.
public static void WriteLine(IFormatProvider provider, uint value)

Writes the text representation of the specified 32-bit unsigned integer value, followed by the current line terminator, to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (uint)
The value to write.
public static void WriteLine(long value)

Writes the text representation of the specified 64-bit signed integer value, followed by the current line terminator, to the console.

Parameters:

value (long)
The value to write.
public static void WriteLine(IFormatProvider provider, long value)

Writes the text representation of the specified 64-bit signed integer value, followed by the current line terminator, to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (long)
The value to write.
public static void WriteLine(ulong value)

Writes the text representation of the specified 64-bit unsigned integer value, followed by the current line terminator, to the console.

Parameters:

value (ulong)
The value to write.
public static void WriteLine(IFormatProvider provider, ulong value)

Writes the text representation of the specified 64-bit unsigned integer value, followed by the current line terminator, to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (ulong)
The value to write.
public static void WriteLine(float value)

Writes the text representation of the specified single-precision floating-point value, followed by the current line terminator, to the console.

Parameters:

value (float)
The value to write.
public static void WriteLine(IFormatProvider provider, float value)

Writes the text representation of the specified single-precision floating-point value, followed by the current line terminator, to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (float)
The value to write.
public static void WriteLine(double value)

Writes the text representation of the specified double-precision floating-point value, followed by the current line terminator, to the console.

Parameters:

value (double)
The value to write.
public static void WriteLine(IFormatProvider provider, double value)

Writes the text representation of the specified double-precision floating-point value, followed by the current line terminator, to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (double)
The value to write.
public static void WriteLine(decimal value)

Writes the text representation of the specified decimal value, followed by the current line terminator, to the console.

Parameters:

value (decimal)
The value to write.
public static void WriteLine(IFormatProvider provider, decimal value)

Writes the text representation of the specified decimal value, followed by the current line terminator, to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (decimal)
The value to write.
public static void WriteLine(bool value)

Writes the text representation of the specified boolean value, followed by the current line terminator, to the console.

Parameters:

value (bool)
The value to write.
public static void WriteLine(IFormatProvider provider, bool value)

Writes the text representation of the specified boolean value, followed by the current line terminator, to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (bool)
The value to write.
public static void WriteLine(char value)

Writes the specified Unicode character, followed by the current line terminator, value to the console.

Parameters:

value (char)
The value to write.
public static void WriteLine(IFormatProvider provider, char value)

Writes the specified Unicode character, followed by the current line terminator, value to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (char)
The value to write.
public static void WriteLine(char[] value)

Writes the specified array of Unicode characters, followed by the current line terminator, value to the console.

Parameters:

value (char[])
The value to write.
public static void WriteLine(IFormatProvider provider, char[] value)

Writes the specified array of Unicode characters, followed by the current line terminator, value to the console.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
value (char[])
The value to write.
public static void WriteLine(string format, object[] args)

Writes the text representation of the specified array of objects, followed by the current line terminator, to the console using the specified format information.

Parameters:

format (string)
A composite format string.
args (object[])
An array of objects to write.
public static void WriteLine(IFormatProvider provider, string format, object[] args)

Writes the text representation of the specified array of objects, followed by the current line terminator, to the console using the specified format information.

Parameters:

provider (IFormatProvider)
An object that supplies culture-specific formatting information.
format (string)
A composite format string.
args (object[])
An array of objects to write.