Ejemplo n.º 1
0
 def style_name(self, value):
     if self._style_name == value:
         return
     if value not in STYLES:
         try:  # loading style dynamically
             pygments_style_by_name(value)
         except Exception:
             print(
                 "Could not find style {0!r}, using default".format(value),
                 file=sys.stderr,
             )
             value = "default"
             builtins.__xonsh__.env["XONSH_COLOR_STYLE"] = value
     cmap = STYLES[value]
     if value == "default":
         self._smap = XONSH_BASE_STYLE.copy()
     else:
         try:
             self._smap = get_style_by_name(value)().styles.copy()
         except (ImportError, pygments.util.ClassNotFound):
             self._smap = XONSH_BASE_STYLE.copy()
     compound = CompoundColorMap(ChainMap(self.trap, cmap, PTK_STYLE, self._smap))
     self.styles = ChainMap(self.trap, cmap, PTK_STYLE, self._smap, compound)
     self._style_name = value
     # Convert new ansicolor names to old PTK1 names
     # Can be remvoed when PTK1 support is dropped.
     if builtins.__xonsh__.shell.shell_type != "prompt_toolkit2":
         for smap in [self.trap, cmap, PTK_STYLE, self._smap]:
             smap.update(ansicolors_to_ptk1_names(smap))
     if ON_WINDOWS and "prompt_toolkit" in builtins.__xonsh__.shell.shell_type:
         self.enhance_colors_for_cmd_exe()
Ejemplo n.º 2
0
 def style_name(self, value):
     if self._style_name == value:
         return
     if value not in STYLES:
         try:  # loading style dynamically
             pygments_style_by_name(value)
         except Exception:
             print(
                 'Could not find style {0!r}, using default'.format(value),
                 file=sys.stderr)
             value = 'default'
             builtins.__xonsh_env__['XONSH_COLOR_STYLE'] = value
     cmap = STYLES[value]
     if value == 'default':
         self._smap = XONSH_BASE_STYLE.copy()
     else:
         try:
             self._smap = get_style_by_name(value)().styles.copy()
         except (ImportError, pygments.util.ClassNotFound):
             self._smap = XONSH_BASE_STYLE.copy()
     compound = CompoundColorMap(
         ChainMap(self.trap, cmap, PTK_STYLE, self._smap))
     self.styles = ChainMap(self.trap, cmap, PTK_STYLE, self._smap,
                            compound)
     self._style_name = value
     if ON_WINDOWS:
         self.enhance_colors_for_cmd_exe()
Ejemplo n.º 3
0
def pygments_style_by_name(name):
    """Gets or makes a pygments color style by its name."""
    if name in STYLES:
        return STYLES[name]
    pstyle = get_style_by_name(name)
    palette = make_palette(pstyle.styles.values())
    astyle = make_pygments_style(palette)
    STYLES[name] = astyle
    return astyle
Ejemplo n.º 4
0
def pygments_style_by_name(name):
    """Gets or makes a pygments color style by its name."""
    if name in STYLES:
        return STYLES[name]
    pstyle = get_style_by_name(name)
    palette = make_palette(pstyle.styles.values())
    astyle = make_pygments_style(palette)
    STYLES[name] = astyle
    return astyle
Ejemplo n.º 5
0
def ansi_style_by_name(name):
    """Gets or makes an ANSI color style by name. If the styles does not
    exist, it will look for a style using the pygments name.
    """
    if name in ANSI_STYLES:
        return ANSI_STYLES[name]
    elif not HAS_PYGMENTS:
        raise KeyError("could not find style {0!r}".format(name))
    from xonsh.pygments_cache import get_style_by_name
    from pygments.util import ClassNotFound

    try:
        pstyle = get_style_by_name(name)
    except (ModuleNotFoundError, ClassNotFound):
        pstyle = get_style_by_name("default")
    palette = make_palette(pstyle.styles.values())
    astyle = make_ansi_style(palette)
    ANSI_STYLES[name] = astyle
    return astyle
Ejemplo n.º 6
0
def ansi_style_by_name(name):
    """Gets or makes an ANSI color style by name. If the styles does not
    exist, it will look for a style using the pygments name.
    """
    if name in ANSI_STYLES:
        return ANSI_STYLES[name]
    elif not HAS_PYGMENTS:
        raise KeyError('could not find style {0!r}'.format(name))
    from xonsh.pygments_cache import get_style_by_name
    pstyle = get_style_by_name(name)
    palette = make_palette(pstyle.styles.values())
    astyle = make_ansi_style(palette)
    ANSI_STYLES[name] = astyle
    return astyle
Ejemplo n.º 7
0
def ansi_style_by_name(name):
    """Gets or makes an ANSI color style by name. If the styles does not
    exist, it will look for a style using the pygments name.
    """
    if name in ANSI_STYLES:
        return ANSI_STYLES[name]
    elif not HAS_PYGMENTS:
        raise KeyError("could not find style {0!r}".format(name))
    from xonsh.pygments_cache import get_style_by_name

    pstyle = get_style_by_name(name)
    palette = make_palette(pstyle.styles.values())
    astyle = make_ansi_style(palette)
    ANSI_STYLES[name] = astyle
    return astyle
Ejemplo n.º 8
0
    def style_name(self, value):
        if self._style_name == value:
            return
        if value not in STYLES:
            try:  # loading style dynamically
                pygments_style_by_name(value)
            except Exception:
                print(
                    "Could not find style {0!r}, using default".format(value),
                    file=sys.stderr,
                )
                value = "default"
                builtins.__xonsh__.env["XONSH_COLOR_STYLE"] = value
        cmap = STYLES[value]
        if value == "default":
            self._smap = XONSH_BASE_STYLE.copy()
        else:
            try:
                style_obj = get_style_by_name(value)()
                self._smap = style_obj.styles.copy()
                self.highlight_color = style_obj.highlight_color
                self.background_color = style_obj.background_color
            except (ImportError, pygments.util.ClassNotFound):
                self._smap = XONSH_BASE_STYLE.copy()
        compound = CompoundColorMap(ChainMap(self.trap, cmap, PTK_STYLE, self._smap))
        self.styles = ChainMap(self.trap, cmap, PTK_STYLE, self._smap, compound)
        self._style_name = value

        for file_type, xonsh_color in builtins.__xonsh__.env.get(
            "LS_COLORS", {}
        ).items():
            color_token = color_token_by_name(xonsh_color, self.styles)
            file_color_tokens[file_type] = color_token

        # Convert new ansicolor names to old PTK1 names
        # Can be remvoed when PTK1 support is dropped.
        if (
            builtins.__xonsh__.shell.shell_type != "prompt_toolkit2"
            and pygments_version_info()
            and pygments_version_info() < (2, 4, 0)
        ):
            for smap in [self.trap, cmap, PTK_STYLE, self._smap]:
                smap.update(ansicolors_to_ptk1_names(smap))

        if ON_WINDOWS and "prompt_toolkit" in builtins.__xonsh__.shell.shell_type:
            self.enhance_colors_for_cmd_exe()
Ejemplo n.º 9
0
    def style_name(self, value):
        if self._style_name == value:
            return
        if value not in STYLES:
            try:  # loading style dynamically
                pygments_style_by_name(value)
            except Exception:
                print(
                    "Could not find style {0!r}, using default".format(value),
                    file=sys.stderr,
                )
                value = "default"
                builtins.__xonsh__.env["XONSH_COLOR_STYLE"] = value
        cmap = STYLES[value]
        if value == "default":
            self._smap = XONSH_BASE_STYLE.copy()
        else:
            try:
                style_obj = get_style_by_name(value)()
                self._smap = style_obj.styles.copy()
                self.highlight_color = style_obj.highlight_color
                self.background_color = style_obj.background_color
            except (ImportError, pygments.util.ClassNotFound):
                self._smap = XONSH_BASE_STYLE.copy()
        compound = CompoundColorMap(
            ChainMap(self.trap, cmap, PTK_STYLE, self._smap))
        self.styles = ChainMap(self.trap, cmap, PTK_STYLE, self._smap,
                               compound)
        self._style_name = value

        for file_type, xonsh_color in builtins.__xonsh__.env.get(
                "LS_COLORS", {}).items():
            color_token = color_token_by_name(xonsh_color, self.styles)
            file_color_tokens[file_type] = color_token

        if ON_WINDOWS and "prompt_toolkit" in builtins.__xonsh__.shell.shell_type:
            self.enhance_colors_for_cmd_exe()