rich.style¶
-
class
rich.style.
Style
(*, color: Optional[Union[rich.color.Color, str]] = None, bgcolor: Optional[Union[rich.color.Color, str]] = None, bold: Optional[bool] = None, dim: Optional[bool] = None, italic: Optional[bool] = None, underline: Optional[bool] = None, blink: Optional[bool] = None, blink2: Optional[bool] = None, reverse: Optional[bool] = None, conceal: Optional[bool] = None, strike: Optional[bool] = None, underline2: Optional[bool] = None, frame: Optional[bool] = None, encircle: Optional[bool] = None, overline: Optional[bool] = None, link: Optional[str] = None)[source]¶ A terminal style.
A terminal style consists of a color (color), a background color (bgcolor), and a number of attributes, such as bold, italic etc. The attributes have 3 states: they can either be on (
True
), off (False
), or not set (None
).- Parameters
color (Union[Color, str], optional) – Color of terminal text. Defaults to None.
bgcolor (Union[Color, str], optional) – Color of terminal background. Defaults to None.
bold (bool, optional) – Enable bold text. Defaults to None.
dim (bool, optional) – Enable dim text. Defaults to None.
italic (bool, optional) – Enable italic text. Defaults to None.
underline (bool, optional) – Enable underlined text. Defaults to None.
blink (bool, optional) – Enabled blinking text. Defaults to None.
blink2 (bool, optional) – Enable fast blinking text. Defaults to None.
reverse (bool, optional) – Enabled reverse text. Defaults to None.
conceal (bool, optional) – Enable concealed text. Defaults to None.
strike (bool, optional) – Enable strikethrough text. Defaults to None.
underline2 (bool, optional) – Enable doubly underlined text. Defaults to None.
frame (bool, optional) – Enable framed text. Defaults to None.
encircle (bool, optional) – Enable encircled text. Defaults to None.
overline (bool, optional) – Enable overlined text. Defaults to None.
link (str, link) – Link URL. Defaults to None.
-
property
background_style
¶ A Style with background only.
-
property
bgcolor
¶ The background color or None if it is not set.
-
classmethod
chain
(*styles: rich.style.Style) → rich.style.Style[source]¶ Combine styles from positional argument in to a single style.
-
property
color
¶ The foreground color or None if it is not set.
-
classmethod
combine
(styles: Iterable[rich.style.Style]) → rich.style.Style[source]¶ Combine styles and get result.
-
copy
() → rich.style.Style[source]¶ Get a copy of this style.
- Returns
A new Style instance with identical attributes.
- Return type
-
classmethod
from_color
(color: Optional[rich.color.Color] = None, bgcolor: Optional[rich.color.Color] = None) → rich.style.Style[source]¶ Create a new style with colors and no attributes.
- Returns
A (foreground) color, or None for no color. Defaults to None. bgcolor (Optional[Color]): A (background) color, or None for no color. Defaults to None.
- Return type
color (Optional[Color])
-
get_html_style
(theme: rich.terminal_theme.TerminalTheme = None) → str[source]¶ Get a CSS style rule.
-
property
link
¶ Link text, if set.
-
property
link_id
¶ Get a link id, used in ansi code for links.
-
classmethod
normalize
(style: str) → str[source]¶ Normalize a style definition so that styles with the same effect have the same string representation.
- Parameters
style (str) – A style definition.
- Returns
Normal form of style definition.
- Return type
str
-
classmethod
null
() → rich.style.Style[source]¶ Create an ‘null’ style, equivalent to Style(), but more performant.
-
classmethod
parse
(style_definition: str) → rich.style.Style[source]¶ Parse a style definition.
- Parameters
style_definition (str) – A string containing a style.
- Raises
errors.StyleSyntaxError – If the style definition syntax is invalid.
- Returns
A Style instance.
- Return type
Style
-
classmethod
pick_first
(*values: Optional[Union[str, rich.style.Style]]) → Union[str, rich.style.Style][source]¶ Pick first non-None style.
-
render
(text: str = '', *, color_system: Optional[rich.color.ColorSystem] = <ColorSystem.TRUECOLOR: 3>, legacy_windows: bool = False) → str[source]¶ Render the ANSI codes for the style.
- Parameters
text (str, optional) – A string to style. Defaults to “”.
color_system (Optional[ColorSystem], optional) – Color system to render to. Defaults to ColorSystem.TRUECOLOR.
- Returns
A string containing ANSI style codes.
- Return type
str
-
test
(text: Optional[str] = None) → None[source]¶ Write text with style directly to terminal.
This method is for testing purposes only.
- Parameters
text (Optional[str], optional) – Text to style or None for style name.
-
property
transparent_background
¶ Check if the style specified a transparent background.
-
update_link
(link: Optional[str] = None) → rich.style.Style[source]¶ Get a copy with a different value for link.
- Parameters
link (str, optional) – New value for link. Defaults to None.
- Returns
A new Style instance.
- Return type
-
property
without_color
¶ Get a copy of the style with color removed.
-
class
rich.style.
StyleStack
(default_style: rich.style.Style)[source]¶ A stack of styles.
-
property
current
¶ Get the Style at the top of the stack.
-
pop
() → rich.style.Style[source]¶ Pop last style and discard.
- Returns
New current style (also available as stack.current)
- Return type
-
push
(style: rich.style.Style) → None[source]¶ Push a new style on to the stack.
- Parameters
style (Style) – New style to combine with current style.
-
property