Mercurial > hg
changeset 24068:4e02418b4236
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.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 04 Feb 2015 14:11:45 -0800 |
parents | 0baf41e02a4d |
children | c6666395fdd2 |
files | hgext/color.py |
diffstat | 1 files changed, 16 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/color.py Fri Feb 06 12:09:09 2015 -0800 +++ b/hgext/color.py Wed Feb 04 14:11:45 2015 -0800 @@ -140,6 +140,17 @@ 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 @@ -213,6 +224,11 @@ 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':