fix(styles): fall back to default style if style not found (#4906)

The fallback is already the default behavior if the user has `pygments`
installed, but if they don't we were awkwardly bailing out here and
preventing startup.
This commit is contained in:
Gil Forsyth 2022-08-03 02:05:28 -04:00 committed by GitHub
parent 5f5dab88c8
commit 2d75729962
Failed to generate hash of commit
2 changed files with 25 additions and 1 deletions

View file

@ -0,0 +1,23 @@
**Added:**
* <news item>
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* Warn and continue if a user without ``pygments`` tries to load an unknown style
**Security:**
* <news item>

View file

@ -1149,7 +1149,8 @@ def ansi_style_by_name(name):
if name in ANSI_STYLES: if name in ANSI_STYLES:
return ANSI_STYLES[name] return ANSI_STYLES[name]
elif not HAS_PYGMENTS: elif not HAS_PYGMENTS:
raise KeyError(f"could not find style {name!r}") print(f"could not find style {name!r}, using 'default'")
return ANSI_STYLES["default"]
from pygments.util import ClassNotFound from pygments.util import ClassNotFound
from xonsh.pygments_cache import get_style_by_name from xonsh.pygments_cache import get_style_by_name