changeset 14769:9adce4b38ed1 stable

color: for the sake of "less -R", default to ansi in auto mode (issue2792) less with the -R option only supports ANSI color codes, and terminfo mode issue non-ANSI color codes (depending on the database). The -r option can work around this, but there are users currently using the -R option, and defaulting to terminfo would break colorization in less for them without warning.
author Brodie Rao <brodie@bitheap.org>
date Wed, 29 Jun 2011 13:20:40 -0400
parents 55db12e54450
children 95a8c0f5dd3f
files hgext/color.py
diffstat 1 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/color.py	Wed Jun 29 13:20:39 2011 -0400
+++ b/hgext/color.py	Wed Jun 29 13:20:40 2011 -0400
@@ -75,6 +75,14 @@
 Some may not be available for a given terminal type, and will be
 silently ignored.
 
+Note that on some systems, terminfo mode may cause problems when using
+color with the pager extension and less -R. less with the -R option
+will only display ECMA-48 color codes, and terminfo mode may sometimes
+emit codes that less doesn't understand. You can work around this by
+either using ansi mode (or auto mode), or by using less -r (which will
+pass through all terminal control codes, not just color control
+codes).
+
 Because there are only eight standard colors, this module allows you
 to define color names for other color slots which might be available
 for your terminal type, assuming terminfo mode.  For instance::
@@ -89,15 +97,15 @@
 defined colors may then be used as any of the pre-defined eight,
 including appending '_background' to set the background to that color.
 
-The color extension will try to detect whether to use terminfo, ANSI
-codes or Win32 console APIs, unless it is made explicit; e.g.::
+By default, the color extension will use ANSI mode (or win32 mode on
+Windows) if it detects a terminal. To override auto mode (to enable
+terminfo mode, for example), set the following configuration option::
 
   [color]
-  mode = ansi
+  mode = terminfo
 
 Any value other than 'ansi', 'win32', 'terminfo', or 'auto' will
 disable color.
-
 '''
 
 import os
@@ -168,10 +176,8 @@
         if os.name == 'nt' and 'TERM' not in os.environ:
             # looks line a cmd.exe console, use win32 API or nothing
             realmode = 'win32'
-        elif not formatted:
+        else:
             realmode = 'ansi'
-        else:
-            realmode = 'terminfo'
 
     if realmode == 'win32':
         if not w32effects: