Class TerminalColorHelper
public static class TerminalColorHelper
- Inheritance
-
TerminalColorHelper
- Inherited Members
Fields
BackgroundResetSequence
Visual ANSI virtual termianl sequence for reseting the background color.
public const string BackgroundResetSequence = "\u001b[49m"
Field Value
ConsoleEscapeCharacter
ANSI escape character for virtual terminal sequences.
public const char ConsoleEscapeCharacter = '\u001b'
Field Value
Remarks
See https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#text-formatting.
ForegroundResetSequence
Visual ANSI virtual termianl sequence for reseting the foreground color.
public const string ForegroundResetSequence = "\u001b[39m"
Field Value
Methods
ConvertRichTextToVirtualTerminalSequences(string, StackColorFormatType, int, int, RemoveRichTextOptions, int, int)
Remove rich text tags from text, and replace <color> and <mark> tags with virtual terminal sequences (depending on the current configuration).
[Pure]
public static string ConvertRichTextToVirtualTerminalSequences(string str, StackColorFormatType format, int index = 0, int length = -1, RemoveRichTextOptions options = RemoveRichTextOptions.All, int argbForeground = -9013642, int argbBackground = -15987700)
Parameters
strstringformatStackColorFormatTypeindexintlengthintoptionsRemoveRichTextOptionsTags to check for and remove.
argbForegroundintColor to reset the foreground to.
argbBackgroundintColor to reset the background to.
Returns
Exceptions
FromConsoleColor(ConsoleColor)
Get a UnityEngine.Color estimation of color.
public static Color FromConsoleColor(ConsoleColor color)
Parameters
colorConsoleColor
Returns
- Color
GetTerminalColorSequence(byte, byte, byte, bool)
Converts an RGB value to an extended color virtual terminal sequence.
public static string GetTerminalColorSequence(byte r, byte g, byte b, bool background = false)
Parameters
rbytegbytebbytebackgroundboolIf the color should apply to the background of the text instead of the foreground.
Returns
Remarks
See https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#extended-colors.
GetTerminalColorSequence(ConsoleColor, bool)
Converts a ConsoleColor value to an 8-bit color virtual terminal sequence.
public static string GetTerminalColorSequence(ConsoleColor color, bool background = false)
Parameters
colorConsoleColorbackgroundboolIf
colorshould apply to the background of the text instead of the foreground.
Returns
Remarks
See https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#text-formatting.
GetTerminalColorSequence(int, bool)
Converts an ARGB value to an extended color virtual terminal sequence.
If the alpha bits (high 8 bits) are zero, the color will be interpreted as a ConsoleColor.
public static string GetTerminalColorSequence(int argb, bool background = false)
Parameters
argbintbackgroundboolIf
argbshould apply to the background of the text instead of the foreground.
Returns
Remarks
See https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#extended-colors.
GetTerminalColorSequenceCode(ConsoleColor, bool)
Gets the number used to start a foreground or background color in an 8-bit color virtual terminal sequence.
public static int GetTerminalColorSequenceCode(ConsoleColor color, bool background = false)
Parameters
colorConsoleColorbackgroundboolIf
colorshould apply to the background of the text instead of the foreground.
Returns
Remarks
See https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#text-formatting.
GetTerminalColorSequenceLength(byte, byte, byte, bool)
Gets the length of an RGB value as an extended color virtual terminal sequence.
public static int GetTerminalColorSequenceLength(byte r, byte g, byte b, bool background = false)
Parameters
rbytegbytebbytebackgroundboolIf the color should apply to the background of the text instead of the foreground.
Returns
Remarks
See https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#extended-colors.
GetTerminalColorSequenceLength(ConsoleColor, bool)
Gets the length of a ConsoleColor value as an 8-bit color virtual terminal sequence.
public static int GetTerminalColorSequenceLength(ConsoleColor color, bool background = false)
Parameters
colorConsoleColorbackgroundboolIf
colorshould apply to the background of the text instead of the foreground.
Returns
Remarks
See https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#text-formatting.
GetTerminalColorSequenceLength(int, bool)
Gets the length of an ARGB value as an extended color virtual terminal sequence.
If the alpha bits (high 8 bits) are zero, the color will be interpreted as a ConsoleColor.
public static int GetTerminalColorSequenceLength(int argb, bool background = false)
Parameters
argbintbackgroundboolIf
argbshould apply to the background of the text instead of the foreground.
Returns
Remarks
See https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#extended-colors.
RemoveVirtualTerminalSequences(ReadOnlySpan<char>)
Effeciently removes any virtual terminal sequences from a string and returns the result as a copy.
public static string RemoveVirtualTerminalSequences(ReadOnlySpan<char> orig)
Parameters
origReadOnlySpan<char>
Returns
ToArgb(Color)
Convert a UnityEngine.Color to ARGB data.
public static int ToArgb(Color color)
Parameters
colorColor
Returns
ToArgb(Color32)
Convert a UnityEngine.Color32 to ARGB data.
public static int ToArgb(Color32 color)
Parameters
colorColor32
Returns
ToArgbRepresentation(ConsoleColor)
Convert to ConsoleColor to an int which will be reinterpreted as ARGB later on. This is done by making the alpha value zero.
public static int ToArgbRepresentation(ConsoleColor color)
Parameters
colorConsoleColor
Returns
ToConsoleColor(int)
Get the closest ConsoleColor to the given ARGB data.
public static ConsoleColor ToConsoleColor(int argb)
Parameters
argbint
Returns
WrapMessageWithTerminalColorSequence(byte, byte, byte, ReadOnlySpan<char>, bool)
Wraps text in an extended color virtual terminal sequence.
public static string WrapMessageWithTerminalColorSequence(byte r, byte g, byte b, ReadOnlySpan<char> message, bool background = false)
Parameters
rbytegbytebbytemessageReadOnlySpan<char>backgroundboolIf the color should apply to the background of the text instead of the foreground.
Returns
Remarks
See https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#extended-colors.
WrapMessageWithTerminalColorSequence(ConsoleColor, ReadOnlySpan<char>, bool)
Wraps text in an 8-bit color virtual terminal sequence.
public static string WrapMessageWithTerminalColorSequence(ConsoleColor color, ReadOnlySpan<char> message, bool background = false)
Parameters
colorConsoleColormessageReadOnlySpan<char>backgroundboolIf
colorshould apply to the background of the text instead of the foreground.
Returns
Remarks
See https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#text-formatting.
WrapMessageWithTerminalColorSequence(int, ReadOnlySpan<char>, bool)
Wraps text in an extended color virtual terminal sequence.
If the alpha bits (high 8 bits) are zero, the color will be interpreted as a ConsoleColor.
public static string WrapMessageWithTerminalColorSequence(int argb, ReadOnlySpan<char> message, bool background = false)
Parameters
argbintmessageReadOnlySpan<char>backgroundboolIf
argbshould apply to the background of the text instead of the foreground.
Returns
Remarks
See https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#extended-colors.
WriteTerminalColorSequence(Span<char>, byte, byte, byte, bool)
Converts an ARGB value to an extended color virtual terminal sequence.
public static int WriteTerminalColorSequence(Span<char> data, byte r, byte g, byte b, bool background = false)
Parameters
dataSpan<char>rbytegbytebbytebackgroundboolIf the color should apply to the background of the text instead of the foreground.
Returns
Remarks
See https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#extended-colors.
WriteTerminalColorSequence(Span<char>, ConsoleColor, bool)
Converts a ConsoleColor value to an 8-bit color virtual terminal sequence.
public static int WriteTerminalColorSequence(Span<char> data, ConsoleColor color, bool background = false)
Parameters
dataSpan<char>colorConsoleColorbackgroundboolIf
colorshould apply to the background of the text instead of the foreground.
Returns
Remarks
See https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#text-formatting.
WriteTerminalColorSequence(Span<char>, int, bool)
Converts an ARGB value to an extended color virtual terminal sequence.
If the alpha bits (high 8 bits) are zero, the color will be interpreted as a ConsoleColor.
public static int WriteTerminalColorSequence(Span<char> data, int argb, bool background = false)
Parameters
dataSpan<char>argbintbackgroundboolIf
argbshould apply to the background of the text instead of the foreground.