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

Class ANSISyntaxTheme

rich/syntax.py:183–213  ·  view source on GitHub ↗

Syntax theme to use standard colors.

Source from the content-addressed store, hash-verified

181
182
183class ANSISyntaxTheme(SyntaxTheme):
184 """Syntax theme to use standard colors."""
185
186 def __init__(self, style_map: Dict[TokenType, Style]) -> None:
187 self.style_map = style_map
188 self._missing_style = Style.null()
189 self._background_style = Style.null()
190 self._style_cache: Dict[TokenType, Style] = {}
191
192 def get_style_for_token(self, token_type: TokenType) -> Style:
193 """Look up style in the style map."""
194 try:
195 return self._style_cache[token_type]
196 except KeyError:
197 # Styles form a hierarchy
198 # We need to go from most to least specific
199 # e.g. ("foo", "bar", "baz") to ("foo", "bar") to ("foo",)
200 get_style = self.style_map.get
201 token = tuple(token_type)
202 style = self._missing_style
203 while token:
204 _style = get_style(token)
205 if _style is not None:
206 style = _style
207 break
208 token = token[:-1]
209 self._style_cache[token_type] = style
210 return style
211
212 def get_background_style(self) -> Style:
213 return self._background_style
214
215
216SyntaxPosition = Tuple[int, int]

Callers 2

test_ansi_themeFunction · 0.90
get_themeMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_ansi_themeFunction · 0.72