RichColor
ConsoleMonster.Styling
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.
Returned or exposed by 9
- Method RichColor.From
- Method RichColor.FromConsoleColor
- Method RichColor.FromRgb
- Method RichColor.FromRole
- Method RichColor.op_Implicit
- Method RichColor.Parse
- Property RichColor.Default
- Property RichStyle.BackgroundColor
- Property RichStyle.Color
Accepted by parameters 16
- Method RichColor.Equals
- Method RichColor.op_Equality
- Method RichColor.op_Equality
- Method RichColor.op_Inequality
- Method RichColor.op_Inequality
- Method RichColor.TryParse
- Constructor RichStyle.RichStyle
- Constructor RichStyle.RichStyle
- Method RichStyle.WithBackgroundColor
- Method RichStyle.WithColor
- Method RichText.FromPieces
- Method RichText.FromPieces
- Method RichText.Gradient
- Method RichText.Gradient
- Method RichTextBuilder.Append
- Method RichTextBuilder.Append
Methods
public bool Equals(RichColor other) #Indicates whether the current object is equal to another object of the same type.
Parameters
- other ConsoleMonster.Styling.RichColor
- 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?
- 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
- The colour.
public static RichColor FromConsoleColor(ConsoleColor color) #A ConsoleColor exactly as PowerShell shows it (see the remarks).
Parameters
- color System.ConsoleColor
- The console colour.
public static RichColor FromRgb(byte r, byte g, byte b) #A 24-bit colour.
Parameters
- r byte
- Red.
- g byte
- Green.
- b byte
- Blue.
public static RichColor FromRole(ThemeToken role) #A theme role, resolved at render time.
Parameters
- role ConsoleMonster.Styling.ThemeToken
- The role.
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
- Left.
- right ConsoleMonster.Styling.RichColor
- Right.
Returns
bool True when equal.public static RichColor op_Implicit(ConsoleColor color) #Converts a ConsoleColor (PowerShell mapping).
Parameters
- color System.ConsoleColor
- The console colour.
Returns
RichColorpublic static RichColor op_Implicit(Color color) #Converts an explicit colour.
Parameters
- color ConsoleMonster.Styling.Color
- The colour.
Returns
RichColorpublic static bool op_Inequality(RichColor left, RichColor right) #Inequality.
Parameters
- left ConsoleMonster.Styling.RichColor
- Left.
- right ConsoleMonster.Styling.RichColor
- Right.
Returns
bool True when different.public static RichColor Parse(string text) #Parses a colour (see RichColor.TryParse).
Parameters
- text string
- The text.
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?
- The theme for roles, or null for the dark theme.
- r byte
- Red.
- g byte
- Green.
- b byte
- 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?
- The text.
- color ConsoleMonster.Styling.RichColor
- The colour.
Returns
bool True when the text is a colour.Inherited Methods
Properties
public static RichColor Default { get; } #No colour: the surrounding or terminal default.