color_files() never returns None for token; but file_color_tokens not tracking LS_COLORS events!

This commit is contained in:
Bob Hyman 2020-03-14 22:33:48 -04:00
parent 177e18764d
commit 9e923efaa2
2 changed files with 31 additions and 5 deletions

View file

@ -142,16 +142,22 @@ def test_nested():
],
)
@skip_if_on_windows
def test_path(tmpdir, xonsh_builtins):
@pytest.fixture
def xonsh_builtins_LS_COLORS(xonsh_builtins):
x = xonsh_builtins.__xonsh__
xonsh_builtins.__xonsh__.shell = DummyShell() # because load_command_cache zaps it.
xonsh_builtins.__xonsh__.shell.shell_type = "prompt_toolkit2"
lsc = LsColors(LsColors.default_settings)
xonsh_builtins.__xonsh__.env["LS_COLORS"] = lsc # establish LS_COLORS before style.
xonsh_builtins.__xonsh__.shell.shell.styler = XonshStyle() # default style
yield xonsh_builtins
xonsh_builtins.__xonsh__ = x
@skip_if_on_windows
def test_path(tmpdir, xonsh_builtins_LS_COLORS):
test_dir = str(tmpdir.mkdir("xonsh-test-highlight-path"))
check_token(
"cd {}".format(test_dir), [(Name.Builtin, "cd"), (Color.BOLD_BLUE, test_dir)]
@ -166,6 +172,25 @@ def test_path(tmpdir, xonsh_builtins):
check_token(test_dir, [(Name.Constant, test_dir)])
@skip_if_on_windows
def test_color_on_lscolors_change(tmpdir, xonsh_builtins_LS_COLORS):
"""Verify colorizer returns Token.Text if file type not defined in LS_COLORS"""
lsc = xonsh_builtins_LS_COLORS.__xonsh__.env["LS_COLORS"]
test_dir = str(tmpdir.mkdir("xonsh-test-highlight-path"))
lsc['di'] = ('GREEN',)
check_token(
"cd {}".format(test_dir), [(Name.Builtin, "cd"), (Color.GREEN, test_dir)]
)
del lsc['di'] ## isn't firing on_ls_colors_change in pyghooks!
check_token(
"cd {}".format(test_dir), [(Name.Builtin, "cd"), (Text, test_dir)]
)
@skip_if_on_windows
def test_subproc_args():
check_token("cd 192.168.0.1", [(Text, "192.168.0.1")])

View file

@ -1379,6 +1379,7 @@ def color_file(file_path: str, mode: int) -> (Color, str):
Bugs
----
* doesn't handle CA (capability)
* doesn't handle LS TARGET mapping.
"""
lsc = builtins.__xonsh__.env["LS_COLORS"]
@ -1425,7 +1426,7 @@ def color_file(file_path: str, mode: int) -> (Color, str):
elif stat.S_ISDOOR(mode):
color_key = "do" # bug missing mapping for FMT based PORT and WHITEOUT ??
ret_color_token = file_color_tokens.get(color_key, None)
ret_color_token = file_color_tokens.get(color_key, Text)
return ret_color_token, color_key