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:
97
jc/cli.py
97
jc/cli.py
@ -11,14 +11,19 @@ import importlib
|
|||||||
import textwrap
|
import textwrap
|
||||||
import signal
|
import signal
|
||||||
import json
|
import json
|
||||||
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
|
||||||
import jc.appdirs as appdirs
|
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
|
||||||
|
pygments_installed = True
|
||||||
|
except Exception:
|
||||||
|
pygments_installed = False
|
||||||
|
|
||||||
|
|
||||||
class info():
|
class info():
|
||||||
@ -115,44 +120,45 @@ 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.__version__.startswith('2.3.'):
|
if pygments_installed:
|
||||||
PYGMENT_COLOR = {
|
if pygments.__version__.startswith('2.3.'):
|
||||||
'black': '#ansiblack',
|
PYGMENT_COLOR = {
|
||||||
'red': '#ansidarkred',
|
'black': '#ansiblack',
|
||||||
'green': '#ansidarkgreen',
|
'red': '#ansidarkred',
|
||||||
'yellow': '#ansibrown',
|
'green': '#ansidarkgreen',
|
||||||
'blue': '#ansidarkblue',
|
'yellow': '#ansibrown',
|
||||||
'magenta': '#ansipurple',
|
'blue': '#ansidarkblue',
|
||||||
'cyan': '#ansiteal',
|
'magenta': '#ansipurple',
|
||||||
'gray': '#ansilightgray',
|
'cyan': '#ansiteal',
|
||||||
'brightblack': '#ansidarkgray',
|
'gray': '#ansilightgray',
|
||||||
'brightred': '#ansired',
|
'brightblack': '#ansidarkgray',
|
||||||
'brightgreen': '#ansigreen',
|
'brightred': '#ansired',
|
||||||
'brightyellow': '#ansiyellow',
|
'brightgreen': '#ansigreen',
|
||||||
'brightblue': '#ansiblue',
|
'brightyellow': '#ansiyellow',
|
||||||
'brightmagenta': '#ansifuchsia',
|
'brightblue': '#ansiblue',
|
||||||
'brightcyan': '#ansiturquoise',
|
'brightmagenta': '#ansifuchsia',
|
||||||
'white': '#ansiwhite',
|
'brightcyan': '#ansiturquoise',
|
||||||
}
|
'white': '#ansiwhite',
|
||||||
else:
|
}
|
||||||
PYGMENT_COLOR = {
|
else:
|
||||||
'black': 'ansiblack',
|
PYGMENT_COLOR = {
|
||||||
'red': 'ansired',
|
'black': 'ansiblack',
|
||||||
'green': 'ansigreen',
|
'red': 'ansired',
|
||||||
'yellow': 'ansiyellow',
|
'green': 'ansigreen',
|
||||||
'blue': 'ansiblue',
|
'yellow': 'ansiyellow',
|
||||||
'magenta': 'ansimagenta',
|
'blue': 'ansiblue',
|
||||||
'cyan': 'ansicyan',
|
'magenta': 'ansimagenta',
|
||||||
'gray': 'ansigray',
|
'cyan': 'ansicyan',
|
||||||
'brightblack': 'ansibrightblack',
|
'gray': 'ansigray',
|
||||||
'brightred': 'ansibrightred',
|
'brightblack': 'ansibrightblack',
|
||||||
'brightgreen': 'ansibrightgreen',
|
'brightred': 'ansibrightred',
|
||||||
'brightyellow': 'ansibrightyellow',
|
'brightgreen': 'ansibrightgreen',
|
||||||
'brightblue': 'ansibrightblue',
|
'brightyellow': 'ansibrightyellow',
|
||||||
'brightmagenta': 'ansibrightmagenta',
|
'brightblue': 'ansibrightblue',
|
||||||
'brightcyan': 'ansibrightcyan',
|
'brightmagenta': 'ansibrightmagenta',
|
||||||
'white': 'ansiwhite',
|
'brightcyan': 'ansibrightcyan',
|
||||||
}
|
'white': 'ansiwhite',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def set_env_colors(env_colors=None):
|
def set_env_colors(env_colors=None):
|
||||||
@ -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