MCPcopy
hub / github.com/Textualize/rich / ThemeStack

Class ThemeStack

rich/theme.py:81–111  ·  view source on GitHub ↗

A stack of themes. Args: theme (Theme): A theme instance

Source from the content-addressed store, hash-verified

79
80
81class ThemeStack:
82 """A stack of themes.
83
84 Args:
85 theme (Theme): A theme instance
86 """
87
88 def __init__(self, theme: Theme) -> None:
89 self._entries: List[Dict[str, Style]] = [theme.styles]
90 self.get = self._entries[-1].get
91
92 def push_theme(self, theme: Theme, inherit: bool = True) -> None:
93 """Push a theme on the top of the stack.
94
95 Args:
96 theme (Theme): A Theme instance.
97 inherit (boolean, optional): Inherit styles from current top of stack.
98 """
99 styles: Dict[str, Style]
100 styles = (
101 {**self._entries[-1], **theme.styles} if inherit else theme.styles.copy()
102 )
103 self._entries.append(styles)
104 self.get = self._entries[-1].get
105
106 def pop_theme(self) -> None:
107 """Pop (and discard) the top-most theme."""
108 if len(self._entries) == 1:
109 raise ThemeStackError("Unable to pop base theme")
110 self._entries.pop()
111 self.get = self._entries[-1].get
112
113
114if __name__ == "__main__": # pragma: no cover

Callers 2

test_theme_stackFunction · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by 1

test_theme_stackFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…