Skip to content
Back to top
View this page
Edit this page

# xonsh.ansi_colors

Tools for helping with ANSI color codes.

xonsh.ansi_colors.ansi_color_escape_code_to_name(escape_code, style, reversed_style=None)

  Converts an ANSI color code escape sequence to a tuple of color names in the provided style (‘default’ should almost be the style). For example, ‘0’ becomes (‘RESET’,) and ‘32;41’ becomes (‘GREEN’, ‘BACKGROUND_RED’). The style keyword may either be a string, in which the style is looked up, or an actual style dict. You can also provide a reversed style mapping, too, which is just the keys/values of the style dict swapped. If reversed style is not provided, it is computed.

xonsh.ansi_colors.ansi_color_name_to_escape_code(name, style='default', cmap=None)

  Converts a color name to the inner part of an ANSI escape code

xonsh.ansi_colors.ansi_color_style(style='default')

  Returns the current color map.

xonsh.ansi_colors.ansi_color_style_names()

  Returns an iterable of all ANSI color style names.

xonsh.ansi_colors.ansi_partial_color_format(template, style='default', cmap=None, hide=False)

  Formats a template string but only with respect to the colors. Another template string is returned, with the color values filled in.

  Parameters:
    template str

      The template string, potentially with color names.

    style str, optional

      Style name to look up color map from.

    cmap dict, optional

      A color map to use, this will prevent the color map from being looked up via the style name.

    hide bool, optional

      Whether to wrap the color codes in the 001 and 002 escape codes, so that the color codes are not counted against line length.

  Returns:
    A template string with the color values filled in.

xonsh.ansi_colors.ansi_reverse_style(style='default', return_style=False)

  Reverses an ANSI color style mapping so that escape codes map to colors. Style may either be string or mapping. May also return the style it looked up.

xonsh.ansi_colors.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.

xonsh.ansi_colors.make_ansi_style(palette)

  Makes an ANSI color style from a color palette

xonsh.ansi_colors.register_custom_ansi_style(name, styles, base='default')

  Register custom ANSI style.

  Parameters:
    name str

      Style name.

    styles dict

      Token (or str) -> style mapping.

    base str, optional

      Base style to use as default.