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)[source]

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)[source]

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

xonsh.ansi_colors.ansi_color_style(style='default')[source]

Returns the current color map.

xonsh.ansi_colors.ansi_color_style_names()[source]

Returns an iterable of all ANSI color style names.

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

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

Parameters:
templatestr

The template string, potentially with color names.

stylestr, optional

Style name to look up color map from.

cmapdict, optional

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

hidebool, 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)[source]

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)[source]

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)[source]

Makes an ANSI color style from a color palette

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

Register custom ANSI style.

Parameters:
namestr

Style name.

stylesdict

Token (or str) -> style mapping.

basestr, optional

Base style to use as default.