Skip to content
ConsoleMonster
Struct

Color

ConsoleMonster.Styling

Namespace
ConsoleMonster.Styling
Assembly
ConsoleMonster
Base
ValueType
Implements
IEquatable<Color>
Modifiers
sealed

A terminal colour: the default colour, a 16- or 256-palette index, or 24-bit RGB. Colours are downsampled to the profile's ColorDepth at encoding time.

Inheritance

  • ValueType
  • Color

Usage

Explore 66 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Accepted by parameters 42

Methods

public Color Blend(Color other, double amount) #

Linearly blends towards another colour in RGB space (used for gradients).

Parameters

other ConsoleMonster.Styling.Color required
The target colour.
amount double required
0 returns this colour, 1 returns other.

Returns

Color An RGB colour.
public Color Downsample(ColorDepth depth) #

Converts the colour to the closest colour representable at depth.

Parameters

depth ConsoleMonster.Capabilities.ColorDepth required
The target colour depth.

Returns

Color The downsampled colour; Color.Default for ColorDepth.None.
Equals 2 overloads
public bool Equals(Color other) #

Indicates whether the current object is equal to another object of the same type.

Parameters

other ConsoleMonster.Styling.Color required
An object to compare with this object.

Returns

bool true if the current object is equal to the other parameter; otherwise, false.
public override bool Equals(object? obj) #

Indicates whether this instance and a specified object are equal.

Parameters

obj object? required
The object to compare with the current instance.

Returns

bool true if obj and this instance are the same type and represent the same value; otherwise, false.
public static Color FromAnsi16(int index) #

Creates one of the 16 standard colours.

Parameters

index int required
Index 0-15 (0 black, 1 maroon, 2 green, 3 olive, 4 navy, 5 purple, 6 teal, 7 silver, 8 grey, 9 red, 10 lime, 11 yellow, 12 blue, 13 fuchsia, 14 aqua, 15 white).

Returns

Color The colour.
public static Color FromAnsi256(int index) #

Creates an xterm 256-palette colour.

Parameters

index int required
Index 0-255.

Returns

Color The colour.
public static Color FromConsoleColor(ConsoleColor color) #

Converts a host console color to its corresponding ANSI 16 palette color.

Parameters

color System.ConsoleColor required
The host color, such as a foreground or background snapshot.

Returns

Color The ANSI color, using the canonical console palette mapping.

Exceptions

  • ArgumentOutOfRangeException – The value is not one of the 16 console colors.
public static Color FromHex(string hex) #

Parses #rgb or #rrggbb.

Parameters

hex string required
The hex string, with or without the leading #.

Returns

Color The colour.
public static Color FromRgb(byte r, byte g, byte b) #

Creates a 24-bit colour.

Parameters

r byte required
Red.
g byte required
Green.
b byte required
Blue.

Returns

Color The colour.
public override int GetHashCode() #

Returns the hash code for this instance.

Returns

int A 32-bit signed integer that is the hash code for this instance.
public static bool op_Equality(Color left, Color right) #

Equality operator.

Parameters

left ConsoleMonster.Styling.Color required
Left.
right ConsoleMonster.Styling.Color required
Right.

Returns

bool Whether equal.
public static bool op_Inequality(Color left, Color right) #

Inequality operator.

Parameters

left ConsoleMonster.Styling.Color required
Left.
right ConsoleMonster.Styling.Color required
Right.

Returns

bool Whether different.
public void ToRgb(out byte r, out byte g, out byte b) #

Returns the approximate RGB value of the colour (palette colours use the Campbell scheme).

Parameters

r byte required
Red.
g byte required
Green.
b byte required
Blue.
public override string ToString() #

Returns the fully qualified type name of this instance.

Returns

string The fully qualified type name.
public static bool TryParse(string? text, out Color color) #

Parses a colour the way Spectre.Console markup does: one of the 256 xterm names (red, aqua, orange1, cadetblue, grey50, deepskyblue4_1), default, #rrggbb, #rgb, rgb(r,g,b), or a 256-palette index (208 or color(208)). Where an xterm name and a ConsoleColor name collide (darkred, darkcyan), the xterm colour wins here, as in Spectre markup; ConsoleColor names that are not xterm names (darkgray, darkyellow, magenta, cyan) keep the PowerShell mapping. Either meaning can be asked for explicitly: console.darkred is the ConsoleColor as Write-Host shows it, palette.darkred the palette colour. RichColor.TryParse reads bare ConsoleColor names first.

Parameters

text string? required
The text to parse.
color ConsoleMonster.Styling.Color required
The parsed colour.

Returns

bool Whether parsing succeeded.

Properties

public static Color Default { get; } #

The terminal's default colour.

public ColorKind Kind { get; } #

How the colour is expressed.

public byte Index { get; } #

Palette index for ColorKind.Ansi16 and ColorKind.Ansi256.

public byte R { get; } #

Red component for ColorKind.Rgb.

public byte G { get; } #

Green component for ColorKind.Rgb.

public byte B { get; } #

Blue component for ColorKind.Rgb.

public bool IsDefault { get; } #

Whether this is the terminal default.