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

Method get_style_for_token

rich/syntax.py:192–210  ·  view source on GitHub ↗

Look up style in the style map.

(self, token_type: TokenType)

Source from the content-addressed store, hash-verified

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

Callers 1

test_ansi_themeFunction · 0.95

Calls 1

get_styleFunction · 0.85

Tested by 1

test_ansi_themeFunction · 0.76