rich.color

class rich.color.Color(name, type, number=None, triplet=None)[source]

Terminal color definition.

Parameters
classmethod default()[source]

Get a Color instance representing the default color.

Returns

Default color.

Return type

Color

downgrade(system)[source]

Downgrade a color system to a system with fewer colors.

Parameters

system (ColorSystem) –

Return type

Color

classmethod from_ansi(number)[source]

Create a Color number from it’s 8-bit ansi number.

Parameters

number (int) – A number between 0-255 inclusive.

Returns

A new Color instance.

Return type

Color

classmethod from_rgb(red, green, blue)[source]

Create a truecolor from three color components in the range(0->255).

Parameters
  • red (float) – Red component in range 0-255.

  • green (float) – Green component in range 0-255.

  • blue (float) – Blue component in range 0-255.

Returns

A new color object.

Return type

Color

classmethod from_triplet(triplet)[source]

Create a truecolor RGB color from a triplet of values.

Parameters

triplet (ColorTriplet) – A color triplet containing red, green and blue components.

Returns

A new color object.

Return type

Color

get_ansi_codes(foreground=True)[source]

Get the ANSI escape codes for this color.

Parameters

foreground (bool) –

Return type

Tuple[str, …]

get_truecolor(theme=None, foreground=True)[source]

Get an equivalent color triplet for this color.

Parameters
  • theme (TerminalTheme, optional) – Optional terminal theme, or None to use default. Defaults to None.

  • foreground (bool, optional) – True for a foreground color, or False for background. Defaults to True.

Returns

A color triplet containing RGB components.

Return type

ColorTriplet

property is_default: bool

Check if the color is a default color.

property is_system_defined: bool

Check if the color is ultimately defined by the system.

property name

The name of the color (typically the input to Color.parse).

property number

The color number, if a standard color, or None.

classmethod parse(color)[source]

Parse a color definition.

Parameters

color (str) –

Return type

Color

property system: ColorSystem

Get the native color system for this color.

property triplet

A triplet of color components, if an RGB color.

property type

The type of the color.

exception rich.color.ColorParseError[source]

The color could not be parsed.

class rich.color.ColorSystem(value)[source]

One of the 3 color system supported by terminals.

class rich.color.ColorType(value)[source]

Type of color stored in Color class.

rich.color.blend_rgb(color1, color2, cross_fade=0.5)[source]

Blend one RGB color in to another.

Parameters
  • color1 (ColorTriplet) –

  • color2 (ColorTriplet) –

  • cross_fade (float) –

Return type

ColorTriplet

rich.color.parse_rgb_hex(hex_color)[source]

Parse six hex characters in to RGB triplet.

Parameters

hex_color (str) –

Return type

ColorTriplet