summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/common
diff options
context:
space:
mode:
authorDan Klein <danklein10@gmail.com>2015-10-29 07:54:21 +0200
committerDan Klein <danklein10@gmail.com>2015-10-29 08:15:05 +0200
commit5377774afbf00b0da0ad0b74d3be207f6eb9124e (patch)
treeca4a9a5e9a4e477054f713d9552408be98b1213d /scripts/automation/trex_control_plane/common
parentf963facdc949c087c863b8ad81aae537bcf3767b (diff)
Added module for text formatting, such that coloring, bold, underline.
Diffstat (limited to 'scripts/automation/trex_control_plane/common')
-rw-r--r--scripts/automation/trex_control_plane/common/text_opts.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/common/text_opts.py b/scripts/automation/trex_control_plane/common/text_opts.py
new file mode 100644
index 00000000..8ab03eeb
--- /dev/null
+++ b/scripts/automation/trex_control_plane/common/text_opts.py
@@ -0,0 +1,72 @@
+
+
+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'},
+ 'underline': {'start': '\x1b[4m',
+ 'end': '\x1b[24m'}}
+
+
+def bold(text):
+ return text_attribute(text, 'bold')
+
+
+def cyan(text):
+ return text_attribute(text, 'cyan')
+
+
+def blue(text):
+ return text_attribute(text, 'blue')
+
+
+def red(text):
+ return text_attribute(text, 'red')
+
+
+def magenta(text):
+ return text_attribute(text, 'magenta')
+
+
+def green(text):
+ return text_attribute(text, 'green')
+
+
+def underline(text):
+ return text_attribute(text, 'underline')
+
+
+def text_attribute(text, attribute):
+ return "{start}{txt}{stop}".format(start=TEXT_CODES[attribute]['start'],
+ txt=text,
+ stop=TEXT_CODES[attribute]['end'])
+
+
+FUNC_DICT = {'blue': blue,
+ 'bold': bold,
+ 'green': green,
+ 'cyan': cyan,
+ 'magenta': magenta,
+ 'underline': underline,
+ 'red': red}
+
+
+def format_text(text, *args):
+ return_string = text
+ for i in args:
+ func = FUNC_DICT.get(i)
+ if func:
+ return_string = func(return_string)
+ return return_string
+
+
+if __name__ == "__main__":
+ pass