[entropy.output] provide function that removes bash color codes from string

This commit is contained in:
Fabio Erculiani
2010-01-25 00:26:05 +01:00
parent d39d5dfcdb
commit b7245d0d85
+15
View File
@@ -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.