Skip to content
ConsoleMonster
Struct

RichColor

ConsoleMonster.Styling

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

A colour for rich text: an explicit Color (hex, RGB, 256-colour index, palette name), a ConsoleColor exactly as PowerShell shows it, or a theme role (Pass, Fail, Warn, Info, Muted, Accent...) that is resolved when the text is rendered, so it follows the light or dark theme.

Inheritance

  • ValueType
  • RichColor

Remarks

ConsoleColor names map the way Write-Host shows them, not by name: PowerShell's DarkRed is ANSI red (index 1) and Red is bright red (index 9); Gray is index 7 and DarkGray index 8. They are emitted as the 16-colour codes, so the terminal's own palette shows them exactly like Write-Host -ForegroundColor.

Usage

Explore 25 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 16

Methods

Equals 2 overloads
public bool Equals(RichColor other) #

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

Parameters

other ConsoleMonster.Styling.RichColor 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 RichColor From(Color color) #

An explicit colour.

Parameters

color ConsoleMonster.Styling.Color required
The colour.

Returns

RichColor The rich colour.
public static RichColor FromConsoleColor(ConsoleColor color) #

A ConsoleColor exactly as PowerShell shows it (see the remarks).

Parameters

color System.ConsoleColor required
The console colour.

Returns

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

A 24-bit colour.

Parameters

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

Returns

RichColor The rich colour.
public static RichColor FromRole(ThemeToken role) #

A theme role, resolved at render time.

Parameters

role ConsoleMonster.Styling.ThemeToken required
The role.

Returns

RichColor The rich 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(RichColor left, RichColor right) #

Equality.

Parameters

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

Returns

bool True when equal.
op_Implicit 3 overloads
public static RichColor op_Implicit(ConsoleColor color) #

Converts a ConsoleColor (PowerShell mapping).

Parameters

color System.ConsoleColor required
The console colour.

Returns

RichColor
public static RichColor op_Implicit(Color color) #

Converts an explicit colour.

Parameters

color ConsoleMonster.Styling.Color required
The colour.

Returns

RichColor
public static RichColor op_Implicit(ThemeToken role) #

Converts a theme role.

Parameters

role ConsoleMonster.Styling.ThemeToken required
The role.

Returns

RichColor
public static bool op_Inequality(RichColor left, RichColor right) #

Inequality.

Parameters

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

Returns

bool True when different.
public static RichColor Parse(string text) #

Parses a colour (see RichColor.TryParse).

Parameters

text string required
The text.

Returns

RichColor The colour.

Exceptions

  • FormatException – The text is not a colour.
public string ToMarkup() #

The colour as a markup word (pass, lime, color(214), #ff8800), or empty for the default.

Returns

string The markup word.
public override string ToString() #

Returns the fully qualified type name of this instance.

Returns

string The fully qualified type name.
public bool TryGetRgb(ITheme? theme, out byte r, out byte g, out byte b) #

The 24-bit value of the colour (roles resolved with theme), for gradients and blending.

Parameters

theme ConsoleMonster.Styling.ITheme? required
The theme for roles, or null for the dark theme.
r byte required
Red.
g byte required
Green.
b byte required
Blue.

Returns

bool False for the default colour.
public static bool TryParse(string? text, out RichColor color) #

Parses a colour: a ConsoleColor name with the PowerShell mapping (Red, DarkCyan; grey and darkgrey spell Gray and DarkGray), a theme role (Pass, Muted), #RRGGBB, rgb(r,g,b), r,g,b, a 256-colour index, or a markup palette name (orange1, cadetblue). palette.darkred asks for the palette colour where a bare name would be the ConsoleColor.

Parameters

text string? required
The text.
color ConsoleMonster.Styling.RichColor required
The colour.

Returns

bool True when the text is a colour.

Properties

public static RichColor Default { get; } #

No colour: the surrounding or terminal default.

public Color Color { get; } #

The explicit colour (default when this is a role).

public ThemeToken? Role { get; } #

The theme role, or null for an explicit colour.

public bool IsDefault { get; } #

Whether no colour is set.