[PATCH] color: verify stdout is a tty before using curses

Augie Fackler durin42 at gmail.com
Sat Apr 30 11:18:50 CDT 2011


# HG changeset patch
# User Augie Fackler <durin42 at gmail.com>
# Date 1304180323 18000
# Node ID e316d00e4ad54d48364145fe4d8d548ad2f0a3f4
# Parent  58e58406ed190ce59c78de13e82da1f6bc47f06c
color: verify stdout is a tty before using curses

Without this change, curses complains when invoked in certain contexts
(such as emacs integration.)

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -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', lambda : False)():
+                _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


More information about the Mercurial-devel mailing list