From f082dbc3a2898960df6f98d8ac71d8a129e4e497 Mon Sep 17 00:00:00 2001 From: nojhan Date: Wed, 5 Jun 2013 13:19:03 +0200 Subject: [PATCH] feature #35: show colors tags in debug mode --- colout/colout.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/colout/colout.py b/colout/colout.py index 7b1ff80..59fffa8 100755 --- a/colout/colout.py +++ b/colout/colout.py @@ -259,6 +259,7 @@ def colorin(text, color="red", style="normal"): assert( type(color) is str ) global colormap_idx + global debug # Special characters. start = "\033[" @@ -276,7 +277,10 @@ def colorin(text, color="red", style="normal"): if color == "none": # if no color, style cannot be applied - return text + if not debug: + return text + else: + return ""+text+"" elif color == "random": mode = 8 @@ -388,13 +392,19 @@ def colorin(text, color="red", style="normal"): formatter = TerminalFormatter(bg=style) # We should return all but the last character, # because Pygments adds a newline char. - return highlight(text, lexer, formatter)[:-1] + if not debug: + return highlight(text, lexer, formatter)[:-1] + else: + return "<"+color+">"+ highlight(text, lexer, formatter)[:-1] + "" # unrecognized else: raise UnknownColor(color) - return start + style_code + endmarks[mode] + color_code + "m" + text + stop + if not debug: + return start + style_code + endmarks[mode] + color_code + "m" + text + stop + else: + return start + style_code + endmarks[mode] + color_code + "m<" + color + ">" + text + "" + stop def colorout(text, match, prev_end, color="red", style="normal", group=0):