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
-
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
-
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
-
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
-
get_ansi_codes
(foreground: bool = True) → Tuple[str, …][source]¶ Get the ANSI escape codes for this color.
-
get_truecolor
(theme: TerminalTheme = None, foreground=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
¶ Check if the color is a default color.
-
property
is_system_defined
¶ 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
¶ 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.
-
classmethod