From a8e56413815123b4bb10f3ddd597f42d11c8ad46 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 25 May 2019 23:33:13 +0200 Subject: Move init_colorama function to external file --- utils/utils.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 utils/utils.py (limited to 'utils/utils.py') diff --git a/utils/utils.py b/utils/utils.py new file mode 100644 index 00000000..a76beb5d --- /dev/null +++ b/utils/utils.py @@ -0,0 +1,23 @@ +#!/bin/python3 + +from contextlib import contextmanager +import colorama + + +@contextmanager +def init_colorama(): + """Set global foreground modifying ANSI codes. + + BLACK, BLUE, CYAN, GREEN, MAGENTA, RED, WHITE, YELLOW, and RESET. + + """ + + # pylint: disable=exec-used,invalid-name + + colorama.init() + for color, ansi in colorama.Fore.__dict__.items(): + exec("global {0}; {0} = '{1}'".format(color, ansi)) + yield + for color in colorama.Fore.__dict__: + exec("global {0}; {0} = ''".format(color)) + colorama.deinit() -- cgit v1.2.1