Show More
@@ -190,8 +190,8 b' def _newchgui(srcui, csystem, attachio):' | |||
|
190 | 190 | self.flush() |
|
191 | 191 | return self._csystem(cmd, util.shellenviron(environ), cwd) |
|
192 | 192 | |
|
193 | def _runpager(self, cmd): | |
|
194 | self._csystem(cmd, util.shellenviron(), type='pager', | |
|
193 | def _runpager(self, cmd, env=None): | |
|
194 | self._csystem(cmd, util.shellenviron(env), type='pager', | |
|
195 | 195 | cmdtable={'attachio': attachio}) |
|
196 | 196 | return True |
|
197 | 197 |
@@ -90,3 +90,9 b' def rccomponents():' | |||
|
90 | 90 | _rccomponents.append(envrc) |
|
91 | 91 | _rccomponents.extend(normpaths(userrcpath())) |
|
92 | 92 | return _rccomponents |
|
93 | ||
|
94 | def defaultpagerenv(): | |
|
95 | '''return a dict of default environment variables and their values, | |
|
96 | intended to be set before starting a pager. | |
|
97 | ''' | |
|
98 | return {'LESS': 'FRX', 'LV': '-c'} |
@@ -854,13 +854,18 b' class ui(object):' | |||
|
854 | 854 | if not pagercmd: |
|
855 | 855 | return |
|
856 | 856 | |
|
857 | pagerenv = {} | |
|
858 | for name, value in rcutil.defaultpagerenv().items(): | |
|
859 | if name not in encoding.environ: | |
|
860 | pagerenv[name] = value | |
|
861 | ||
|
857 | 862 | self.debug('starting pager for command %r\n' % command) |
|
858 | 863 | self.flush() |
|
859 | 864 | |
|
860 | 865 | wasformatted = self.formatted() |
|
861 | 866 | if util.safehasattr(signal, "SIGPIPE"): |
|
862 | 867 | signal.signal(signal.SIGPIPE, _catchterm) |
|
863 | if self._runpager(pagercmd): | |
|
868 | if self._runpager(pagercmd, pagerenv): | |
|
864 | 869 | self.pageractive = True |
|
865 | 870 | # Preserve the formatted-ness of the UI. This is important |
|
866 | 871 | # because we mess with stdout, which might confuse |
@@ -879,7 +884,7 b' class ui(object):' | |||
|
879 | 884 | # warning about a missing pager command. |
|
880 | 885 | self.disablepager() |
|
881 | 886 | |
|
882 | def _runpager(self, command): | |
|
887 | def _runpager(self, command, env=None): | |
|
883 | 888 | """Actually start the pager and set up file descriptors. |
|
884 | 889 | |
|
885 | 890 | This is separate in part so that extensions (like chg) can |
@@ -912,7 +917,8 b' class ui(object):' | |||
|
912 | 917 | pager = subprocess.Popen( |
|
913 | 918 | command, shell=shell, bufsize=-1, |
|
914 | 919 | close_fds=util.closefds, stdin=subprocess.PIPE, |
|
915 |
stdout=util.stdout, stderr=util.stderr |
|
|
920 | stdout=util.stdout, stderr=util.stderr, | |
|
921 | env=util.shellenviron(env)) | |
|
916 | 922 | except OSError as e: |
|
917 | 923 | if e.errno == errno.ENOENT and not shell: |
|
918 | 924 | self.warn(_("missing pager command '%s', skipping pager\n") |
@@ -254,3 +254,29 b' Put annotate in the ignore list for page' | |||
|
254 | 254 | 8: a 8 |
|
255 | 255 | 9: a 9 |
|
256 | 256 | 10: a 10 |
|
257 | ||
|
258 | Environment variables like LESS and LV are set automatically: | |
|
259 | $ cat > $TESTTMP/printlesslv.py <<EOF | |
|
260 | > import os, sys | |
|
261 | > sys.stdin.read() | |
|
262 | > for name in ['LESS', 'LV']: | |
|
263 | > sys.stdout.write(('%s=%s\n') % (name, os.environ.get(name, '-'))) | |
|
264 | > sys.stdout.flush() | |
|
265 | > EOF | |
|
266 | ||
|
267 | $ cat >> $HGRCPATH <<EOF | |
|
268 | > [alias] | |
|
269 | > noop = log -r 0 -T '' | |
|
270 | > [ui] | |
|
271 | > formatted=1 | |
|
272 | > [pager] | |
|
273 | > pager = $PYTHON $TESTTMP/printlesslv.py | |
|
274 | > EOF | |
|
275 | $ unset LESS | |
|
276 | $ unset LV | |
|
277 | $ hg noop --pager=on | |
|
278 | LESS=FRX | |
|
279 | LV=-c | |
|
280 | $ LESS=EFGH hg noop --pager=on | |
|
281 | LESS=EFGH | |
|
282 | LV=-c |
General Comments 0
You need to be logged in to leave comments.
Login now