Skip to content
ConsoleMonster

API Reference

Struct

RichColor

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 Boolean Equals(RichColor other) #
Returns: Boolean

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

Parameters

other ConsoleMonster.Styling.RichColor requiredposition: 0
An object to compare with this object.

Returns

true if the current object is equal to the other parameter; otherwise, false.

public override Boolean Equals(Object? obj) #
Returns: Boolean

Indicates whether this instance and a specified object are equal.

Parameters

obj System.Object? requiredposition: 0
The object to compare with the current instance.

Returns

true if obj and this instance are the same type and represent the same value; otherwise, false.

public static RichColor From(Color color) #
Returns: RichColor

An explicit colour.

Parameters

color ConsoleMonster.Styling.Color requiredposition: 0
The colour.

Returns

The rich colour.

public static RichColor FromConsoleColor(ConsoleColor color) #
Returns: RichColor

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

Parameters

color System.ConsoleColor requiredposition: 0
The console colour.

Returns

The rich colour.

public static RichColor FromRgb(Byte r, Byte g, Byte b) #
Returns: RichColor

A 24-bit colour.

Parameters

r System.Byte requiredposition: 0
Red.
g System.Byte requiredposition: 1
Green.
b System.Byte requiredposition: 2
Blue.

Returns

The rich colour.

public static RichColor FromRole(ThemeToken role) #
Returns: RichColor

A theme role, resolved at render time.

Parameters

role ConsoleMonster.Styling.ThemeToken requiredposition: 0
The role.

Returns

The rich colour.

public override Int32 GetHashCode() #
Returns: Int32

Returns the hash code for this instance.

Returns

A 32-bit signed integer that is the hash code for this instance.

public static Boolean op_Equality(RichColor left, RichColor right) #
Returns: Boolean

Equality.

Parameters

left ConsoleMonster.Styling.RichColor requiredposition: 0
Left.
right ConsoleMonster.Styling.RichColor requiredposition: 1
Right.

Returns

True when equal.

op_Implicit 3 overloads
public static RichColor op_Implicit(ConsoleColor color) #
Returns: RichColor

Converts a ConsoleColor (PowerShell mapping).

Parameters

color System.ConsoleColor requiredposition: 0
The console colour.
public static RichColor op_Implicit(Color color) #
Returns: RichColor

Converts an explicit colour.

Parameters

color ConsoleMonster.Styling.Color requiredposition: 0
The colour.
public static RichColor op_Implicit(ThemeToken role) #
Returns: RichColor

Converts a theme role.

Parameters

role ConsoleMonster.Styling.ThemeToken requiredposition: 0
The role.
public static Boolean op_Inequality(RichColor left, RichColor right) #
Returns: Boolean

Inequality.

Parameters

left ConsoleMonster.Styling.RichColor requiredposition: 0
Left.
right ConsoleMonster.Styling.RichColor requiredposition: 1
Right.

Returns

True when different.

public static RichColor Parse(String text) #
Returns: RichColor

Parses a colour (see RichColor.TryParse).

Parameters

text System.String requiredposition: 0
The text.

Returns

The colour.

Exceptions

  • FormatException – The text is not a colour.
public String ToMarkup() #
Returns: String

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

Returns

The markup word.

public override String ToString() #
Returns: String

Returns the fully qualified type name of this instance.

Returns

The fully qualified type name.

public Boolean TryGetRgb(ITheme? theme, out Byte r, out Byte g, out Byte b) #
Returns: Boolean

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

Parameters

theme ConsoleMonster.Styling.ITheme? requiredposition: 0
The theme for roles, or null for the dark theme.
r System.Byte requiredposition: 1
Red.
g System.Byte requiredposition: 2
Green.
b System.Byte requiredposition: 3
Blue.

Returns

False for the default colour.

public static Boolean TryParse(String? text, out RichColor color) #
Returns: Boolean

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 System.String? requiredposition: 0
The text.
color ConsoleMonster.Styling.RichColor requiredposition: 1
The colour.

Returns

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 Boolean IsDefault { get; } #

Whether no colour is set.