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

Class ThemeStack

rich/theme.py:81–111  ·  rich/theme.py::ThemeStack

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

Source from the content-addressed store, hash-verified

79
80
81class ThemeStack:
82 class="st">"""A stack of themes.
83
84 Args:
85 theme (Theme): A theme instance
86 class="st">"""
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 class="st">"""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 class="st">"""
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 class="st">""class="st">"Pop (and discard) the top-most theme."class="st">""
108 if len(self._entries) == 1:
109 raise ThemeStackError(class="st">"Unable to pop base theme")
110 self._entries.pop()
111 self.get = self._entries[-1].get
112
113
114if __name__ == class="st">"__main__": class="cm"># 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