From a47020e5d7150839b02d350063d25a1e3e6c3eec Mon Sep 17 00:00:00 2001 From: Jason Green Date: Thu, 19 Oct 2017 21:48:52 -0400 Subject: [PATCH 1/3] added the ability also specify background color in 8 color mode --- colout/colout.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/colout/colout.py b/colout/colout.py index a5744d9..641abf5 100755 --- a/colout/colout.py +++ b/colout/colout.py @@ -44,6 +44,18 @@ context["colors"] = { "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"] = {} # pre-defined colormaps @@ -508,6 +520,7 @@ def colorin(text, color="red", style="normal"): color_code = "" style_code = "" + background_code = "" # Convert the style code if style == "random" or style == "Random": @@ -515,8 +528,11 @@ def colorin(text, color="red", style="normal"): else: if style in context["styles"]: style_code = str(context["styles"][style]) + + color_background = color.strip().split("_") + color = color_background[0] + background = color_background[1] if len(color_background) == 2 else None - color = color.strip() m = mode(color) if color == "none": @@ -572,9 +588,17 @@ def colorin(text, color="red", style="normal"): else: 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 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: return start + style_code + endmarks[m] + color_code + "m" \ + " Date: Fri, 20 Oct 2017 21:30:43 -0400 Subject: [PATCH 3/3] fixed color --- colout/colout.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colout/colout.py b/colout/colout.py index d492747..73e43ea 100755 --- a/colout/colout.py +++ b/colout/colout.py @@ -347,7 +347,7 @@ def color_random( color ): global context m = mode(color) if m == 8: - color_name = random.choice(context["colormaps"]["random"]) + color_name = random.choice(list(context["colormaps"]["random"])) color_code = context["colors"][color_name] color_code = str(30 + color_code)