def test_lscolors_events(key_in, old_in, new_in, test, xonsh_builtins): lsc = LsColors.fromstring("rs=0:di=01;34:pi=40;33") # corresponding colors: [('NO_COLOR',), ('BOLD_CYAN',), ('BOLD_CYAN',), ('BACKGROUND_BLACK', 'YELLOW')] event_fired = False @xonsh_builtins.events.on_lscolors_change def handler(key, oldvalue, newvalue, **kwargs): nonlocal old_in, new_in, key_in, event_fired assert ( key == key_in and oldvalue == old_in and newvalue == new_in ), "Old and new event values match" event_fired = True xonsh_builtins.__xonsh__.env["LS_COLORS"] = lsc if new_in is None: old = lsc.pop(key_in, "argle") else: lsc[key_in] = new_in if old_in == new_in: assert not event_fired, "No event if value doesn't change" else: assert event_fired
def xonsh_builtins_ls_colors(xession, events_fxt): xession.shell = DummyShell() # because load_command_cache zaps it. xession.shell.shell_type = "prompt_toolkit" lsc = LsColors(LsColors.default_settings) xession.env["LS_COLORS"] = lsc # establish LS_COLORS before style. xession.shell.shell.styler = XonshStyle() # default style events.on_lscolors_change(on_lscolors_change) yield xession
def xs_LS_COLORS(xession): """Xonsh environment including LS_COLORS""" e = xession.env lsc = LsColors(LsColors.default_settings) xession.env["LS_COLORS"] = lsc xession.shell.shell_type = "prompt_toolkit" xession.shell.shell.styler = XonshStyle() # default style yield xession xession.env = e
def xonsh_builtins_LS_COLORS(xonsh_builtins): """Xonsh environment including LS_COLORS""" e = xonsh_builtins.__xonsh__.env lsc = LsColors(LsColors.default_settings) xonsh_builtins.__xonsh__.env["LS_COLORS"] = lsc xonsh_builtins.__xonsh__.shell.shell_type = "prompt_toolkit" xonsh_builtins.__xonsh__.shell.shell.styler = XonshStyle() # default style yield xonsh_builtins xonsh_builtins.__xonsh__.env = e
def xonsh_builtins_LS_COLORS(xonsh_builtins): """Xonsh environment including LS_COLORS""" e = xonsh_builtins.__xonsh__.env lsc = LsColors(LsColors.default_settings) xonsh_builtins.__xonsh__.env["LS_COLORS"] = lsc xonsh_builtins.__xonsh__.shell.shell_type = "prompt_toolkit2" # styler = XonshStyle() # default style # xonsh_builtins.__xonsh__.shell.shell.styler = styler # can't really instantiate XonshStyle separate from a shell?? yield xonsh_builtins xonsh_builtins.__xonsh__.env = e
def xs_LS_COLORS(xession, os_env, monkeypatch): """Xonsh environment including LS_COLORS""" # original env is needed on windows. since it will skip enhanced coloring # for some emulators monkeypatch.setattr(xession, "env", os_env) lsc = LsColors(LsColors.default_settings) xession.env["LS_COLORS"] = lsc # todo: a separate test for this as True xession.env["INTENSIFY_COLORS_ON_WIN"] = False xession.shell.shell_type = "prompt_toolkit" xession.shell.shell.styler = XonshStyle() # default style yield xession
def test_path(tmpdir, xonsh_builtins): 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 test_dir = str(tmpdir.mkdir("xonsh-test-highlight-path")) check_token( "cd {}".format(test_dir), [(Name.Builtin, "cd"), (Color.BOLD_BLUE, test_dir)] ) check_token( "cd {}-xxx".format(test_dir), [(Name.Builtin, "cd"), (Text, "{}-xxx".format(test_dir))], ) check_token("cd X={}".format(test_dir), [(Color.BOLD_BLUE, test_dir)]) with builtins.__xonsh__.env.swap(AUTO_CD=True): check_token(test_dir, [(Name.Constant, test_dir)])
def test_lscolors_target(xonsh_builtins): lsc = LsColors.fromstring("ln=target") assert lsc["ln"] == ("NO_COLOR", ) assert lsc.is_target("ln") assert lsc.detype() == "ln=target" assert not (lsc.is_target("mi"))
def test_lscolors_target(): lsc = LsColors.fromstring("ln=target") assert lsc["ln"] == ("TARGET",) assert lsc.detype() == "ln=target"
def test_lscolors_target(xession): lsc = LsColors.fromstring("ln=target") assert lsc["ln"] == ("RESET", ) assert lsc.is_target("ln") assert lsc.detype() == "ln=target" assert not (lsc.is_target("mi"))