[PATCH 2 of 2 stable] color: for the sake of "less -R", default to ansi in auto mode (issue2792)
Brodie Rao
brodie at bitheap.org
Wed Jun 29 12:22:07 CDT 2011
# HG changeset patch
# User Brodie Rao <brodie at bitheap.org>
# Date 1309368040 14400
# Branch stable
# Node ID 934618a0f0815d43f0709eb96ddc8f873e2b48e6
# Parent b1e9906e07f7190b555dd6604d0912136579cd0d
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.
diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -75,6 +75,14 @@ ECMA-48 mode, the options are 'bold', 'i
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 @@ that have brighter colors defined in the
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 @@ def _modesetup(ui, opts):
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:
More information about the Mercurial-devel
mailing list