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 | |
| parent | 887e799ab10f5e479900adc8fede5238c68073df (diff) | |
| download | sphinx-57b2e34e98ea845422abb244f6efb6e26309e0a4.tar.gz | |
Only do colors on terminals that support them. #4102.
Diffstat (limited to 'sphinx')
| -rw-r--r-- | sphinx/__init__.py | 4 | ||||
| -rw-r--r-- | sphinx/util/console.py | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/sphinx/__init__.py b/sphinx/__init__.py index 9499dc1f..b31a6a52 100644 --- a/sphinx/__init__.py +++ b/sphinx/__init__.py @@ -17,7 +17,7 @@ from os import path from cStringIO import StringIO from sphinx.util import format_exception_cut_frames, save_traceback -from sphinx.util.console import darkred, nocolor +from sphinx.util.console import darkred, nocolor, color_terminal __revision__ = '$Revision$' __version__ = '0.5' @@ -54,7 +54,7 @@ def main(argv=sys.argv): from sphinx.application import Sphinx, SphinxError from docutils.utils import SystemMessage - if not sys.stdout.isatty() or sys.platform == 'win32': + if not sys.stdout.isatty() or sys.platform == 'win32' or not color_terminal(): # Windows' poor cmd box doesn't understand ANSI sequences nocolor() 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() |
