#!/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()