Table of Contents

Class TerminalColorHelper

Namespace
Uncreated.Warfare.Util
Assembly
Uncreated.Warfare.dll
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

string

ConsoleEscapeCharacter

ANSI escape character for virtual terminal sequences.

public const char ConsoleEscapeCharacter = '\u001b'

Field Value

char

Remarks

ForegroundResetSequence

Visual ANSI virtual termianl sequence for reseting the foreground color.

public const string ForegroundResetSequence = "\u001b[39m"

Field Value

string

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

str string
format StackColorFormatType
index int
length int
options RemoveRichTextOptions

Tags to check for and remove.

argbForeground int

Color to reset the foreground to.

argbBackground int

Color to reset the background to.

Returns

string

Exceptions

ArgumentOutOfRangeException

FromConsoleColor(ConsoleColor)

Get a UnityEngine.Color estimation of color.

public static Color FromConsoleColor(ConsoleColor color)

Parameters

color ConsoleColor

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

r byte
g byte
b byte
background bool

If the color should apply to the background of the text instead of the foreground.

Returns

string

Remarks

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

color ConsoleColor
background bool

If color should apply to the background of the text instead of the foreground.

Returns

string

Remarks

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

argb int
background bool

If argb should apply to the background of the text instead of the foreground.

Returns

string

Remarks

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

color ConsoleColor
background bool

If color should apply to the background of the text instead of the foreground.

Returns

int

Remarks

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

r byte
g byte
b byte
background bool

If the color should apply to the background of the text instead of the foreground.

Returns

int

Remarks

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

color ConsoleColor
background bool

If color should apply to the background of the text instead of the foreground.

Returns

int

Remarks

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

argb int
background bool

If argb should apply to the background of the text instead of the foreground.

Returns

int

Remarks

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

orig ReadOnlySpan<char>

Returns

string

ToArgb(Color)

Convert a UnityEngine.Color to ARGB data.

public static int ToArgb(Color color)

Parameters

color Color

Returns

int

ToArgb(Color32)

Convert a UnityEngine.Color32 to ARGB data.

public static int ToArgb(Color32 color)

Parameters

color Color32

Returns

int

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

color ConsoleColor

Returns

int

ToConsoleColor(int)

Get the closest ConsoleColor to the given ARGB data.

public static ConsoleColor ToConsoleColor(int argb)

Parameters

argb int

Returns

ConsoleColor

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

r byte
g byte
b byte
message ReadOnlySpan<char>
background bool

If the color should apply to the background of the text instead of the foreground.

Returns

string

Remarks

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

color ConsoleColor
message ReadOnlySpan<char>
background bool

If color should apply to the background of the text instead of the foreground.

Returns

string

Remarks

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

argb int
message ReadOnlySpan<char>
background bool

If argb should apply to the background of the text instead of the foreground.

Returns

string

Remarks

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

data Span<char>
r byte
g byte
b byte
background bool

If the color should apply to the background of the text instead of the foreground.

Returns

int

Remarks

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

data Span<char>
color ConsoleColor
background bool

If color should apply to the background of the text instead of the foreground.

Returns

int

Remarks

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

data Span<char>
argb int
background bool

If argb should apply to the background of the text instead of the foreground.

Returns

int

Remarks