diff --git a/colout/colout.py b/colout/colout.py index b80e065..cd7d68b 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 @@ -335,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) @@ -508,15 +520,23 @@ def colorin(text, color="red", style="normal"): color_code = "" style_code = "" - + background_code = "" + list_style_code = [] + # Convert the style code if style == "random" or style == "Random": style = random.choice(list(context["styles"].keys())) else: - if style in context["styles"]: - style_code = str(context["styles"][style]) + styles = style.split(".") + for astyle in styles: + if astyle in context["styles"]: + list_style_code.append(str(context["styles"][astyle])) + style_code = ";".join(list_style_code) + + 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 +592,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" \ + "