added the ability also specify background color in 8 color mode

This commit is contained in:
Jason Green 2017-10-19 21:48:52 -04:00
commit a47020e5d7

View file

@ -44,6 +44,18 @@ context["colors"] = {
"magenta": 5, "purple": 5, "cyan": 6, "white": 7, "none": -1 "magenta": 5, "purple": 5, "cyan": 6, "white": 7, "none": -1
} }
context["backgrounds"] = {
"black": 0,
"red": 1,
"green": 2,
"yellow": 3,
"blue": 4,
"magenta": 5,
"cyan": 6,
"white": 7
}
context["themes"] = {} context["themes"] = {}
# pre-defined colormaps # pre-defined colormaps
@ -508,6 +520,7 @@ def colorin(text, color="red", style="normal"):
color_code = "" color_code = ""
style_code = "" style_code = ""
background_code = ""
# Convert the style code # Convert the style code
if style == "random" or style == "Random": if style == "random" or style == "Random":
@ -516,7 +529,10 @@ def colorin(text, color="red", style="normal"):
if style in context["styles"]: if style in context["styles"]:
style_code = str(context["styles"][style]) style_code = str(context["styles"][style])
color = color.strip() color_background = color.strip().split("_")
color = color_background[0]
background = color_background[1] if len(color_background) == 2 else None
m = mode(color) m = mode(color)
if color == "none": if color == "none":
@ -572,9 +588,17 @@ def colorin(text, color="red", style="normal"):
else: else:
raise UnknownColor(color) raise UnknownColor(color)
if background in context["backgrounds"] and m == 8:
background_code = endmarks[m] + str(40 + context["backgrounds"][background])
elif background == None:
pass
else:
raise UnknownColor(background)
if color_code is not None: if color_code is not None:
if not debug: if not debug:
return start + style_code + endmarks[m] + color_code + "m" + text + stop return start + style_code + endmarks[m] + color_code + background_code + "m" + text + stop
else: else:
return start + style_code + endmarks[m] + color_code + "m" \ return start + style_code + endmarks[m] + color_code + "m" \
+ "<color name=" + str(color) + " code=" + color_code \ + "<color name=" + str(color) + " code=" + color_code \