Table of Contents

Class ConsoleHelper

Namespace
Xunit.Runner.Common
Assembly
xunit.v3.runner.common.dll

This class helps write colored text to the console. On Windows, it will use the built-in console functions; on Linux and macOS, it will use ANSI color codes.

public class ConsoleHelper
Inheritance
ConsoleHelper
Inherited Members

Constructors

ConsoleHelper(TextReader, TextWriter)

Initializes a new instance of the ConsoleHelper class.

public ConsoleHelper(TextReader consoleReader, TextWriter consoleWriter)

Parameters

consoleReader TextReader

The TextReader for the console (typically In).

consoleWriter TextWriter

The TextWriter for the console (typically Out).

Properties

LockObject

Gets a lock object that can be used to lock multiple calls to ConsoleHelper functions to ensure consistent output.

public object LockObject { get; }

Property Value

object

ResetColor

Equivalent to ResetColor().

public Action ResetColor { get; }

Property Value

Action

SetBackgroundColor

Equivalent to BackgroundColor.

public Action<ConsoleColor> SetBackgroundColor { get; }

Property Value

Action<ConsoleColor>

SetForegroundColor

Equivalent to ForegroundColor.

public Action<ConsoleColor> SetForegroundColor { get; }

Property Value

Action<ConsoleColor>

Methods

ReadLine()

Gets a line of input from the console.

public string? ReadLine()

Returns

string

UseAnsiColor()

Force using ANSI color instead of deciding based on OS.

public void UseAnsiColor()

Write(string?)

Writes the string value to the console.

public void Write(string? value)

Parameters

value string

Write(string, object?)

Writes a formatted string value to the console.

public void Write(string format, object? arg0)

Parameters

format string

The message format string

arg0 object

The value to replace {0} in the format string

Write(string, object?, object?)

Writes a formatted string value to the console.

public void Write(string format, object? arg0, object? arg1)

Parameters

format string

The message format string

arg0 object

The value to replace {0} in the format string

arg1 object

The value to replace {1} in the format string

Write(string, object?, object?, object?)

Writes a formatted string value to the console.

public void Write(string format, object? arg0, object? arg1, object? arg2)

Parameters

format string

The message format string

arg0 object

The value to replace {0} in the format string

arg1 object

The value to replace {1} in the format string

arg2 object

The value to replace {2} in the format string

Write(string, params object?[])

Writes a formatted string value to the console.

public void Write(string format, params object?[] args)

Parameters

format string

The message format string

args object[]

An object array that contains zero or more objects to format.

WriteLine()

Writes NewLine to the console.

public void WriteLine()

WriteLine(string?)

Writes the string value to the console, followed by NewLine.

public void WriteLine(string? value)

Parameters

value string

WriteLine(string, object?)

Writes a formatted string value to the console, followed by NewLine.

public void WriteLine(string format, object? arg0)

Parameters

format string

The message format string

arg0 object

The value to replace {0} in the format string

WriteLine(string, object?, object?)

Writes a formatted string value to the console, followed by NewLine.

public void WriteLine(string format, object? arg0, object? arg1)

Parameters

format string

The message format string

arg0 object

The value to replace {0} in the format string

arg1 object

The value to replace {1} in the format string

WriteLine(string, object?, object?, object?)

Writes a formatted string value to the console, followed by NewLine.

public void WriteLine(string format, object? arg0, object? arg1, object? arg2)

Parameters

format string

The message format string

arg0 object

The value to replace {0} in the format string

arg1 object

The value to replace {1} in the format string

arg2 object

The value to replace {2} in the format string

WriteLine(string, params object?[])

Writes a formatted string value to the console, followed by NewLine.

public void WriteLine(string format, params object?[] args)

Parameters

format string

The message format string

args object[]

An object array that contains zero or more objects to format.