Commits

Anonymous committed c8f0941

Only do colors on terminals that support them. #4102.

  • Participants
  • Parent commits 512a8d9

Comments (0)

Files changed (3)

 
 * Don't crash on weird casing of role names (like ``:Class:``).
 
+* Only output ANSI colors on color terminals.
+
 
 Release 0.4.3 (Oct 8, 2008)
 ===========================

File sphinx/__init__.py

 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'
     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()
 

File sphinx/util/console.py

     :license: BSD.
 """
 
+import os
+
 codes = {}
 
 def get_terminal_width():
     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()