From b8c38a565361354642ba62d168bbedc2cef2d5e4 Mon Sep 17 00:00:00 2001 From: nojhan Date: Tue, 26 Mar 2013 23:02:52 +0100 Subject: [PATCH] Add the "none" color. Useful when grouping. --- README.md | 2 +- colout.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bb37078..9edd5c5 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ If you ask for less colors, the last one will be duplicated across remaining groups. Available colors are: blue, black, yellow, cyan, green, magenta, white, red, -rainbow, random, Random or any number between 0 and 255. +rainbow, random, Random, none or any number between 0 and 255. Available styles are: normal, bold, faint, italic, underline, blink, rapid_blink, reverse, conceal or random. diff --git a/colout.py b/colout.py index bc0267c..6e37bac 100755 --- a/colout.py +++ b/colout.py @@ -24,7 +24,7 @@ styles = { # Available color names in 8-colors mode colors = { "black": 0, "red": 1, "green": 2, "yellow": 3, "blue": 4, - "magenta": 5, "cyan": 6, "white": 7 + "magenta": 5, "cyan": 6, "white": 7, "none": -1 } rainbow = ["red", "yellow", "green", "cyan", "blue", "magenta"] @@ -79,6 +79,9 @@ def colorin(text, color="red", style="normal"): start = "\033[" stop = "\033[0m" + color_code = "" + style_code = "" + # Convert the style code if style == "random" or style == "Random": style = random.choice(list(styles.keys())) @@ -86,7 +89,11 @@ def colorin(text, color="red", style="normal"): if style in styles: style_code = str(styles[style]) - if color == "random": + if color == "none": + # if no color, style cannot be applied + return text + + elif color == "random": mode = 8 color_code = random.choice(list(colors.values())) color_code = str(30 + color_code)