Class ConsoleHelper
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
consoleReaderTextReaderThe TextReader for the console (typically In).
consoleWriterTextWriterThe 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
ResetColor
Equivalent to ResetColor().
public Action ResetColor { get; }
Property Value
SetBackgroundColor
Equivalent to BackgroundColor.
public Action<ConsoleColor> SetBackgroundColor { get; }
Property Value
SetForegroundColor
Equivalent to ForegroundColor.
public Action<ConsoleColor> SetForegroundColor { get; }
Property Value
Methods
ReadLine()
Gets a line of input from the console.
public string? ReadLine()
Returns
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
valuestring
Write(string, object?)
Writes a formatted string value to the console.
public void Write(string format, object? arg0)
Parameters
Write(string, object?, object?)
Writes a formatted string value to the console.
public void Write(string format, object? arg0, object? arg1)
Parameters
formatstringThe message format string
arg0objectThe value to replace {0} in the format string
arg1objectThe 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
formatstringThe message format string
arg0objectThe value to replace {0} in the format string
arg1objectThe value to replace {1} in the format string
arg2objectThe 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
formatstringThe message format string
argsobject[]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
valuestring
WriteLine(string, object?)
Writes a formatted string value to the console, followed by NewLine.
public void WriteLine(string format, object? arg0)
Parameters
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
formatstringThe message format string
arg0objectThe value to replace {0} in the format string
arg1objectThe 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
formatstringThe message format string
arg0objectThe value to replace {0} in the format string
arg1objectThe value to replace {1} in the format string
arg2objectThe 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)