diff --git a/kittens/diff/highlight.py b/kittens/diff/highlight.py index 52380c198..c03ee639b 100644 --- a/kittens/diff/highlight.py +++ b/kittens/diff/highlight.py @@ -16,10 +16,21 @@ from kitty.rgb import color_as_sgr, parse_sharp from .collect import Segment, data_for_path, lines_for_path +class StyleNotFound(Exception): + pass + + class DiffFormatter(Formatter): def __init__(self, style='default'): - Formatter.__init__(self, style=style) + try: + Formatter.__init__(self, style=style) + initialized = True + except ClassNotFound: + initialized = False + if not initialized: + raise StyleNotFound('pygments style "{}" not found'.format(style)) + self.styles = {} for token, style in self.style: start = [] diff --git a/kittens/diff/main.py b/kittens/diff/main.py index 667bb673c..78f0739aa 100644 --- a/kittens/diff/main.py +++ b/kittens/diff/main.py @@ -241,8 +241,14 @@ class DiffHandler(Handler): self.restore_position = None self.draw_screen() if initialize_highlighter is not None and not self.highlighting_done: + from .highlight import StyleNotFound self.highlighting_done = True - initialize_highlighter(self.opts.pygments_style) + try: + initialize_highlighter(self.opts.pygments_style) + except StyleNotFound as e: + self.report_traceback_on_exit = str(e) + self.quit_loop(1) + return self.start_job('highlight', highlight_collection, self.collection, self.opts.syntax_aliases) elif job_id == 'highlight': hdata = job_result['result']