2from typing
import Dict, List, IO, Mapping, Optional
4from .default_styles
import DEFAULT_STYLES
5from .style
import Style, StyleType
9 """A container for style information, used by :class:`~rich.console.Console`.
12 styles (Dict[str, Style], optional): A mapping of style names on to styles. Defaults to None for a theme with no styles.
13 inherit (bool, optional): Inherit default styles. Defaults to True.
16 styles: Dict[str, Style]
19 self, styles: Optional[Mapping[str, StyleType]] =
None, inherit: bool =
True
22 if styles
is not None:
31 def config(self) -> str:
32 """Get contents of a config file for this theme."""
33 config =
"[styles]\n" +
"\n".join(
34 f
"{name} = {style}" for name, style
in sorted(self.
stylesstyles.items())
40 cls, config_file: IO[str], source: Optional[str] =
None, inherit: bool =
True
42 """Load a theme from a text mode file.
45 config_file (IO[str]): An open conf file.
46 source (str, optional): The filename of the open file. Defaults to None.
47 inherit (bool, optional): Inherit default styles. Defaults to True.
50 Theme: A New theme instance.
55 theme =
Theme(styles, inherit=inherit)
60 cls, path: str, inherit: bool =
True, encoding: Optional[str] =
None
62 """Read a theme from a path.
65 path (str): Path to a config file readable by Python configparser module.
66 inherit (bool, optional): Inherit default styles. Defaults to True.
67 encoding (str, optional): Encoding of the config file. Defaults to None.
70 Theme: A new theme instance.
72 with open(path,
"rt", encoding=encoding)
as config_file:
73 return cls.
from_file(config_file, source=path, inherit=inherit)
77 """Base exception for errors related to the theme stack."""
84 theme (Theme): A theme instance
91 def push_theme(self, theme: Theme, inherit: bool =
True) ->
None:
92 """Push a theme on the top of the stack.
95 theme (Theme): A Theme instance.
96 inherit (boolean, optional): Inherit styles from current top of stack.
98 styles: Dict[str, Style]
106 """Pop (and discard) the top-most theme."""
113if __name__ ==
"__main__":
None __init__(self, Theme theme)
None push_theme(self, Theme theme, bool inherit=True)
__init__(self, Optional[Mapping[str, StyleType]] styles=None, bool inherit=True)
"Theme" from_file(cls, IO[str] config_file, Optional[str] source=None, bool inherit=True)
"Theme" read(cls, str path, bool inherit=True, Optional[str] encoding=None)