Skip to content

Commit

Permalink
fix pygments key error
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Mar 15, 2020
1 parent 15df025 commit 6b088ea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.7.2] - 2020-03-15

### Fixed

- KeyError for missing pygments style

## [0.7.1] - 2020-03-13

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "rich"
homepage = "https://github.com/willmcgugan/rich"
documentation = "https://rich.readthedocs.io/en/latest/"
version = "0.7.1"
version = "0.7.2"
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
authors = ["Will McGugan <willmcgugan@gmail.com>"]
license = "MIT"
Expand Down
24 changes: 14 additions & 10 deletions rich/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,20 @@ def _get_theme_style(self, token_type) -> Style:
if token_type in self._style_cache:
style = self._style_cache[token_type]
else:
pygments_style = self._pygments_style_class.style_for_token(token_type)
color = pygments_style["color"]
bgcolor = pygments_style["bgcolor"]
style = Style(
color="#" + color if color else "#000000",
bgcolor="#" + bgcolor if bgcolor else self._background_color,
bold=pygments_style["bold"],
italic=pygments_style["italic"],
underline=pygments_style["underline"],
)
try:
pygments_style = self._pygments_style_class.style_for_token(token_type)
except KeyError:
style = Style()
else:
color = pygments_style["color"]
bgcolor = pygments_style["bgcolor"]
style = Style(
color="#" + color if color else "#000000",
bgcolor="#" + bgcolor if bgcolor else self._background_color,
bold=pygments_style["bold"],
italic=pygments_style["italic"],
underline=pygments_style["underline"],
)
self._style_cache[token_type] = style

return style
Expand Down

0 comments on commit 6b088ea

Please sign in to comment.