API Reference
RichColor
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.Background
- Property RichStyle.Foreground
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.WithBackground
- Method RichStyle.WithForeground
- Method RichText.FromPieces
- Method RichText.FromPieces
- Method RichText.Gradient
- Method RichText.Gradient
- Method RichTextBuilder.Append
- Method RichTextBuilder.Append
Methods
public Boolean Equals(RichColor other) #BooleanIndicates 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
true if the current object is equal to the other parameter; otherwise, false.
public override Boolean Equals(Object? obj) #BooleanIndicates whether this instance and a specified object are equal.
Parameters
- obj System.Object?
- 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) #RichColorAn explicit colour.
Parameters
- color ConsoleMonster.Styling.Color
- The colour.
Returns
The rich colour.
public static RichColor FromConsoleColor(ConsoleColor color) #RichColorA ConsoleColor exactly as PowerShell shows it (see the remarks).
Parameters
- color System.ConsoleColor
- The console colour.
Returns
The rich colour.
public static RichColor FromRgb(Byte r, Byte g, Byte b) #RichColorA 24-bit colour.
Parameters
- r System.Byte
- Red.
- g System.Byte
- Green.
- b System.Byte
- Blue.
Returns
The rich colour.
public static RichColor FromRole(ThemeToken role) #RichColorA theme role, resolved at render time.
Parameters
- role ConsoleMonster.Styling.ThemeToken
- The role.
Returns
The rich colour.
public override Int32 GetHashCode() #Int32Returns 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) #BooleanEquality.
Parameters
- left ConsoleMonster.Styling.RichColor
- Left.
- right ConsoleMonster.Styling.RichColor
- Right.
Returns
True when equal.
public static RichColor op_Implicit(ConsoleColor color) #RichColorConverts a ConsoleColor (PowerShell mapping).
Parameters
- color System.ConsoleColor
- The console colour.
public static RichColor op_Implicit(Color color) #RichColorConverts an explicit colour.
Parameters
- color ConsoleMonster.Styling.Color
- The colour.
public static RichColor op_Implicit(ThemeToken role) #RichColorConverts a theme role.
Parameters
- role ConsoleMonster.Styling.ThemeToken
- The role.
public static Boolean op_Inequality(RichColor left, RichColor right) #BooleanInequality.
Parameters
- left ConsoleMonster.Styling.RichColor
- Left.
- right ConsoleMonster.Styling.RichColor
- Right.
Returns
True when different.
public static RichColor Parse(String text) #RichColorParses a colour (see RichColor.TryParse).
Parameters
- text System.String
- The text.
Returns
The colour.
Exceptions
FormatException– The text is not a colour.
public String ToMarkup() #StringThe colour as a markup word (pass, lime, color(214), #ff8800), or empty for the default.
Returns
The markup word.
public override String ToString() #StringReturns 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) #BooleanThe 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 System.Byte
- Red.
- g System.Byte
- Green.
- b System.Byte
- Blue.
Returns
False for the default colour.
public static Boolean TryParse(String? text, out RichColor color) #BooleanParses 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?
- The text.
- color ConsoleMonster.Styling.RichColor
- The colour.
Returns
True when the text is a colour.
Inherited Methods
Properties
public static RichColor Default { get; } #No colour: the surrounding or terminal default.