rich.color

class rich.color.Color(name: str, type: rich.color.ColorType, number: Optional[int] = None, triplet: Optional[rich.color_triplet.ColorTriplet] = None)[source]

Terminal color definition.

classmethod default() rich.color.Color[source]

Get a Color instance representing the default color.

Returns

Default color.

Return type

Color

downgrade(system: rich.color.ColorSystem) rich.color.Color[source]

Downgrade a color system to a system with fewer colors.

classmethod from_ansi(number: int) rich.color.Color[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: float, green: float, blue: float) rich.color.Color[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: rich.color_triplet.ColorTriplet) rich.color.Color[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: bool = True) Tuple[str, ...][source]

Get the ANSI escape codes for this color.

get_truecolor(theme: Optional[TerminalTheme] = None, foreground: bool = True) rich.color_triplet.ColorTriplet[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: str) rich.color.Color[source]

Parse a color definition.

property system: rich.color.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: rich.color_triplet.ColorTriplet, color2: rich.color_triplet.ColorTriplet, cross_fade: float = 0.5) rich.color_triplet.ColorTriplet[source]

Blend one RGB color in to another.

rich.color.parse_rgb_hex(hex_color: str) rich.color_triplet.ColorTriplet[source]

Parse six hex characters in to RGB triplet.