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
file_color_tokens = dict() """Parallel to LS_COLORS, keyed by dircolors keys, but value is a Color token. Initialized by XonshStyle.""" # define as external funcition so tests can reference it too. def on_lscolors_change(key, oldvalue, newvalue, **kwargs): """if LS_COLORS updated, update file_color_tokens and corresponding color token in style""" if newvalue is None: del file_color_tokens[key] else: file_color_tokens[key] = color_token_by_name(newvalue) events.on_lscolors_change(on_lscolors_change) def color_file(file_path: str, path_stat: os.stat_result) -> (Color, str): """Determine color to use for file *approximately* as ls --color would, given lstat() results and its path. Parameters ---------- file_path: relative path of file (as user typed it). path_stat: lstat() results for file_path. Returns -------