Sunday, 16 May 2010
Tested with Mercurial 1.5.3, 1.5.4 and 1.6 on:
- Windows XP Professional
- Windows Server 2008 SP2 x86
- Windows Server 2008 R2
Unfortunately, the pager extension is a little broken on Windows, as described in issue 1677 on Mercurial issue tracker, so I have modified it to use a temporary file for storing the commands output, and then call the pager with the temporary file as a command line parameter. You can find the source code on Bitbucket and CodePlex.
My favorite pager on Windows is less.exe, which works just fine with the ANSI codes generated from the Mercurial color extension:
You can also use less.exe distributed with msysGit, but thanks to Jeremy Skinner I have noticed an unexpected behaviour of the color extension on Windows, that outputs an ANSI escape sequence between CR and LF, causing the pager to show the CR characters on screen as ^M:
ESC[0m ESC[0;1;41m CR ESC[0m LF
One workaround would be to use the r option instead of R, causing all control characters to be displayed, not just the ANSI color escape sequences.
However the solution proposed by Jeremy - to strip the CR characters from all lines - it’s working just fine with both pager versions, and I have patched the pager extension accordingly.
In Mercurial 1.6+, the color extension must be set to use ANSI mode:
[color] mode = ansi
Also, due to some internal changes, the output of the commands must be read using a different syntax, that will lead to crashes on previous versions, so in Mercurial 1.6+ the hg16mode option must be set to yes:
[pager] hg16mode = yes
Since I have no previous experience with Python and Mercurial, please treat it as an experimental extension. Your feedback is welcome.
.hgrc sample for Mercurial 1.6+ (please update the paths for your system):
[extensions] hgext.color = ; Mercurial pager extension should be disabled ;hgext.pager = ; ~ is the %HOME% folder tpager = ~/tpager.py [color] mode = ansi [pager] attend = annotate, cat, diff, export, glog, help, log, qdiff, status, tip hg16mode = yes ; full path to the executable pager = D:\Tools\Less\less.exe -FSRX