Skip to content

Commit 902dc1f

Browse files
committed
use TextLexer as fallback in case pygments raises ClassNotFound. Related Textualize#11
1 parent 20a0d07 commit 902dc1f

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/rich_cli/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from typing import TYPE_CHECKING, List, NoReturn, Optional, Tuple
33

44
import click
5+
from pygments.lexers.special import TextLexer
6+
from pygments.util import ClassNotFound
57
from rich.console import Console, RenderableType
68
from rich.markup import escape
79
from rich.text import Text
@@ -98,6 +100,8 @@ def read_resource(path: str, lexer: Optional[str]) -> Tuple[str, Optional[str]]:
98100

99101
lexer = guess_lexer_for_filename(path, text).name
100102
return (text, lexer)
103+
except ClassNotFound:
104+
return (text, TextLexer())
101105
except Exception as error:
102106
on_error(f"unable to read {escape(path)}", error)
103107

0 commit comments

Comments
 (0)