Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/dispatch.py @ 32125:f928d53b687c stable
dispatch: setup color before pager for correct console information on windows
Before this patch, "hg CMD --pager on" on Windows shows output
unintentionally decorated with ANSI color escape sequences, if color
mode is "auto". This issue occurs in steps below.
1. dispatch() invokes ui.pager() at detection of "--pager on"
2. stdout of hg process is redirected into stdin of pager process
3. "ui.formatted" = True, because isatty(stdout) is so before (2)
4. color module is loaded for colorization
5. color.w32effects = None, because GetConsoleScreenBufferInfo()
fails on stdout redirected at (2)
6. "ansi" color mode is chosen, because of "not w32effects"
7. output is colorized in "ansi" mode because of "ui.formatted" = True
Even if "ansi" color mode is chosen, ordinarily redirected stdout
makes ui.formatted() return False, and colorization is avoided. But in
this issue case, "ui.formatted" = True at (3) forces output to be
colorized.
For correct console information on win32, it is needed to ensure that
color module is loaded before redirection of stdout for pagination.
BTW, if any of enabled extensions has "colortable" attribute, this
issue is avoided even before this patch, because color module is
imported as a part of loading such extension, and extension loading
occurs before setting up pager. For example, mq and keyword have
"colortable".
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Tue, 23 May 2017 03:29:23 +0900 |
parents | 616e788321cc |
children | 9929af2b09b4 |
comparison
equal
deleted
inserted
replaced
32124:99515353c72a | 32125:f928d53b687c |
---|---|
831 | 831 |
832 if options['noninteractive']: | 832 if options['noninteractive']: |
833 for ui_ in uis: | 833 for ui_ in uis: |
834 ui_.setconfig('ui', 'interactive', 'off', '-y') | 834 ui_.setconfig('ui', 'interactive', 'off', '-y') |
835 | 835 |
836 if util.parsebool(options['pager']): | |
837 ui.pager('internal-always-' + cmd) | |
838 elif options['pager'] != 'auto': | |
839 ui.disablepager() | |
840 | |
841 if cmdoptions.get('insecure', False): | 836 if cmdoptions.get('insecure', False): |
842 for ui_ in uis: | 837 for ui_ in uis: |
843 ui_.insecureconnections = True | 838 ui_.insecureconnections = True |
844 | 839 |
845 # setup color handling | 840 # setup color handling before pager, because setting up pager |
841 # might cause incorrect console information | |
846 coloropt = options['color'] | 842 coloropt = options['color'] |
847 for ui_ in uis: | 843 for ui_ in uis: |
848 if coloropt: | 844 if coloropt: |
849 ui_.setconfig('ui', 'color', coloropt, '--color') | 845 ui_.setconfig('ui', 'color', coloropt, '--color') |
850 color.setup(ui_) | 846 color.setup(ui_) |
847 | |
848 if util.parsebool(options['pager']): | |
849 ui.pager('internal-always-' + cmd) | |
850 elif options['pager'] != 'auto': | |
851 ui.disablepager() | |
851 | 852 |
852 if options['version']: | 853 if options['version']: |
853 return commands.version_(ui) | 854 return commands.version_(ui) |
854 if options['help']: | 855 if options['help']: |
855 return commands.help_(ui, cmd, command=cmd is not None) | 856 return commands.help_(ui, cmd, command=cmd is not None) |