Exemple #1
0
def parse(style_string):
    for s in style_string.split():
        if s.startswith("#"):
            ix = s[1:] if len(s) == 7 else "".join(_ * 2 for _ in s[1:])
            c = x256.to_rgb(x256.from_hex(ix))
            return "\"#{:02x}{:02x}{:02x}\"".format(*c)
    return "nil"
Exemple #2
0
def load_style(name):
    style = pygments.styles.get_style_by_name(name)
    bg = parse(style.background_color)
    fg = parse(style.styles[Text])
    if fg == "nil":
        brightness = sum(x256.to_rgb(x256.from_hex(bg[2:-1]))) / 3
        fg = "\"#000000\"" if brightness >= 128 else "\"#FFFFFF\""
    style_dict = dict((str(k), parse(v)) for k, v in style.styles.items())
    return bg, fg, translate(style_dict)
Exemple #3
0
def color_to_hex(color):
    """
    Given either an hexadecimal or HTML color name, return a the hex
    approximation without the `#`.
    """
    if color.startswith("#"):
        return x256.from_hex(color.strip("#"))
    else:
        return x256.from_html_name(color)
Exemple #4
0
def color_to_hex(color):
    """
    Given either an hexadecimal or HTML color name, return a the hex
    approximation without the `#`.
    """
    if color.startswith("#"):
        return x256.from_hex(color.strip("#"))
    else:
        return x256.from_html_name(color)
Exemple #5
0
 def test_from_hex(self):
     color = x256.from_hex(self.hex)
     self.assertEqual(self.xcolor, color)
Exemple #6
0
def create_label_attr(label):
    # TODO: sensible foreground color
    bg = "h%s" % x256.from_hex(label.color)
    return urwid.AttrSpec("black", bg)
Exemple #7
0
def create_label_attr(label):
    # TODO: sensible foreground color
    bg = "h%s" % x256.from_hex(label.color)
    return urwid.AttrSpec("black", bg)
def rgb2xterm(rgb, color_text):
    rgb = rgb.lstrip('#')
    color = x256.from_hex(rgb)
    text = 'RGB {} -> xterm color {}'.format(rgb, color)
    print_color(color, text, color_text=color_text)
def colorize(fg,bg):
	return '\x1b[38;5;' + str(x256.from_hex(fg[1:])) + 'm' + '\x1b[48;5;' + str(x256.from_hex(bg[1:])) + 'm'