Get a style from a Pygments class.
(self, token_type: TokenType)
| 155 | self._background_style = Style(bgcolor=self._background_color) |
| 156 | |
| 157 | def get_style_for_token(self, token_type: TokenType) -> Style: |
| 158 | """Get a style from a Pygments class.""" |
| 159 | try: |
| 160 | return self._style_cache[token_type] |
| 161 | except KeyError: |
| 162 | try: |
| 163 | pygments_style = self._pygments_style_class.style_for_token(token_type) |
| 164 | except KeyError: |
| 165 | style = Style.null() |
| 166 | else: |
| 167 | color = pygments_style["color"] |
| 168 | bgcolor = pygments_style["bgcolor"] |
| 169 | style = Style( |
| 170 | color="#" + color if color else "#000000", |
| 171 | bgcolor="#" + bgcolor if bgcolor else self._background_color, |
| 172 | bold=pygments_style["bold"], |
| 173 | italic=pygments_style["italic"], |
| 174 | underline=pygments_style["underline"], |
| 175 | ) |
| 176 | self._style_cache[token_type] = style |
| 177 | return style |
| 178 | |
| 179 | def get_background_style(self) -> Style: |
| 180 | return self._background_style |