Patchwork [4,of,4,V2] color: support a different color mode when the pager is active

login
register
mail settings
Submitter Gregory Szorc
Date Feb. 6, 2015, 8:11 p.m.
Message ID <842ebae3497813dec1f6.1423253464@gps-mbp.local>
Download mbox | patch
Permalink /patch/7724/
State Accepted
Commit 4e02418b4236a07049ad5e71836decfa8a8120b6
Headers show

Comments

Gregory Szorc - Feb. 6, 2015, 8:11 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1423087905 28800
#      Wed Feb 04 14:11:45 2015 -0800
# Node ID 842ebae3497813dec1f61a12ed0a24dee151ca95
# Parent  e7fd7d7aabbebd77be388a2c80b2f1daf8534c84
color: support a different color mode when the pager is active

MSYS on Windows has a terminal that supports the "win32" color mode
(which "auto" properly detects for us). However, a popularily configured
pager in that environment (GNU less) only supports the "ansi" color
mode.

This patch teaches color about a new config option: pagermode. It
behaves like "mode" but is only consulted when the pager is active for
the current command. MSYS users can now set "pagermode = ansi" and get a
colorful experience that just works. Previously, MSYS users would have
to live without color when using GNU less as the pager, would have to
manually configure the pager to attend every command, or would have
gibberish if "ansi" was used without the pager.
Matt Mackall - Feb. 6, 2015, 10:51 p.m.
On Fri, 2015-02-06 at 12:11 -0800, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1423087905 28800
> #      Wed Feb 04 14:11:45 2015 -0800
> # Node ID 842ebae3497813dec1f61a12ed0a24dee151ca95
> # Parent  e7fd7d7aabbebd77be388a2c80b2f1daf8534c84
> color: support a different color mode when the pager is active

These are queued for default, thanks.

Patch

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -139,8 +139,19 @@  will only display ECMA-48 color codes, a
 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).
+
+On some systems (such as MSYS in Windows), the terminal may support
+a different color mode than the pager (activated via the "pager"
+extension). It is possible to define separate modes depending on whether
+the pager is active::
+
+  [color]
+  mode = auto
+  pagermode = ansi
+
+If ``pagermode`` is not defined, the ``mode`` will be used.
 '''
 
 import os
 
@@ -212,8 +223,13 @@  def _modesetup(ui, coloropt):
 
     formatted = always or (os.environ.get('TERM') != 'dumb' and ui.formatted())
 
     mode = ui.config('color', 'mode', 'auto')
+
+    # If pager is active, color.pagermode overrides color.mode.
+    if getattr(ui, 'pageractive', False):
+        mode = ui.config('color', 'pagermode', mode)
+
     realmode = mode
     if mode == 'auto':
         if os.name == 'nt':
             term = os.environ.get('TERM')