[PATCH] color: use ui.formatted() to test TTYness, not sys.stdout.isatty()

Brodie Rao brodie at bitheap.org
Sun May 1 05:14:24 CDT 2011


# HG changeset patch
# User Brodie Rao <brodie at bitheap.org>
# Date 1304244862 -7200
# Node ID de9e9fed0d5ed6eb6f35ad7f387e3c447b4e22e8
# Parent  3e9e02a41dfb0a85ec0968681e416d579ee875db
color: use ui.formatted() to test TTYness, not sys.stdout.isatty()

This fixes the color extension not working with pager (broken in
877390020477). The pager extension already sets ui.formatted=True to
allow this use case.

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -301,13 +301,15 @@ def uisetup(ui):
     global _terminfo_params
     if ui.plain():
         return
+
+    formatted = (os.environ.get('TERM') != 'dumb' and ui.formatted())
     mode = ui.config('color', 'mode', 'auto')
     if mode == 'auto':
         if os.name == 'nt' and 'TERM' not in os.environ:
             # looks line a cmd.exe console, use win32 API or nothing
             mode = w32effects and 'win32' or 'none'
         else:
-            if getattr(sys.stdout, 'isatty', None) and sys.stdout.isatty():
+            if not formatted:
                 _terminfo_params = False
             else:
                 _terminfosetup(ui)
@@ -332,8 +334,7 @@ def uisetup(ui):
         auto = coloropt == 'auto'
         always = util.parsebool(coloropt)
         if (always or
-            (always is None and
-             (auto and (os.environ.get('TERM') != 'dumb' and ui_.formatted())))):
+            (always is None and auto and formatted)):
             colorui._colormode = mode
             colorui.__bases__ = (ui_.__class__,)
             ui_.__class__ = colorui


More information about the Mercurial-devel mailing list