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:
13
jc/cli.py
13
jc/cli.py
@ -11,14 +11,19 @@ import importlib
|
|||||||
import textwrap
|
import textwrap
|
||||||
import signal
|
import signal
|
||||||
import json
|
import json
|
||||||
|
import jc
|
||||||
|
import jc.appdirs as appdirs
|
||||||
|
# make pygments import optional
|
||||||
|
try:
|
||||||
import pygments
|
import pygments
|
||||||
from pygments import highlight
|
from pygments import highlight
|
||||||
from pygments.style import Style
|
from pygments.style import Style
|
||||||
from pygments.token import (Name, Number, String, Keyword)
|
from pygments.token import (Name, Number, String, Keyword)
|
||||||
from pygments.lexers import JsonLexer
|
from pygments.lexers import JsonLexer
|
||||||
from pygments.formatters import Terminal256Formatter
|
from pygments.formatters import Terminal256Formatter
|
||||||
import jc
|
pygments_installed = True
|
||||||
import jc.appdirs as appdirs
|
except Exception:
|
||||||
|
pygments_installed = False
|
||||||
|
|
||||||
|
|
||||||
class info():
|
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.
|
# 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.
|
# startswith is sufficient and avoids potential exceptions from split and int.
|
||||||
|
if pygments_installed:
|
||||||
if pygments.__version__.startswith('2.3.'):
|
if pygments.__version__.startswith('2.3.'):
|
||||||
PYGMENT_COLOR = {
|
PYGMENT_COLOR = {
|
||||||
'black': '#ansiblack',
|
'black': '#ansiblack',
|
||||||
@ -438,6 +444,9 @@ def main():
|
|||||||
quiet = 'q' in options
|
quiet = 'q' in options
|
||||||
raw = 'r' in options
|
raw = 'r' in options
|
||||||
|
|
||||||
|
if not pygments_installed:
|
||||||
|
mono = True
|
||||||
|
|
||||||
if help_me:
|
if help_me:
|
||||||
print(helptext())
|
print(helptext())
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
Reference in New Issue
Block a user