summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2016-12-18 20:11:31 +0200
committerYaroslav Brustinov <ybrustin@cisco.com>2016-12-19 11:23:48 +0200
commit5cfeb192a3ff47c5cacc21abe20db2f61a66dd2b (patch)
tree57a455e70d9ac9c453495f4929ac9fac5b9fb011 /scripts/automation/trex_control_plane/stl/trex_stl_lib/utils
parentcc4bd93b660505a7c9d8e370a1220377907fa6d2 (diff)
changes from code review
Change-Id: I628608643d902bd6310b04b8036fc5f1fcc42309 Signed-off-by: Yaroslav Brustinov <ybrustin@cisco.com>
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib/utils')
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py20
1 files changed, 6 insertions, 14 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py
index 6c5dd2c3..63b05bf4 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py
@@ -131,21 +131,13 @@ def yellow(text):
def underline(text):
return text_attribute(text, 'underline')
-
-start_end_newlines = re.compile('^(\n)*([^\n].*[^\n])?(\n)*$', re.DOTALL)
+# apply attribute on each non-empty line
def text_attribute(text, attribute):
- match = start_end_newlines.match(text)
- try:
- startpad, msg, endpad = match.groups('')
- except:
- startpad = endpad = ''
- msg = text
- return "{startpad}{startattr}{txt}{endattr}{endpad}".format(
- startpad = startpad,
- startattr = TEXT_CODES[attribute]['start'],
- txt = msg,
- endattr = TEXT_CODES[attribute]['end'],
- endpad = endpad)
+ return '\n'.join(['{start}{txt}{end}'.format(
+ start = TEXT_CODES[attribute]['start'],
+ txt = line,
+ end = TEXT_CODES[attribute]['end'])
+ if line else '' for line in ('%s' % text).split('\n')])
FUNC_DICT = {'blue': blue,