From b7245d0d85ee07b4b44ca4b2107a8a2e321950c5 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Mon, 25 Jan 2010 00:26:05 +0100 Subject: [PATCH] [entropy.output] provide function that removes bash color codes from string --- libraries/entropy/output.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libraries/entropy/output.py b/libraries/entropy/output.py index 3b32869ce..eaf92826e 100644 --- a/libraries/entropy/output.py +++ b/libraries/entropy/output.py @@ -251,6 +251,21 @@ def colorize(color_key, text): return codes[color_key] + text + codes["reset"] return text +def decolorize(text): + my_esc_seq = "\x1b" + new_text = '' + append = True + for char in text: + if char == my_esc_seq: + append = False + continue + elif char == "m" and not append: + append = True + continue + if append: + new_text += char + return new_text + def bold(text): """ Make text bold using bash/terminal codes.