Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/ui.py @ 31629:c60091fa1426
pager: improve support for various flavors of `more` on Windows
Hardcoding 'more' -> 'more.com' means that 'more.exe' from MSYS would need to be
configured with its *.exe extension. This will resolve to either one, as
cmd.exe would have done if the command ran through the shell.
Something that's maybe problematic with this is it comes after 'pageractive' and
various ui configs have been set by the calling method. But the other early
exits in this method don't undo those changes either.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Fri, 24 Mar 2017 22:40:08 -0400 |
parents | c5d924e5dfdb |
children | 0f8ba0bc1154 |
comparison
equal
deleted
inserted
replaced
31628:a01e1132f6fa | 31629:c60091fa1426 |
---|---|
844 envpager = encoding.environ.get('PAGER', 'more') | 844 envpager = encoding.environ.get('PAGER', 'more') |
845 pagercmd = self.config('pager', 'pager', envpager) | 845 pagercmd = self.config('pager', 'pager', envpager) |
846 if not pagercmd: | 846 if not pagercmd: |
847 return | 847 return |
848 | 848 |
849 if pycompat.osname == 'nt': | |
850 # `more` cannot be invoked with shell=False, but `more.com` can. | |
851 # Hide this implementation detail from the user, so we can also get | |
852 # sane bad PAGER behavior. If args are also given, the space in the | |
853 # command line forces shell=True, so that case doesn't need to be | |
854 # handled here. | |
855 if pagercmd == 'more': | |
856 pagercmd = 'more.com' | |
857 | |
858 self.debug('starting pager for command %r\n' % command) | 849 self.debug('starting pager for command %r\n' % command) |
859 self.flush() | 850 self.flush() |
860 self.pageractive = True | 851 self.pageractive = True |
861 # Preserve the formatted-ness of the UI. This is important | 852 # Preserve the formatted-ness of the UI. This is important |
862 # because we mess with stdout, which might confuse | 853 # because we mess with stdout, which might confuse |
879 # If the command doesn't contain any of these characters, we | 870 # If the command doesn't contain any of these characters, we |
880 # assume it's a binary and exec it directly. This means for | 871 # assume it's a binary and exec it directly. This means for |
881 # simple pager command configurations, we can degrade | 872 # simple pager command configurations, we can degrade |
882 # gracefully and tell the user about their broken pager. | 873 # gracefully and tell the user about their broken pager. |
883 shell = any(c in command for c in "|&;<>()$`\\\"' \t\n*?[#~=%") | 874 shell = any(c in command for c in "|&;<>()$`\\\"' \t\n*?[#~=%") |
875 | |
876 if pycompat.osname == 'nt' and not shell: | |
877 # Window's built-in `more` cannot be invoked with shell=False, but | |
878 # its `more.com` can. Hide this implementation detail from the | |
879 # user so we can also get sane bad PAGER behavior. MSYS has | |
880 # `more.exe`, so do a cmd.exe style resolution of the executable to | |
881 # determine which one to use. | |
882 fullcmd = util.findexe(command) | |
883 if not fullcmd: | |
884 self.warn(_("missing pager command '%s', skipping pager\n") | |
885 % command) | |
886 return | |
887 | |
888 command = fullcmd | |
889 | |
884 try: | 890 try: |
885 pager = subprocess.Popen( | 891 pager = subprocess.Popen( |
886 command, shell=shell, bufsize=-1, | 892 command, shell=shell, bufsize=-1, |
887 close_fds=util.closefds, stdin=subprocess.PIPE, | 893 close_fds=util.closefds, stdin=subprocess.PIPE, |
888 stdout=util.stdout, stderr=util.stderr) | 894 stdout=util.stdout, stderr=util.stderr) |