def _pygments_to_ansi_style(style): """Tries to convert the given pygments style to ANSI style. Parameter --------- style : pygments style value Returns ------- ANSI style """ ansi_style_list = [] parts = style.split(" ") for part in parts: if part == "bold": ansi_style_list.append("1") elif part == "italic": ansi_style_list.append("3") elif part == "underline": ansi_style_list.append("4") elif part[:3] == "bg:": ansi_style_list.append("48;5;" + rgb2short(part[3:])[0]) else: ansi_style_list.append("38;5;" + rgb2short(part)[0]) return ";".join(ansi_style_list)
def make_ansi_style(palette): """Makes an ANSI color style from a color palette""" style = {"RESET": "0"} for name, t in BASE_XONSH_COLORS.items(): closest = find_closest_color(t, palette) if len(closest) == 3: closest = "".join([a * 2 for a in closest]) short = rgb2short(closest)[0] style[name] = "38;5;" + short return style
def make_ansi_style(palette): """Makes an ANSI color style from a color palette""" style = {"NO_COLOR": "0"} for name, t in BASE_XONSH_COLORS.items(): closest = find_closest_color(t, palette) if len(closest) == 3: closest = "".join([a * 2 for a in closest]) short = rgb2short(closest)[0] style[name] = "38;5;" + short return style
def _pygments_to_ansi_style(style): """Tries to convert the given pygments style to ANSI style. Parameters ---------- style : pygments style value Returns ------- ANSI style """ ansi_style_list = [] parts = style.split(" ") for part in parts: if part in _PART_STYLE_CODE_MAPPING: ansi_style_list.append(_PART_STYLE_CODE_MAPPING[part]) elif part[:3] == "bg:": ansi_style_list.append("48;5;" + rgb2short(part[3:])[0]) else: ansi_style_list.append("38;5;" + rgb2short(part)[0]) return ";".join(ansi_style_list)
def make_ansi_style(palette): """Makes an ANSI color style from a color palette""" style = {"NO_COLOR": "0"} for name, t in BASE_XONSH_COLORS.items(): closest = find_closest_color(t, palette) if len(closest) == 3: closest = "".join([a * 2 for a in closest]) short = rgb2short(closest)[0] style[name] = "38;5;" + short style["BOLD_" + name] = "1;38;5;" + short style["UNDERLINE_" + name] = "4;38;5;" + short style["BOLD_UNDERLINE_" + name] = "1;4;38;5;" + short style["BACKGROUND_" + name] = "48;5;" + short return style
def make_ansi_style(palette): """Makes an ANSI color style from a color palette""" style = {'NO_COLOR': '0'} for name, t in BASE_XONSH_COLORS.items(): closest = find_closest_color(t, palette) if len(closest) == 3: closest = ''.join([a * 2 for a in closest]) short = rgb2short(closest)[0] style[name] = '38;5;' + short style['BOLD_' + name] = '1;38;5;' + short style['UNDERLINE_' + name] = '4;38;5;' + short style['BOLD_UNDERLINE_' + name] = '1;4;38;5;' + short style['BACKGROUND_' + name] = '48;5;' + short return style
def make_ansi_style(pallette): """Makes an ANSI color style from a color pallette""" style = {'NO_COLOR': '0'} for name, t in BASE_XONSH_COLORS.items(): closest = find_closest_color(t, pallette) if len(closest) == 3: closest = ''.join([a*2 for a in closest]) short = rgb2short(closest)[0] style[name] = '38;5;' + short style['BOLD_'+name] = '1;38;5;' + short style['UNDERLINE_'+name] = '4;38;5;' + short style['BOLD_UNDERLINE_'+name] = '1;4;38;5;' + short style['BACKGROUND_'+name] = '48;5;' + short return style