Table of Contents

Struct Color

Namespace
Retro.Crt
Assembly
Retro.Crt.dll

A console color in 24-bit truecolor, an xterm 256-palette index, or one of the 16 standard SGR slots. Use Rgb(byte, byte, byte) for arbitrary colors, Indexed256(byte) for xterm palette entries, and the named static fields (LightCyan, Brown, …) for the classic DOS palette mapped onto the user's terminal theme.

public readonly record struct Color : IEquatable<Color>
Implements
Inherited Members

Fields

Black

public static readonly Color Black

Field Value

Color

Brown

public static readonly Color Brown

Field Value

Color

DarkBlue

public static readonly Color DarkBlue

Field Value

Color

DarkCyan

public static readonly Color DarkCyan

Field Value

Color

DarkGray

public static readonly Color DarkGray

Field Value

Color

DarkGreen

public static readonly Color DarkGreen

Field Value

Color

DarkMagenta

public static readonly Color DarkMagenta

Field Value

Color

DarkRed

public static readonly Color DarkRed

Field Value

Color

LightBlue

public static readonly Color LightBlue

Field Value

Color

LightCyan

public static readonly Color LightCyan

Field Value

Color

LightGray

public static readonly Color LightGray

Field Value

Color

LightGreen

public static readonly Color LightGreen

Field Value

Color

LightMagenta

public static readonly Color LightMagenta

Field Value

Color

LightRed

public static readonly Color LightRed

Field Value

Color

White

public static readonly Color White

Field Value

Color

Yellow

public static readonly Color Yellow

Field Value

Color

Properties

B

public byte B { get; }

Property Value

byte

G

public byte G { get; }

Property Value

byte

Index

Palette index. 0..15 for Standard16, 0..255 for Xterm256; ignored for truecolor.

public byte Index { get; }

Property Value

byte

Mode

public ColorMode Mode { get; }

Property Value

ColorMode

R

public byte R { get; }

Property Value

byte

Methods

For(ColorDepth)

Return a color that depth can render exactly. Truecolor values get quantized to the closest 256-palette entry or BIOS-16 anchor; Xterm256 values get folded into Standard16 if the depth permits only 16 colors. Standard16 values pass through unchanged — they always render correctly. Returns the default(Color) sentinel for None; callers should check capability before emitting.

public Color For(ColorDepth depth)

Parameters

depth ColorDepth

Returns

Color

FromHex(string)

Parse a CSS hex string: #RRGGBB or #RGB (case insensitive, with or without leading #). Returns a truecolor Color. Throws FormatException on bad input.

public static Color FromHex(string hex)

Parameters

hex string

Returns

Color

Indexed256(byte)

xterm 256-palette entry. Index 0..15 mirrors the user's terminal theme (same as Standard(byte)); 16..231 is the 6×6×6 RGB cube; 232..255 is the 24-step grayscale ramp.

public static Color Indexed256(byte index)

Parameters

index byte

Returns

Color

QuantizeToStandard16(byte, byte, byte)

Public quantizer — find the closest BIOS-16 anchor for an arbitrary RGB triple. Useful when consumers want to pre-render theme colors for terminals that lack truecolor.

public static byte QuantizeToStandard16(byte r, byte g, byte b)

Parameters

r byte
g byte
b byte

Returns

byte

QuantizeToXterm256(byte, byte, byte)

Public quantizer — find the closest xterm 256-palette entry for an arbitrary RGB triple. Returns an index in 16..255 (never the terminal-themed 0..15 slots).

public static byte QuantizeToXterm256(byte r, byte g, byte b)

Parameters

r byte
g byte
b byte

Returns

byte

Rgb(byte, byte, byte)

24-bit truecolor.

public static Color Rgb(byte r, byte g, byte b)

Parameters

r byte
g byte
b byte

Returns

Color

TryFromHex(string?, out Color)

Non-throwing companion to FromHex(string).

public static bool TryFromHex(string? hex, out Color color)

Parameters

hex string
color Color

Returns

bool

TryFromName(string?, out Color)

Look up one of the named DOS palette entries by name (case insensitive). Accepts canonical names like "LightCyan" as well as the lower-cased variant.

public static bool TryFromName(string? name, out Color color)

Parameters

name string
color Color

Returns

bool

TryParse(string?, out Color)

Parse either a hex string (#RRGGBB / #RGB) or a DOS palette name ("LightCyan"). Hex takes priority when input starts with #.

public static bool TryParse(string? text, out Color color)

Parameters

text string
color Color

Returns

bool