From: wang fei <feix.y.wang@intel.com>
To: dts@dpdk.org
Cc: wang fei <feix.y.wang@intel.com>
Subject: [dts] [Patch V1] framework/texttable.py: Add the class of supporting trex sent this patch on behalf of chen hongli
Date: Wed, 20 Sep 2017 20:13:51 +0800 [thread overview]
Message-ID: <1505909631-49915-1-git-send-email-feix.y.wang@intel.com> (raw)
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
reply other threads:[~2017-09-20 9:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1505909631-49915-1-git-send-email-feix.y.wang@intel.com \
--to=feix.y.wang@intel.com \
--cc=dts@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).