diff options
Diffstat (limited to 'sphinx/util/console.py')
-rw-r--r-- | sphinx/util/console.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/sphinx/util/console.py b/sphinx/util/console.py index 24d3e4568..ee6e4ea91 100644 --- a/sphinx/util/console.py +++ b/sphinx/util/console.py @@ -22,6 +22,7 @@ except ImportError: _ansi_re = re.compile('\x1b\\[(\\d\\d;){0,2}\\d\\dm') codes = {} + def get_terminal_width(): """Borrowed from the py lib.""" try: @@ -41,6 +42,8 @@ def get_terminal_width(): _tw = get_terminal_width() + + def term_width_line(text): if not codes: # if no coloring, don't output fancy backspaces @@ -49,6 +52,7 @@ def term_width_line(text): # codes are not displayed, this must be taken into account return text.ljust(_tw + len(text) - len(_ansi_re.sub('', text))) + '\r' + def color_terminal(): if sys.platform == 'win32' and colorama is not None: colorama.init() @@ -70,15 +74,19 @@ def nocolor(): colorama.deinit() codes.clear() + def coloron(): codes.update(_orig_codes) + def colorize(name, text): return codes.get(name, '') + text + codes.get('reset', '') + def strip_colors(s): return re.compile('\x1b.*?m').sub('', s) + def create_color_func(name): def inner(text): return colorize(name, text) |