rich.style
- class rich.style.Style(*, color=None, bgcolor=None, bold=None, dim=None, italic=None, underline=None, blink=None, blink2=None, reverse=None, conceal=None, strike=None, underline2=None, frame=None, encircle=None, overline=None, link=None, meta=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.
- clear_meta_and_links()[source]
Get a copy of this style with link and meta information removed.
- Returns:
New style object.
- Return type:
- copy()[source]
Get a copy of this style.
- Returns:
A new Style instance with identical attributes.
- Return type:
- classmethod from_color(color=None, bgcolor=None)[source]
Create a new style with colors and no attributes.
- get_html_style(theme=None)[source]
Get a CSS style rule.
- Parameters:
theme (TerminalTheme | None)
- Return type:
- classmethod normalize(style)[source]
Normalize a style definition so that styles with the same effect have the same string representation.
- classmethod null()[source]
Create an ‘null’ style, equivalent to Style(), but more performant.
- Return type:
- classmethod on(meta=None, **handlers)[source]
Create a blank style with meta information.
Example
style = Style.on(click=self.on_click)
- classmethod parse(style_definition)[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
- render(text='', *, color_system=ColorSystem.TRUECOLOR, legacy_windows=False)[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.
legacy_windows (bool)
- Returns:
A string containing ANSI style codes.
- Return type:
- test(text=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.
- Return type:
None