mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-19 00:17:51 +02:00
Merge pull request #72 from duelafn/pygments-2.3
Support older pygments
This commit is contained in:
53
jc/cli.py
53
jc/cli.py
@ -11,6 +11,7 @@ import importlib
|
|||||||
import textwrap
|
import textwrap
|
||||||
import signal
|
import signal
|
||||||
import json
|
import json
|
||||||
|
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)
|
||||||
@ -98,6 +99,47 @@ if os.path.isdir(local_parsers_dir):
|
|||||||
parsers.append(plugin_name)
|
parsers.append(plugin_name)
|
||||||
|
|
||||||
|
|
||||||
|
# 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.__version__.startswith("2.3."):
|
||||||
|
PYGMENT_COLOR = {
|
||||||
|
'black': '#ansiblack',
|
||||||
|
'red': '#ansidarkred',
|
||||||
|
'green': '#ansidarkgreen',
|
||||||
|
'yellow': '#ansibrown',
|
||||||
|
'blue': '#ansidarkblue',
|
||||||
|
'magenta': '#ansipurple',
|
||||||
|
'cyan': '#ansiteal',
|
||||||
|
'gray': '#ansilightgray',
|
||||||
|
'brightblack': '#ansidarkgray',
|
||||||
|
'brightred': '#ansired',
|
||||||
|
'brightgreen': '#ansigreen',
|
||||||
|
'brightyellow': '#ansiyellow',
|
||||||
|
'brightblue': '#ansiblue',
|
||||||
|
'brightmagenta': '#ansifuchsia',
|
||||||
|
'brightcyan': '#ansiturquoise',
|
||||||
|
'white': '#ansiwhite',
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
PYGMENT_COLOR = {
|
||||||
|
'black': 'ansiblack',
|
||||||
|
'red': 'ansired',
|
||||||
|
'green': 'ansigreen',
|
||||||
|
'yellow': 'ansiyellow',
|
||||||
|
'blue': 'ansiblue',
|
||||||
|
'magenta': 'ansimagenta',
|
||||||
|
'cyan': 'ansicyan',
|
||||||
|
'gray': 'ansigray',
|
||||||
|
'brightblack': 'ansibrightblack',
|
||||||
|
'brightred': 'ansibrightred',
|
||||||
|
'brightgreen': 'ansibrightgreen',
|
||||||
|
'brightyellow': 'ansibrightyellow',
|
||||||
|
'brightblue': 'ansibrightblue',
|
||||||
|
'brightmagenta': 'ansibrightmagenta',
|
||||||
|
'brightcyan': 'ansibrightcyan',
|
||||||
|
'white': 'ansiwhite',
|
||||||
|
}
|
||||||
|
|
||||||
def set_env_colors():
|
def set_env_colors():
|
||||||
"""
|
"""
|
||||||
Grab custom colors from JC_COLORS environment variable. JC_COLORS env variable takes 4 comma
|
Grab custom colors from JC_COLORS environment variable. JC_COLORS env variable takes 4 comma
|
||||||
@ -127,8 +169,7 @@ def set_env_colors():
|
|||||||
input_error = True
|
input_error = True
|
||||||
|
|
||||||
for color in color_list:
|
for color in color_list:
|
||||||
if color not in ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'gray', 'brightblack', 'brightred',
|
if color != 'default' and color not in PYGMENT_COLOR:
|
||||||
'brightgreen', 'brightyellow', 'brightblue', 'brightmagenta', 'brightcyan', 'white', 'default']:
|
|
||||||
input_error = True
|
input_error = True
|
||||||
|
|
||||||
# if there is an issue with the env variable, just set all colors to default and move on
|
# if there is an issue with the env variable, just set all colors to default and move on
|
||||||
@ -138,10 +179,10 @@ def set_env_colors():
|
|||||||
|
|
||||||
# Try the color set in the JC_COLORS env variable first. If it is set to default, then fall back to default colors
|
# Try the color set in the JC_COLORS env variable first. If it is set to default, then fall back to default colors
|
||||||
return {
|
return {
|
||||||
Name.Tag: f'bold ansi{color_list[0]}' if not color_list[0] == 'default' else 'bold ansiblue', # key names
|
Name.Tag: f'bold {PYGMENT_COLOR[color_list[0]]}' if not color_list[0] == 'default' else 'bold ' + PYGMENT_COLOR['blue'], # key names
|
||||||
Keyword: f'ansi{color_list[1]}' if not color_list[1] == 'default' else 'ansibrightblack', # true, false, null
|
Keyword: PYGMENT_COLOR[color_list[1]] if not color_list[1] == 'default' else PYGMENT_COLOR['brightblack'], # true, false, null
|
||||||
Number: f'ansi{color_list[2]}' if not color_list[2] == 'default' else 'ansimagenta', # numbers
|
Number: PYGMENT_COLOR[color_list[2]] if not color_list[2] == 'default' else PYGMENT_COLOR['magenta'], # numbers
|
||||||
String: f'ansi{color_list[3]}' if not color_list[3] == 'default' else 'ansigreen' # strings
|
String: PYGMENT_COLOR[color_list[3]] if not color_list[3] == 'default' else PYGMENT_COLOR['green'] # strings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
2
setup.py
2
setup.py
@ -12,7 +12,7 @@ setuptools.setup(
|
|||||||
install_requires=[
|
install_requires=[
|
||||||
'ruamel.yaml>=0.15.0',
|
'ruamel.yaml>=0.15.0',
|
||||||
'xmltodict>=0.12.0',
|
'xmltodict>=0.12.0',
|
||||||
'Pygments>=2.4.2'
|
'Pygments>=2.3.0'
|
||||||
],
|
],
|
||||||
license='MIT',
|
license='MIT',
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
|
Reference in New Issue
Block a user