From 20116cf69dd0fddb60b2cb9e9e325a0d39d5d75f Mon Sep 17 00:00:00 2001 From: Fabien Benureau Date: Sat, 29 Jun 2013 22:41:33 +0100 Subject: [PATCH] color.undye method for purging color from strings --- papers/color.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/papers/color.py b/papers/color.py index 794d028..ada8dec 100644 --- a/papers/color.py +++ b/papers/color.py @@ -1,7 +1,7 @@ """ Small code to handle colored text """ - +import re bold = '\033[1m' end = '\033[0m' @@ -37,3 +37,10 @@ def setup(enable = True): dye = _dye else: dye = _nodye + + +undye_re = re.compile('\x1b\[[;\d]*[A-Za-z]') + +def undye(s): + """Purge string s of color""" + return undye_re.sub('', s) \ No newline at end of file