1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-19 00:17:51 +02:00

make pygments library optional

This commit is contained in:
Kelly Brazil
2021-03-26 15:54:45 -07:00
parent 5f00973e40
commit 3638298af8

View File

@ -11,14 +11,19 @@ import importlib
import textwrap
import signal
import json
import jc
import jc.appdirs as appdirs
# make pygments import optional
try:
import pygments
from pygments import highlight
from pygments.style import Style
from pygments.token import (Name, Number, String, Keyword)
from pygments.lexers import JsonLexer
from pygments.formatters import Terminal256Formatter
import jc
import jc.appdirs as appdirs
pygments_installed = True
except Exception:
pygments_installed = False
class info():
@ -115,6 +120,7 @@ if os.path.isdir(local_parsers_dir):
# We only support 2.3.0+, pygments changed color names in 2.4.0.
# startswith is sufficient and avoids potential exceptions from split and int.
if pygments_installed:
if pygments.__version__.startswith('2.3.'):
PYGMENT_COLOR = {
'black': '#ansiblack',
@ -438,6 +444,9 @@ def main():
quiet = 'q' in options
raw = 'r' in options
if not pygments_installed:
mono = True
if help_me:
print(helptext())
sys.exit(0)