def test_XonshStyle_init_file_color_tokens(xonsh_builtins_LS_COLORS): xs = XonshStyle() assert xs.styles assert type(file_color_tokens) is dict assert set(file_color_tokens.keys()) == set( xonsh_builtins_LS_COLORS.__xonsh__.env["LS_COLORS"].keys() )
def test_XonshStyle_init_file_color_tokens(xs_LS_COLORS, monkeypatch): keys = list(file_color_tokens) for n in keys: monkeypatch.delitem(file_color_tokens, n) xs = XonshStyle() assert xs.styles assert type(file_color_tokens) is dict assert set(file_color_tokens.keys()) == set(xs_LS_COLORS.env["LS_COLORS"].keys())
def styler(self): if self._styler is DefaultNotGiven: if HAS_PYGMENTS: from xonsh.pyghooks import XonshStyle env = builtins.__xonsh_env__ self._styler = XonshStyle(env.get('XONSH_COLOR_STYLE')) else: self._styler = None return self._styler
def test_colorize_file(key, file_path, colorizable_files, xonsh_builtins_LS_COLORS): xonsh_builtins_LS_COLORS.__xonsh__.shell.shell.styler = ( XonshStyle() ) # default style ffp = colorizable_files + "/" + file_path mode = (os.lstat(ffp)).st_mode color_token, color_key = color_file(ffp, mode) assert color_key == key, "File classified as expected kind" assert color_token == file_color_tokens[key], "Color token is as expected"
def test_color_token_by_name(in_tuple, exp_ct, exp_ansi_colors, xs_LS_COLORS): from xonsh.pyghooks import XonshStyle, color_token_by_name xs = XonshStyle() styles = xs.styles ct = color_token_by_name(in_tuple, styles) ansi_colors = styles[ct] # if keyerror, ct was not cached assert ct == exp_ct, "returned color token is right" assert ansi_colors == exp_ansi_colors, "color token mapped to correct color string"
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 styler(self): if self._styler is DefaultNotGiven: if HAS_PYGMENTS: from xonsh.pyghooks import XonshStyle env = XSH.env self._styler = XonshStyle(env.get("XONSH_COLOR_STYLE")) else: self._styler = None return self._styler
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 __init__(self, execer, ctx, **kwargs): super().__init__(**kwargs) self.execer = execer self.ctx = ctx self.completer = Completer() self.buffer = [] self.need_more_lines = False self.mlprompt = None if HAVE_PYGMENTS: env = builtins.__xonsh_env__ self.styler = XonshStyle(env.get('XONSH_COLOR_STYLE')) else: self.styler = None
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 html_format(s, style="default"): buf = io.StringIO() proxy_style = xonsh_style_proxy(XonshStyle(style)) # make sure we have a foreground color fgcolor = proxy_style._styles[Token.Text][0] if not fgcolor: fgcolor = invert_color(proxy_style.background_color[1:].strip("#")) # need to generate stream before creating formatter so that all tokens actually exist if isinstance(s, str): token_stream = partial_color_tokenize(s) else: token_stream = s formatter = XonshHtmlFormatter( wrapcode=True, noclasses=True, style=proxy_style, prestyles="margin: 0em; padding: 0.5em 0.1em; color: #" + fgcolor, cssstyles="border-style: solid; border-radius: 5px", ) formatter.format(token_stream, buf) return buf.getvalue()