Improved webconfig.py's handling of combined term256 and classic colors

This commit is contained in:
ridiculousfish 2012-06-05 01:19:59 -07:00
parent d871095d0b
commit 53cba2a2e6

View file

@ -37,6 +37,16 @@ def parse_one_color(comp):
# Unknown # Unknown
return '' return ''
def better_color(c1, c2):
""" Indicate which color is "better", i.e. prefer term256 colors """
if not c2: return c1
if not c1: return c2
if c1 == 'normal': return c2
if c2 == 'normal': return c1
if c2 in named_colors: return c1
if c1 in named_colors: return c2
return c1
def parse_color(color_str): def parse_color(color_str):
""" A basic function to parse a color string, for example, 'red' '--bold' """ """ A basic function to parse a color string, for example, 'red' '--bold' """
@ -53,11 +63,10 @@ def parse_color(color_str):
underline = True underline = True
elif comp.startswith('--background='): elif comp.startswith('--background='):
# Background color # Background color
background_color = parse_one_color(comp[len('--background='):]) background_color = better_color(background_color, parse_one_color(comp[len('--background='):]))
else: else:
# Regular color # Regular color
maybe_color = parse_one_color(comp) color = better_color(color, parse_one_color(comp))
if maybe_color: color = maybe_color
return [color, background_color, bold, underline] return [color, background_color, bold, underline]