test suite reviews and discussions
 help / color / mirror / Atom feed
* [dts] [Patch V1] framework/texttable.py: Add the class of supporting trex sent this patch on behalf of chen hongli
@ 2017-09-20 12:13 wang fei
  0 siblings, 0 replies; only message in thread
From: wang fei @ 2017-09-20 12:13 UTC (permalink / raw)
  To: dts; +Cc: wang fei

Signed-off-by: wang fei <feix.y.wang@intel.com>
---
 framework/texttable.py | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/framework/texttable.py b/framework/texttable.py
index 2f37a0c..f423bf7 100644
--- a/framework/texttable.py
+++ b/framework/texttable.py
@@ -92,6 +92,7 @@ Brian Peterson:
 
 import sys
 import string
+import re
 from functools import reduce
 
 try:
@@ -122,6 +123,34 @@ def len(iterable):
     except:
         return iterable.__len__()
 
+TEXT_CODES = {'bold': {'start': '\x1b[1m',
+                       'end': '\x1b[22m'},
+              'cyan': {'start': '\x1b[36m',
+                       'end': '\x1b[39m'},
+              'blue': {'start': '\x1b[34m',
+                       'end': '\x1b[39m'},
+              'red': {'start': '\x1b[31m',
+                      'end': '\x1b[39m'},
+              'magenta': {'start': '\x1b[35m',
+                          'end': '\x1b[39m'},
+              'green': {'start': '\x1b[32m',
+                        'end': '\x1b[39m'},
+              'yellow': {'start': '\x1b[33m',
+                         'end': '\x1b[39m'},
+              'underline': {'start': '\x1b[4m',
+                            'end': '\x1b[24m'}}
+
+class TextCodesStripper:
+    keys = [re.escape(v['start']) for k,v in TEXT_CODES.items()]
+    keys += [re.escape(v['end']) for k,v in TEXT_CODES.items()]
+    pattern = re.compile("|".join(keys))
+
+    @staticmethod
+    def strip (s):
+        return re.sub(TextCodesStripper.pattern, '', s)
+
+def ansi_len (iterable):
+    return len(TextCodesStripper.strip(iterable))
 
 class ArraySizeError(Exception):
 
-- 
2.7.4

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-09-20  9:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-20 12:13 [dts] [Patch V1] framework/texttable.py: Add the class of supporting trex sent this patch on behalf of chen hongli wang fei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).