Skip to content
ConsoleMonster

API Reference

Struct

Color

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 46 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 14

Accepted by parameters 32

Methods

public Color Blend(Color other, Double amount) #
Returns: Color

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

Parameters

other ConsoleMonster.Styling.Color requiredposition: 0
The target colour.
amount System.Double requiredposition: 1
0 returns this colour, 1 returns other.

Returns

An RGB colour.

public Color Downsample(ColorDepth depth) #
Returns: Color

Converts the colour to the closest colour representable at depth.

Parameters

depth ConsoleMonster.Capabilities.ColorDepth requiredposition: 0
The target colour depth.

Returns

The downsampled colour; Color.Default for ColorDepth.None.

Equals 2 overloads
public Boolean Equals(Color other) #
Returns: Boolean

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

Parameters

other ConsoleMonster.Styling.Color 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 Color FromAnsi16(Int32 index) #
Returns: Color

Creates one of the 16 standard colours.

Parameters

index System.Int32 requiredposition: 0
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

The colour.

public static Color FromAnsi256(Int32 index) #
Returns: Color

Creates an xterm 256-palette colour.

Parameters

index System.Int32 requiredposition: 0
Index 0-255.

Returns

The colour.

public static Color FromHex(String hex) #
Returns: Color

Parses #rgb or #rrggbb.

Parameters

hex System.String requiredposition: 0
The hex string, with or without the leading #.

Returns

The colour.

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

Creates 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 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(Color left, Color right) #
Returns: Boolean

Equality operator.

Parameters

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

Returns

Whether equal.

public static Boolean op_Inequality(Color left, Color right) #
Returns: Boolean

Inequality operator.

Parameters

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

Returns

Whether different.

public Void ToRgb(out Byte r, out Byte g, out Byte b) #
Returns: Void

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

Parameters

r System.Byte requiredposition: 0
Red.
g System.Byte requiredposition: 1
Green.
b System.Byte requiredposition: 2
Blue.
public override String ToString() #
Returns: String

Returns the fully qualified type name of this instance.

Returns

The fully qualified type name.

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

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

Returns

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

Whether this is the terminal default.