color: verify stdout is a tty before using curses
authorAugie Fackler <durin42@gmail.com>
Sat, 30 Apr 2011 11:18:43 -0500
changeset 14095 877390020477
parent 14094 d10c6835497e
child 14096 dea93484cf9f
color: verify stdout is a tty before using curses Without this change, curses complains when invoked in certain contexts because stdout isn't a tty (such as emacs integration) but we ask it to check for various bits of information from terminfo.
hgext/color.py
--- a/hgext/color.py	Sun May 01 03:51:04 2011 -0500
+++ b/hgext/color.py	Sat Apr 30 11:18:43 2011 -0500
@@ -100,7 +100,7 @@
 
 '''
 
-import os
+import os, sys
 
 from mercurial import commands, dispatch, extensions, ui as uimod, util
 from mercurial.i18n import _
@@ -307,11 +307,14 @@
             # looks line a cmd.exe console, use win32 API or nothing
             mode = w32effects and 'win32' or 'none'
         else:
-            _terminfosetup(ui)
-            if not _terminfo_params:
-                mode = 'ansi'
+            if getattr(sys.stdout, 'isatty', None) and sys.stdout.isatty():
+                _terminfo_params = False
             else:
-                mode = 'terminfo'
+                _terminfosetup(ui)
+                if not _terminfo_params:
+                    mode = 'ansi'
+                else:
+                    mode = 'terminfo'
     if mode == 'win32':
         if w32effects is None:
             # only warn if color.mode is explicitly set to win32