diff options
| author | georg.brandl <devnull@localhost> | 2008-10-16 21:16:28 +0000 |
|---|---|---|
| committer | georg.brandl <devnull@localhost> | 2008-10-16 21:16:28 +0000 |
| commit | 57b2e34e98ea845422abb244f6efb6e26309e0a4 (patch) | |
| tree | 4e434fbb8b8d420f73ab954754100f4fc8e94de1 /sphinx/util/console.py | |
| parent | 887e799ab10f5e479900adc8fede5238c68073df (diff) | |
| download | sphinx-57b2e34e98ea845422abb244f6efb6e26309e0a4.tar.gz | |
Only do colors on terminals that support them. #4102.
Diffstat (limited to 'sphinx/util/console.py')
| -rw-r--r-- | sphinx/util/console.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/sphinx/util/console.py b/sphinx/util/console.py index 05ab7e50..d6ebcb94 100644 --- a/sphinx/util/console.py +++ b/sphinx/util/console.py @@ -9,6 +9,8 @@ :license: BSD. """ +import os + codes = {} def get_terminal_width(): @@ -34,6 +36,14 @@ def print_and_backspace(text, func): else: func(text.ljust(_tw) + _tw * "\b") +def color_terminal(): + if 'COLORTERM' in os.environ: + return True + term = os.environ.get('TERM', 'dumb').lower() + if 'xterm' in term or 'color' in term: + return True + return False + def nocolor(): codes.clear() |
