diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/__init__.py | 0 | ||||
-rw-r--r-- | utils/utils.py | 23 |
2 files changed, 23 insertions, 0 deletions
diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/utils/__init__.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() |