mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
black
This commit is contained in:
parent
470517ff21
commit
1c6b1e1ea4
10 changed files with 151 additions and 144 deletions
|
@ -3,40 +3,40 @@ import pytest
|
||||||
|
|
||||||
from xonsh.ansi_colors import ansi_color_escape_code_to_name, ansi_reverse_style
|
from xonsh.ansi_colors import ansi_color_escape_code_to_name, ansi_reverse_style
|
||||||
|
|
||||||
RS = ansi_reverse_style(style='default')
|
RS = ansi_reverse_style(style="default")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('key, value', [
|
@pytest.mark.parametrize("key, value", [("", "NO_COLOR"), ("31", "RED")])
|
||||||
('', 'NO_COLOR'),
|
|
||||||
('31', 'RED'),
|
|
||||||
])
|
|
||||||
def test_ansi_reverse_style(key, value):
|
def test_ansi_reverse_style(key, value):
|
||||||
assert key in RS
|
assert key in RS
|
||||||
assert RS[key] == value
|
assert RS[key] == value
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('inp, exp', [
|
@pytest.mark.parametrize(
|
||||||
('0', ('NO_COLOR',)),
|
"inp, exp",
|
||||||
('\0010\002', ('NO_COLOR',)),
|
[
|
||||||
('\033[0m', ('NO_COLOR',)),
|
("0", ("NO_COLOR",)),
|
||||||
('\001\033[0m\002', ('NO_COLOR',)),
|
("\0010\002", ("NO_COLOR",)),
|
||||||
('00;36', ('CYAN',)),
|
("\033[0m", ("NO_COLOR",)),
|
||||||
('01;31', ('BOLD_RED',)),
|
("\001\033[0m\002", ("NO_COLOR",)),
|
||||||
('04;31', ('UNDERLINE_RED',)),
|
("00;36", ("CYAN",)),
|
||||||
('1;4;31', ('BOLD_UNDERLINE_RED',)),
|
("01;31", ("BOLD_RED",)),
|
||||||
('4;1;31', ('BOLD_UNDERLINE_RED',)),
|
("04;31", ("UNDERLINE_RED",)),
|
||||||
('31;42', ('RED', 'BACKGROUND_GREEN')),
|
("1;4;31", ("BOLD_UNDERLINE_RED",)),
|
||||||
('42;31', ('BACKGROUND_GREEN', 'RED')),
|
("4;1;31", ("BOLD_UNDERLINE_RED",)),
|
||||||
('40', ('BACKGROUND_BLACK',)),
|
("31;42", ("RED", "BACKGROUND_GREEN")),
|
||||||
('38;5;89', ('PURPLE',),),
|
("42;31", ("BACKGROUND_GREEN", "RED")),
|
||||||
('48;5;89', ('BACKGROUND_PURPLE',),),
|
("40", ("BACKGROUND_BLACK",)),
|
||||||
('38;2;170;0;0', ('RED',),),
|
("38;5;89", ("PURPLE",)),
|
||||||
('48;2;170;0;0', ('BACKGROUND_RED',),),
|
("48;5;89", ("BACKGROUND_PURPLE",)),
|
||||||
('1;38;5;124', ('BOLD_RED',),),
|
("38;2;170;0;0", ("RED",)),
|
||||||
('4;1;38;2;170;0;0', ('BOLD_UNDERLINE_RED',),),
|
("48;2;170;0;0", ("BACKGROUND_RED",)),
|
||||||
('1;38;5;40', ('BOLD_GREEN',),),
|
("1;38;5;124", ("BOLD_RED",)),
|
||||||
('48;5;16;38;5;184', ('BACKGROUND_BLACK', 'INTENSE_YELLOW')),
|
("4;1;38;2;170;0;0", ("BOLD_UNDERLINE_RED",)),
|
||||||
])
|
("1;38;5;40", ("BOLD_GREEN",)),
|
||||||
|
("48;5;16;38;5;184", ("BACKGROUND_BLACK", "INTENSE_YELLOW")),
|
||||||
|
],
|
||||||
|
)
|
||||||
def test_ansi_color_escape_code_to_name(inp, exp):
|
def test_ansi_color_escape_code_to_name(inp, exp):
|
||||||
obs = ansi_color_escape_code_to_name(inp, 'default', reversed_style=RS)
|
obs = ansi_color_escape_code_to_name(inp, "default", reversed_style=RS)
|
||||||
assert obs == exp
|
assert obs == exp
|
|
@ -64,7 +64,7 @@ def test_parse_aliases():
|
||||||
"__XONSH_ALIAS_END__\n"
|
"__XONSH_ALIAS_END__\n"
|
||||||
"more filth"
|
"more filth"
|
||||||
)
|
)
|
||||||
obs = parse_aliases(s, 'bash')
|
obs = parse_aliases(s, "bash")
|
||||||
assert exp == obs
|
assert exp == obs
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ def test_premain_D(shell):
|
||||||
|
|
||||||
def test_premain_custom_rc(shell, tmpdir, monkeypatch):
|
def test_premain_custom_rc(shell, tmpdir, monkeypatch):
|
||||||
monkeypatch.setattr(sys.stdin, "isatty", lambda: True)
|
monkeypatch.setattr(sys.stdin, "isatty", lambda: True)
|
||||||
monkeypatch.setitem(os.environ, "XONSH_CACHE_SCRIPTS", 'False')
|
monkeypatch.setitem(os.environ, "XONSH_CACHE_SCRIPTS", "False")
|
||||||
f = tmpdir.join("wakkawakka")
|
f = tmpdir.join("wakkawakka")
|
||||||
f.write("print('hi')")
|
f.write("print('hi')")
|
||||||
args = xonsh.main.premain(["--rc", f.strpath])
|
args = xonsh.main.premain(["--rc", f.strpath])
|
||||||
|
@ -78,7 +78,7 @@ def test_force_interactive_custom_rc_with_script(shell, tmpdir, monkeypatch):
|
||||||
"""Calling a custom RC file on a script-call with the interactive flag
|
"""Calling a custom RC file on a script-call with the interactive flag
|
||||||
should run interactively
|
should run interactively
|
||||||
"""
|
"""
|
||||||
monkeypatch.setitem(os.environ, "XONSH_CACHE_SCRIPTS", 'False')
|
monkeypatch.setitem(os.environ, "XONSH_CACHE_SCRIPTS", "False")
|
||||||
f = tmpdir.join("wakkawakka")
|
f = tmpdir.join("wakkawakka")
|
||||||
f.write("print('hi')")
|
f.write("print('hi')")
|
||||||
args = xonsh.main.premain(["-i", "--rc", f.strpath, "tests/sample.xsh"])
|
args = xonsh.main.premain(["-i", "--rc", f.strpath, "tests/sample.xsh"])
|
||||||
|
@ -120,8 +120,10 @@ def test_premain_invalid_arguments(shell, case, capsys):
|
||||||
xonsh.main.premain([case])
|
xonsh.main.premain([case])
|
||||||
assert "unrecognized argument" in capsys.readouterr()[1]
|
assert "unrecognized argument" in capsys.readouterr()[1]
|
||||||
|
|
||||||
|
|
||||||
def test_premain_timings_arg(shell):
|
def test_premain_timings_arg(shell):
|
||||||
xonsh.main.premain(['--timings'])
|
xonsh.main.premain(["--timings"])
|
||||||
|
|
||||||
|
|
||||||
def test_xonsh_failback(shell, monkeypatch, monkeypatch_stderr):
|
def test_xonsh_failback(shell, monkeypatch, monkeypatch_stderr):
|
||||||
failback_checker = []
|
failback_checker = []
|
||||||
|
|
|
@ -106,74 +106,65 @@ def test_format_prompt_with_no_env(formatter, xonsh_builtins, live_fields):
|
||||||
xonsh_builtins.__xonsh__.shell.prompt_formatter = formatter
|
xonsh_builtins.__xonsh__.shell.prompt_formatter = formatter
|
||||||
|
|
||||||
env = Env()
|
env = Env()
|
||||||
env.pop('VIRTUAL_ENV', None) # For virtualenv
|
env.pop("VIRTUAL_ENV", None) # For virtualenv
|
||||||
env.pop('CONDA_DEFAULT_ENV', None) # For conda/CircleCI
|
env.pop("CONDA_DEFAULT_ENV", None) # For conda/CircleCI
|
||||||
xonsh_builtins.__xonsh__.env = env
|
xonsh_builtins.__xonsh__.env = env
|
||||||
|
|
||||||
assert formatter('{env_name}', fields=live_fields) == ''
|
assert formatter("{env_name}", fields=live_fields) == ""
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('envname', ['env', 'foo', 'bar'])
|
@pytest.mark.parametrize("envname", ["env", "foo", "bar"])
|
||||||
def test_format_prompt_with_various_envs(formatter, xonsh_builtins, live_fields, envname):
|
def test_format_prompt_with_various_envs(
|
||||||
|
formatter, xonsh_builtins, live_fields, envname
|
||||||
|
):
|
||||||
xonsh_builtins.__xonsh__.shell.prompt_formatter = formatter
|
xonsh_builtins.__xonsh__.shell.prompt_formatter = formatter
|
||||||
|
|
||||||
env = Env(VIRTUAL_ENV=envname)
|
env = Env(VIRTUAL_ENV=envname)
|
||||||
xonsh_builtins.__xonsh__.env = env
|
xonsh_builtins.__xonsh__.env = env
|
||||||
|
|
||||||
exp = live_fields['env_prefix'] + envname + live_fields['env_postfix']
|
exp = live_fields["env_prefix"] + envname + live_fields["env_postfix"]
|
||||||
assert formatter('{env_name}', fields=live_fields) == exp
|
assert formatter("{env_name}", fields=live_fields) == exp
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('pre', ['(', '[[', '', ' '])
|
@pytest.mark.parametrize("pre", ["(", "[[", "", " "])
|
||||||
@pytest.mark.parametrize('post', [')', ']]', '', ' '])
|
@pytest.mark.parametrize("post", [")", "]]", "", " "])
|
||||||
def test_format_prompt_with_various_prepost(
|
def test_format_prompt_with_various_prepost(
|
||||||
formatter,
|
formatter, xonsh_builtins, live_fields, pre, post
|
||||||
xonsh_builtins,
|
|
||||||
live_fields,
|
|
||||||
pre,
|
|
||||||
post,
|
|
||||||
):
|
):
|
||||||
xonsh_builtins.__xonsh__.shell.prompt_formatter = formatter
|
xonsh_builtins.__xonsh__.shell.prompt_formatter = formatter
|
||||||
|
|
||||||
env = Env(VIRTUAL_ENV='env')
|
env = Env(VIRTUAL_ENV="env")
|
||||||
xonsh_builtins.__xonsh__.env = env
|
xonsh_builtins.__xonsh__.env = env
|
||||||
|
|
||||||
live_fields.update({'env_prefix': pre, 'env_postfix': post})
|
live_fields.update({"env_prefix": pre, "env_postfix": post})
|
||||||
|
|
||||||
exp = pre + 'env' + post
|
exp = pre + "env" + post
|
||||||
assert formatter('{env_name}', fields=live_fields) == exp
|
assert formatter("{env_name}", fields=live_fields) == exp
|
||||||
|
|
||||||
|
|
||||||
def test_noenv_with_disable_set(formatter, xonsh_builtins, live_fields):
|
def test_noenv_with_disable_set(formatter, xonsh_builtins, live_fields):
|
||||||
xonsh_builtins.__xonsh__.shell.prompt_formatter = formatter
|
xonsh_builtins.__xonsh__.shell.prompt_formatter = formatter
|
||||||
|
|
||||||
env = Env(VIRTUAL_ENV='env', VIRTUAL_ENV_DISABLE_PROMPT=1)
|
env = Env(VIRTUAL_ENV="env", VIRTUAL_ENV_DISABLE_PROMPT=1)
|
||||||
xonsh_builtins.__xonsh__.env = env
|
xonsh_builtins.__xonsh__.env = env
|
||||||
|
|
||||||
exp = ''
|
exp = ""
|
||||||
assert formatter('{env_name}', fields=live_fields) == exp
|
assert formatter("{env_name}", fields=live_fields) == exp
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('disable', [0, 1])
|
@pytest.mark.parametrize("disable", [0, 1])
|
||||||
def test_custom_env_overrides_default(
|
def test_custom_env_overrides_default(formatter, xonsh_builtins, live_fields, disable):
|
||||||
formatter,
|
|
||||||
xonsh_builtins,
|
|
||||||
live_fields,
|
|
||||||
disable,
|
|
||||||
):
|
|
||||||
xonsh_builtins.__xonsh__.shell.prompt_formatter = formatter
|
xonsh_builtins.__xonsh__.shell.prompt_formatter = formatter
|
||||||
|
|
||||||
prompt = '!venv active! '
|
prompt = "!venv active! "
|
||||||
|
|
||||||
env = Env(
|
env = Env(
|
||||||
VIRTUAL_ENV='env',
|
VIRTUAL_ENV="env", VIRTUAL_ENV_PROMPT=prompt, VIRTUAL_ENV_DISABLE_PROMPT=disable
|
||||||
VIRTUAL_ENV_PROMPT=prompt,
|
|
||||||
VIRTUAL_ENV_DISABLE_PROMPT=disable,
|
|
||||||
)
|
)
|
||||||
xonsh_builtins.__xonsh__.env = env
|
xonsh_builtins.__xonsh__.env = env
|
||||||
|
|
||||||
exp = '' if disable else prompt
|
exp = "" if disable else prompt
|
||||||
assert formatter('{env_name}', fields=live_fields) == exp
|
assert formatter("{env_name}", fields=live_fields) == exp
|
||||||
|
|
||||||
|
|
||||||
def test_promptformatter_cache(formatter):
|
def test_promptformatter_cache(formatter):
|
||||||
|
|
|
@ -375,22 +375,25 @@ def test_subproc_toks_pyeval_nested():
|
||||||
assert exp == obs
|
assert exp == obs
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('phrase', [
|
@pytest.mark.parametrize(
|
||||||
'xandy',
|
"phrase",
|
||||||
'xory',
|
[
|
||||||
'xand',
|
"xandy",
|
||||||
'andy',
|
"xory",
|
||||||
'xor',
|
"xand",
|
||||||
'ory',
|
"andy",
|
||||||
'x-and',
|
"xor",
|
||||||
'x-or',
|
"ory",
|
||||||
'and-y',
|
"x-and",
|
||||||
'or-y',
|
"x-or",
|
||||||
'x-and-y',
|
"and-y",
|
||||||
'x-or-y',
|
"or-y",
|
||||||
'in/and/path',
|
"x-and-y",
|
||||||
'in/or/path',
|
"x-or-y",
|
||||||
])
|
"in/and/path",
|
||||||
|
"in/or/path",
|
||||||
|
],
|
||||||
|
)
|
||||||
def test_subproc_toks_and_or(phrase):
|
def test_subproc_toks_and_or(phrase):
|
||||||
s = "echo " + phrase
|
s = "echo " + phrase
|
||||||
exp = "![{0}]".format(s)
|
exp = "![{0}]".format(s)
|
||||||
|
|
|
@ -51,7 +51,9 @@ skip_if_on_msys = pytest.mark.skipif(
|
||||||
|
|
||||||
skip_if_on_windows = pytest.mark.skipif(ON_WINDOWS, reason="Unix stuff")
|
skip_if_on_windows = pytest.mark.skipif(ON_WINDOWS, reason="Unix stuff")
|
||||||
|
|
||||||
skip_if_on_azure_pipelines = pytest.mark.skipif(ON_AZURE_PIPELINES, reason="not suitable for azure")
|
skip_if_on_azure_pipelines = pytest.mark.skipif(
|
||||||
|
ON_AZURE_PIPELINES, reason="not suitable for azure"
|
||||||
|
)
|
||||||
|
|
||||||
skip_if_on_unix = pytest.mark.skipif(not ON_WINDOWS, reason="Windows stuff")
|
skip_if_on_unix = pytest.mark.skipif(not ON_WINDOWS, reason="Windows stuff")
|
||||||
|
|
||||||
|
@ -201,9 +203,11 @@ def nodes_equal(x, y):
|
||||||
type(y),
|
type(y),
|
||||||
)
|
)
|
||||||
if isinstance(x, (ast.Expr, ast.FunctionDef, ast.ClassDef)):
|
if isinstance(x, (ast.Expr, ast.FunctionDef, ast.ClassDef)):
|
||||||
assert x.lineno == y.lineno, (
|
assert (
|
||||||
"Ast nodes do not have the same line number : %s != %s"
|
x.lineno == y.lineno
|
||||||
% (x.lineno, y.lineno)
|
), "Ast nodes do not have the same line number : %s != %s" % (
|
||||||
|
x.lineno,
|
||||||
|
y.lineno,
|
||||||
)
|
)
|
||||||
assert x.col_offset == y.col_offset, (
|
assert x.col_offset == y.col_offset, (
|
||||||
"Ast nodes do not have the same column offset number : %s != %s"
|
"Ast nodes do not have the same column offset number : %s != %s"
|
||||||
|
|
|
@ -117,7 +117,7 @@ def ansi_color_style(style="default"):
|
||||||
return cmap
|
return cmap
|
||||||
|
|
||||||
|
|
||||||
def ansi_reverse_style(style='default', return_style=False):
|
def ansi_reverse_style(style="default", return_style=False):
|
||||||
"""Reverses an ANSI color style mapping so that escape codes map to
|
"""Reverses an ANSI color style mapping so that escape codes map to
|
||||||
colors. Style may either be string or mapping. May also return
|
colors. Style may either be string or mapping. May also return
|
||||||
the style it looked up.
|
the style it looked up.
|
||||||
|
@ -126,22 +126,22 @@ def ansi_reverse_style(style='default', return_style=False):
|
||||||
reversed_style = {v: k for k, v in style.items()}
|
reversed_style = {v: k for k, v in style.items()}
|
||||||
# add keys to make this more useful
|
# add keys to make this more useful
|
||||||
updates = {
|
updates = {
|
||||||
'1': 'BOLD_',
|
"1": "BOLD_",
|
||||||
'2': 'FAINT_',
|
"2": "FAINT_",
|
||||||
'4': 'UNDERLINE_',
|
"4": "UNDERLINE_",
|
||||||
'5': 'SLOWBLINK_',
|
"5": "SLOWBLINK_",
|
||||||
'1;4': 'BOLD_UNDERLINE_',
|
"1;4": "BOLD_UNDERLINE_",
|
||||||
'4;1': 'BOLD_UNDERLINE_',
|
"4;1": "BOLD_UNDERLINE_",
|
||||||
'38': 'SET_FOREGROUND_',
|
"38": "SET_FOREGROUND_",
|
||||||
'48': 'SET_BACKGROUND_',
|
"48": "SET_BACKGROUND_",
|
||||||
'38;2': 'SET_FOREGROUND_3INTS_',
|
"38;2": "SET_FOREGROUND_3INTS_",
|
||||||
'48;2': 'SET_BACKGROUND_3INTS_',
|
"48;2": "SET_BACKGROUND_3INTS_",
|
||||||
'38;5': 'SET_FOREGROUND_SHORT_',
|
"38;5": "SET_FOREGROUND_SHORT_",
|
||||||
'48;5': 'SET_BACKGROUND_SHORT_',
|
"48;5": "SET_BACKGROUND_SHORT_",
|
||||||
}
|
}
|
||||||
for ec, name in reversed_style.items():
|
for ec, name in reversed_style.items():
|
||||||
no_left_zero = ec.lstrip('0')
|
no_left_zero = ec.lstrip("0")
|
||||||
if no_left_zero.startswith(';'):
|
if no_left_zero.startswith(";"):
|
||||||
updates[no_left_zero[1:]] = name
|
updates[no_left_zero[1:]] = name
|
||||||
elif no_left_zero != ec:
|
elif no_left_zero != ec:
|
||||||
updates[no_left_zero] = name
|
updates[no_left_zero] = name
|
||||||
|
@ -155,40 +155,40 @@ def ansi_reverse_style(style='default', return_style=False):
|
||||||
|
|
||||||
@lazyobject
|
@lazyobject
|
||||||
def ANSI_ESCAPE_CODE_RE():
|
def ANSI_ESCAPE_CODE_RE():
|
||||||
return re.compile(r'\001?(\033\[)?([0-9;]+)m?\002?')
|
return re.compile(r"\001?(\033\[)?([0-9;]+)m?\002?")
|
||||||
|
|
||||||
|
|
||||||
@lazyobject
|
@lazyobject
|
||||||
def ANSI_REVERSE_COLOR_NAME_TRANSLATIONS():
|
def ANSI_REVERSE_COLOR_NAME_TRANSLATIONS():
|
||||||
base = {
|
base = {
|
||||||
'SET_FOREGROUND_FAINT_': 'SET_FOREGROUND_3INTS_',
|
"SET_FOREGROUND_FAINT_": "SET_FOREGROUND_3INTS_",
|
||||||
'SET_BACKGROUND_FAINT_': 'SET_BACKGROUND_3INTS_',
|
"SET_BACKGROUND_FAINT_": "SET_BACKGROUND_3INTS_",
|
||||||
'SET_FOREGROUND_SLOWBLINK_': 'SET_FOREGROUND_SHORT_',
|
"SET_FOREGROUND_SLOWBLINK_": "SET_FOREGROUND_SHORT_",
|
||||||
'SET_BACKGROUND_SLOWBLINK_': 'SET_BACKGROUND_SHORT_',
|
"SET_BACKGROUND_SLOWBLINK_": "SET_BACKGROUND_SHORT_",
|
||||||
}
|
}
|
||||||
data = {'UNDERLINE_BOLD_': 'BOLD_UNDERLINE_'}
|
data = {"UNDERLINE_BOLD_": "BOLD_UNDERLINE_"}
|
||||||
data.update(base)
|
data.update(base)
|
||||||
data.update({'BOLD_' + k: 'BOLD_' + v for k, v in base.items()})
|
data.update({"BOLD_" + k: "BOLD_" + v for k, v in base.items()})
|
||||||
data.update({'UNDERLINE_' + k: 'UNDERLINE_' + v for k, v in base.items()})
|
data.update({"UNDERLINE_" + k: "UNDERLINE_" + v for k, v in base.items()})
|
||||||
data.update({'BOLD_UNDERLINE_' + k: 'BOLD_UNDERLINE_' + v for k, v in base.items()})
|
data.update({"BOLD_UNDERLINE_" + k: "BOLD_UNDERLINE_" + v for k, v in base.items()})
|
||||||
data.update({'UNDERLINE_BOLD_' + k: 'BOLD_UNDERLINE_' + v for k, v in base.items()})
|
data.update({"UNDERLINE_BOLD_" + k: "BOLD_UNDERLINE_" + v for k, v in base.items()})
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
@lazyobject
|
@lazyobject
|
||||||
def ANSI_COLOR_NAME_SET_3INTS_RE():
|
def ANSI_COLOR_NAME_SET_3INTS_RE():
|
||||||
return re.compile(r'(\w+_)?SET_(FORE|BACK)GROUND_3INTS_(\d+)_(\d+)_(\d+)')
|
return re.compile(r"(\w+_)?SET_(FORE|BACK)GROUND_3INTS_(\d+)_(\d+)_(\d+)")
|
||||||
|
|
||||||
|
|
||||||
@lazyobject
|
@lazyobject
|
||||||
def ANSI_COLOR_NAME_SET_SHORT_RE():
|
def ANSI_COLOR_NAME_SET_SHORT_RE():
|
||||||
return re.compile(r'(\w+_)?SET_(FORE|BACK)GROUND_SHORT_(\d+)')
|
return re.compile(r"(\w+_)?SET_(FORE|BACK)GROUND_SHORT_(\d+)")
|
||||||
|
|
||||||
|
|
||||||
def _color_name_from_ints(ints, background=False, prefix=None):
|
def _color_name_from_ints(ints, background=False, prefix=None):
|
||||||
name = find_closest_color(ints, BASE_XONSH_COLORS)
|
name = find_closest_color(ints, BASE_XONSH_COLORS)
|
||||||
if background:
|
if background:
|
||||||
name = 'BACKGROUND_' + name
|
name = "BACKGROUND_" + name
|
||||||
name = name if prefix is None else prefix + name
|
name = name if prefix is None else prefix + name
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
@ -215,8 +215,8 @@ def ansi_color_escape_code_to_name(escape_code, style, reversed_style=None):
|
||||||
names = []
|
names = []
|
||||||
n_ints = 0
|
n_ints = 0
|
||||||
seen_set_foreback = False
|
seen_set_foreback = False
|
||||||
for e in ec.split(';'):
|
for e in ec.split(";"):
|
||||||
no_left_zero = e.lstrip('0') if len(e) > 1 else e
|
no_left_zero = e.lstrip("0") if len(e) > 1 else e
|
||||||
if seen_set_foreback and n_ints > 0:
|
if seen_set_foreback and n_ints > 0:
|
||||||
names.append(e)
|
names.append(e)
|
||||||
n_ints -= 1
|
n_ints -= 1
|
||||||
|
@ -226,49 +226,53 @@ def ansi_color_escape_code_to_name(escape_code, style, reversed_style=None):
|
||||||
else:
|
else:
|
||||||
names.append(reversed_style.get(no_left_zero, no_left_zero))
|
names.append(reversed_style.get(no_left_zero, no_left_zero))
|
||||||
# set the flags for next time
|
# set the flags for next time
|
||||||
if '38' == e or '48' == e:
|
if "38" == e or "48" == e:
|
||||||
seen_set_foreback = True
|
seen_set_foreback = True
|
||||||
elif '2' == e:
|
elif "2" == e:
|
||||||
n_ints = 3
|
n_ints = 3
|
||||||
elif '5' == e:
|
elif "5" == e:
|
||||||
n_ints = 1
|
n_ints = 1
|
||||||
# normalize names
|
# normalize names
|
||||||
n = ''
|
n = ""
|
||||||
norm_names = []
|
norm_names = []
|
||||||
colors = set(reversed_style.values())
|
colors = set(reversed_style.values())
|
||||||
for name in names:
|
for name in names:
|
||||||
if name == 'NO_COLOR':
|
if name == "NO_COLOR":
|
||||||
# skip most '0' entries
|
# skip most '0' entries
|
||||||
continue
|
continue
|
||||||
n = n + name if n else name
|
n = n + name if n else name
|
||||||
n = ANSI_REVERSE_COLOR_NAME_TRANSLATIONS.get(n, n)
|
n = ANSI_REVERSE_COLOR_NAME_TRANSLATIONS.get(n, n)
|
||||||
if n.endswith('_'):
|
if n.endswith("_"):
|
||||||
continue
|
continue
|
||||||
elif ANSI_COLOR_NAME_SET_SHORT_RE.match(n) is not None:
|
elif ANSI_COLOR_NAME_SET_SHORT_RE.match(n) is not None:
|
||||||
pre, fore_back, short = ANSI_COLOR_NAME_SET_SHORT_RE.match(n).groups()
|
pre, fore_back, short = ANSI_COLOR_NAME_SET_SHORT_RE.match(n).groups()
|
||||||
n = _color_name_from_ints(short_to_ints(short),
|
n = _color_name_from_ints(
|
||||||
background=(fore_back == 'BACK'),
|
short_to_ints(short), background=(fore_back == "BACK"), prefix=pre
|
||||||
prefix=pre)
|
)
|
||||||
elif ANSI_COLOR_NAME_SET_3INTS_RE.match(n) is not None:
|
elif ANSI_COLOR_NAME_SET_3INTS_RE.match(n) is not None:
|
||||||
pre, fore_back, r, g, b = ANSI_COLOR_NAME_SET_3INTS_RE.match(n).groups()
|
pre, fore_back, r, g, b = ANSI_COLOR_NAME_SET_3INTS_RE.match(n).groups()
|
||||||
n = _color_name_from_ints((int(r), int(g), int(b)),
|
n = _color_name_from_ints(
|
||||||
background=(fore_back == 'BACK'),
|
(int(r), int(g), int(b)), background=(fore_back == "BACK"), prefix=pre
|
||||||
prefix=pre)
|
)
|
||||||
elif 'GROUND_3INTS_' in n:
|
elif "GROUND_3INTS_" in n:
|
||||||
# have 1 or 2, but not 3 ints
|
# have 1 or 2, but not 3 ints
|
||||||
n += '_'
|
n += "_"
|
||||||
continue
|
continue
|
||||||
# error check
|
# error check
|
||||||
if n not in colors:
|
if n not in colors:
|
||||||
msg = ("Could not translate ANSI color code {escape_code!r} "
|
msg = (
|
||||||
"into a known color in the palette. Specifically, the {n!r} "
|
"Could not translate ANSI color code {escape_code!r} "
|
||||||
"portion of {name!r} in {names!r} seems to missing.")
|
"into a known color in the palette. Specifically, the {n!r} "
|
||||||
raise ValueError(msg.format(escape_code=escape_code, names=names, name=name, n=n))
|
"portion of {name!r} in {names!r} seems to missing."
|
||||||
|
)
|
||||||
|
raise ValueError(
|
||||||
|
msg.format(escape_code=escape_code, names=names, name=name, n=n)
|
||||||
|
)
|
||||||
norm_names.append(n)
|
norm_names.append(n)
|
||||||
n = ''
|
n = ""
|
||||||
# return
|
# return
|
||||||
if len(norm_names) == 0:
|
if len(norm_names) == 0:
|
||||||
return ('NO_COLOR',)
|
return ("NO_COLOR",)
|
||||||
else:
|
else:
|
||||||
return tuple(norm_names)
|
return tuple(norm_names)
|
||||||
|
|
||||||
|
|
|
@ -609,7 +609,7 @@ class SubprocSpec:
|
||||||
|
|
||||||
def _cmd_event_name(self):
|
def _cmd_event_name(self):
|
||||||
if callable(self.alias):
|
if callable(self.alias):
|
||||||
return self.alias.__name__
|
return self.alias.__name__
|
||||||
elif self.binary_loc is None:
|
elif self.binary_loc is None:
|
||||||
return "<not-found>"
|
return "<not-found>"
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -365,7 +365,7 @@ class LsColors(cabc.MutableMapping):
|
||||||
if self._detyped is None:
|
if self._detyped is None:
|
||||||
self._detyped = ":".join(
|
self._detyped = ":".join(
|
||||||
[
|
[
|
||||||
key + "=" + ";".join([style[v] or '0' for v in val])
|
key + "=" + ";".join([style[v] or "0" for v in val])
|
||||||
for key, val in sorted(self._d.items())
|
for key, val in sorted(self._d.items())
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -421,13 +421,15 @@ class LsColors(cabc.MutableMapping):
|
||||||
if filename is not None:
|
if filename is not None:
|
||||||
cmd.append(filename)
|
cmd.append(filename)
|
||||||
# get env
|
# get env
|
||||||
if hasattr(builtins, "__xonsh__") and hasattr(builtins.__xonsh__, 'env'):
|
if hasattr(builtins, "__xonsh__") and hasattr(builtins.__xonsh__, "env"):
|
||||||
denv = builtins.__xonsh__.env.detype()
|
denv = builtins.__xonsh__.env.detype()
|
||||||
else:
|
else:
|
||||||
denv = None
|
denv = None
|
||||||
# run dircolors
|
# run dircolors
|
||||||
try:
|
try:
|
||||||
out = subprocess.check_output(cmd, env=denv, universal_newlines=True, stderr=subprocess.DEVNULL)
|
out = subprocess.check_output(
|
||||||
|
cmd, env=denv, universal_newlines=True, stderr=subprocess.DEVNULL
|
||||||
|
)
|
||||||
except (subprocess.CalledProcessError, FileNotFoundError):
|
except (subprocess.CalledProcessError, FileNotFoundError):
|
||||||
return cls(cls.default_settings)
|
return cls(cls.default_settings)
|
||||||
s = out.splitlines()[0]
|
s = out.splitlines()[0]
|
||||||
|
@ -460,7 +462,7 @@ def ensure_ls_colors_in_env(spec=None, **kwargs):
|
||||||
ls command is called.
|
ls command is called.
|
||||||
"""
|
"""
|
||||||
env = builtins.__xonsh__.env
|
env = builtins.__xonsh__.env
|
||||||
if 'LS_COLORS' not in env._d:
|
if "LS_COLORS" not in env._d:
|
||||||
# this adds it to the env too
|
# this adds it to the env too
|
||||||
default_lscolors(env)
|
default_lscolors(env)
|
||||||
events.on_pre_spec_run_ls.discard(ensure_ls_colors_in_env)
|
events.on_pre_spec_run_ls.discard(ensure_ls_colors_in_env)
|
||||||
|
@ -664,13 +666,13 @@ def xonsh_append_newline(env):
|
||||||
@default_value
|
@default_value
|
||||||
def default_lscolors(env):
|
def default_lscolors(env):
|
||||||
"""Gets a default instanse of LsColors"""
|
"""Gets a default instanse of LsColors"""
|
||||||
inherited_lscolors = os_environ.get('LS_COLORS', None)
|
inherited_lscolors = os_environ.get("LS_COLORS", None)
|
||||||
if inherited_lscolors is None:
|
if inherited_lscolors is None:
|
||||||
lsc = LsColors.fromdircolors()
|
lsc = LsColors.fromdircolors()
|
||||||
else:
|
else:
|
||||||
lsc = LsColors.fromstring(inherited_lscolors)
|
lsc = LsColors.fromstring(inherited_lscolors)
|
||||||
# have to place this in the env, so it is applied
|
# have to place this in the env, so it is applied
|
||||||
env['LS_COLORS'] = lsc
|
env["LS_COLORS"] = lsc
|
||||||
return lsc
|
return lsc
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1088,6 +1088,7 @@ def swap_values(d, updates, default=_DEFAULT_SENTINEL):
|
||||||
# Validators and converters
|
# Validators and converters
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
def detype(x):
|
def detype(x):
|
||||||
"""This assumes that the object has a detype method, and calls that."""
|
"""This assumes that the object has a detype method, and calls that."""
|
||||||
return x.detype()
|
return x.detype()
|
||||||
|
|
Loading…
Add table
Reference in a new issue