2008-03-20 02:57:14 +03:00
|
|
|
# pager.py - display output using a pager
|
|
|
|
#
|
|
|
|
# Copyright 2008 David Soria Parra <dsp@php.net>
|
|
|
|
#
|
2009-04-26 03:08:54 +04:00
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2008-03-20 02:57:14 +03:00
|
|
|
#
|
2010-08-28 06:36:35 +04:00
|
|
|
# To load the extension, add it to your configuration file:
|
2008-03-20 02:57:14 +03:00
|
|
|
#
|
|
|
|
# [extension]
|
2009-12-22 02:50:03 +03:00
|
|
|
# pager =
|
2008-03-20 02:57:14 +03:00
|
|
|
#
|
2016-09-21 02:44:49 +03:00
|
|
|
# Run 'hg help pager' to get info on configuration.
|
2008-04-03 15:47:05 +04:00
|
|
|
|
2017-02-07 08:07:53 +03:00
|
|
|
'''browse command output with an external pager (DEPRECATED)
|
2008-04-03 15:47:05 +04:00
|
|
|
|
2017-02-07 08:07:53 +03:00
|
|
|
Forcibly enable paging for individual commands that don't typically
|
|
|
|
request pagination with the attend-<command> option. This setting
|
|
|
|
takes precedence over ignore options and defaults::
|
2014-05-09 22:32:56 +04:00
|
|
|
|
|
|
|
[pager]
|
|
|
|
attend-cat = false
|
2008-04-03 15:47:05 +04:00
|
|
|
'''
|
2016-02-29 06:15:00 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
from mercurial import (
|
|
|
|
cmdutil,
|
|
|
|
commands,
|
|
|
|
dispatch,
|
|
|
|
extensions,
|
|
|
|
)
|
2008-03-20 02:57:14 +03:00
|
|
|
|
2016-08-23 18:26:08 +03:00
|
|
|
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
|
2015-04-28 23:44:37 +03:00
|
|
|
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
|
|
|
|
# be specifying the version(s) of Mercurial they are tested with, or
|
|
|
|
# leave the attribute unspecified.
|
2016-08-23 18:26:08 +03:00
|
|
|
testedwith = 'ships-with-hg-core'
|
2012-05-15 23:37:49 +04:00
|
|
|
|
2008-03-20 02:57:14 +03:00
|
|
|
def uisetup(ui):
|
2016-12-26 03:25:44 +03:00
|
|
|
|
2008-10-23 02:34:52 +04:00
|
|
|
def pagecmd(orig, ui, options, cmd, cmdfunc):
|
2014-05-09 22:07:50 +04:00
|
|
|
auto = options['pager'] == 'auto'
|
2017-02-16 01:47:57 +03:00
|
|
|
if auto and not ui.pageractive:
|
2014-05-09 22:07:50 +04:00
|
|
|
usepager = False
|
2009-11-12 18:29:40 +03:00
|
|
|
attend = ui.configlist('pager', 'attend', attended)
|
2014-05-09 22:10:23 +04:00
|
|
|
ignore = ui.configlist('pager', 'ignore')
|
2013-10-13 05:51:34 +04:00
|
|
|
cmds, _ = cmdutil.findcmd(cmd, commands.table)
|
|
|
|
|
|
|
|
for cmd in cmds:
|
2014-05-09 22:32:56 +04:00
|
|
|
var = 'attend-%s' % cmd
|
|
|
|
if ui.config('pager', var):
|
|
|
|
usepager = ui.configbool('pager', var)
|
|
|
|
break
|
2014-05-09 22:07:50 +04:00
|
|
|
if (cmd in attend or
|
|
|
|
(cmd not in ignore and not attend)):
|
2014-05-09 21:58:53 +04:00
|
|
|
usepager = True
|
2013-10-13 05:51:34 +04:00
|
|
|
break
|
2014-05-09 21:58:53 +04:00
|
|
|
|
2017-02-16 01:47:57 +03:00
|
|
|
if usepager:
|
2017-02-07 07:21:45 +03:00
|
|
|
# Slight hack: the attend list is supposed to override
|
|
|
|
# the ignore list for the pager extension, but the
|
|
|
|
# core code doesn't know about attend, so we have to
|
|
|
|
# lobotomize the ignore list so that the extension's
|
|
|
|
# behavior is preserved.
|
|
|
|
ui.setconfig('pager', 'ignore', '', 'pager')
|
2017-02-16 01:47:57 +03:00
|
|
|
ui.pager('extension-via-attend-' + cmd)
|
2008-10-23 02:34:52 +04:00
|
|
|
return orig(ui, options, cmd, cmdfunc)
|
2008-03-29 21:41:50 +03:00
|
|
|
|
2015-02-06 23:09:09 +03:00
|
|
|
# Wrap dispatch._runcommand after color is loaded so color can see
|
|
|
|
# ui.pageractive. Otherwise, if we loaded first, color's wrapped
|
|
|
|
# dispatch._runcommand would run without having access to ui.pageractive.
|
|
|
|
def afterloaded(loaded):
|
|
|
|
extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
|
|
|
|
extensions.afterloaded('color', afterloaded)
|
2009-11-12 18:29:40 +03:00
|
|
|
|
2017-02-07 07:57:21 +03:00
|
|
|
attended = [
|
|
|
|
'the-default-attend-list-is-now-empty-but-that-breaks-the-extension',
|
|
|
|
]
|