Skip to content

Theme Reference

Bases: Theme

A container for style information used by rich.console.Console.

Parameters:

Name Type Description Default
styles Dict[str, StyleType]

Mapping of style names to style definitions. Defaults to DEFAULT_STYLES.

DEFAULT_STYLES
Notes

The theme always inherits Rich's default styles (inherit=True).

Source code in src/rich_gradient/theme.py
class GradientTheme(Theme):
    """A container for style information used by ``rich.console.Console``.

    Args:
        styles (Dict[str, StyleType], optional): Mapping of style names to
            style definitions. Defaults to ``DEFAULT_STYLES``.

    Notes:
        The theme always inherits Rich's default styles (``inherit=True``).
    """

    # styles: Dict[str, Style] = {}

    def __init__(self, styles: Dict[str, StyleType] = DEFAULT_STYLES) -> None:
        """Initialize the theme with the given styles."""
        super().__init__(styles=styles, inherit=True)
        self._theme: Theme = Theme(DEFAULT_STYLES)
        self._styles: Dict[str, StyleType] = styles

    @property
    def theme(self) -> Theme:
        return self._theme

    @theme.setter
    def theme(self, theme: Theme = Theme(DEFAULT_STYLES)) -> None:
        self._theme = theme

    def __call__(self) -> Theme:
        return self.theme

    def __repr__(self) -> str:
        return f"GradientTheme({self._styles!r})"

    def __rich__(self) -> Table:
        return styles_table()

    def __getitem__(self, name: str) -> Style:
        return Style.parse(str(self._styles[name]))

    @classmethod
    def get_theme_table(cls) -> Table:
        """Get a table of all styles in the theme."""
        return styles_table()

__init__(styles=DEFAULT_STYLES)

Initialize the theme with the given styles.

Source code in src/rich_gradient/theme.py
def __init__(self, styles: Dict[str, StyleType] = DEFAULT_STYLES) -> None:
    """Initialize the theme with the given styles."""
    super().__init__(styles=styles, inherit=True)
    self._theme: Theme = Theme(DEFAULT_STYLES)
    self._styles: Dict[str, StyleType] = styles

get_theme_table() classmethod

Get a table of all styles in the theme.

Source code in src/rich_gradient/theme.py
@classmethod
def get_theme_table(cls) -> Table:
    """Get a table of all styles in the theme."""
    return styles_table()

Note: GRADIENT_TERMINAL_THEME is a terminal theme constant exported from

rich_gradient.theme for use with Console.save_svg. It is not included in

the auto-generated API table above but is part of the public API.