| 1 |
# pager.py - display output using a pager |
| 2 |
# |
| 3 |
# Copyright 2008 David Soria Parra <[email protected]> |
| 4 |
# |
| 5 |
# This software may be used and distributed according to the terms of the |
| 6 |
# GNU General Public License version 2 or any later version. |
| 7 |
# |
| 8 |
# To load the extension, add it to your configuration file: |
| 9 |
# |
| 10 |
# [extension] |
| 11 |
# pager = |
| 12 |
# |
| 13 |
# Run 'hg help pager' to get info on configuration. |
| 14 |
|
| 15 |
'''browse command output with an external pager (DEPRECATED) |
| 16 |
|
| 17 |
Forcibly enable paging for individual commands that don't typically |
| 18 |
request pagination with the attend-<command> option. This setting |
| 19 |
takes precedence over ignore options and defaults:: |
| 20 |
|
| 21 |
[pager] |
| 22 |
attend-cat = false |
| 23 |
''' |
| 24 |
|
| 25 |
from __future__ import annotations |
| 26 |
|
| 27 |
from mercurial import ( |
| 28 |
commands, |
| 29 |
dispatch, |
| 30 |
extensions, |
| 31 |
registrar, |
| 32 |
) |
| 33 |
from mercurial.main_script import cmd_finder |
| 34 |
|
| 35 |
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
| 36 |
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
| 37 |
# be specifying the version(s) of Mercurial they are tested with, or |
| 38 |
# leave the attribute unspecified. |
| 39 |
testedwith = b'ships-with-hg-core' |
| 40 |
|
| 41 |
configtable = {} |
| 42 |
configitem = registrar.configitem(configtable) |
| 43 |
|
| 44 |
configitem( |
| 45 |
b'pager', |
| 46 |
b'attend', |
| 47 |
default=lambda: attended, |
| 48 |
) |
| 49 |
|
| 50 |
|
| 51 |
def uisetup(ui): |
| 52 |
def pagecmd(orig, ui, options, cmd, cmdfunc): |
| 53 |
auto = options[b'pager'] == b'auto' |
| 54 |
if auto and not ui.pageractive: |
| 55 |
usepager = False |
| 56 |
attend = ui.configlist(b'pager', b'attend') |
| 57 |
ignore = ui.configlist(b'pager', b'ignore') |
| 58 |
cmds, _ = cmd_finder.find_cmd(cmd, commands.table) |
| 59 |
|
| 60 |
for cmd in cmds: |
| 61 |
var = b'attend-%s' % cmd |
| 62 |
if ui.config(b'pager', var, None): |
| 63 |
usepager = ui.configbool(b'pager', var, True) |
| 64 |
break |
| 65 |
if cmd in attend or (cmd not in ignore and not attend): |
| 66 |
usepager = True |
| 67 |
break |
| 68 |
|
| 69 |
if usepager: |
| 70 |
# Slight hack: the attend list is supposed to override |
| 71 |
# the ignore list for the pager extension, but the |
| 72 |
# core code doesn't know about attend, so we have to |
| 73 |
# lobotomize the ignore list so that the extension's |
| 74 |
# behavior is preserved. |
| 75 |
ui.setconfig(b'pager', b'ignore', b'', b'pager') |
| 76 |
ui.pager(b'extension-via-attend-' + cmd) |
| 77 |
else: |
| 78 |
ui.disablepager() |
| 79 |
return orig(ui, options, cmd, cmdfunc) |
| 80 |
|
| 81 |
extensions.wrapfunction(dispatch, '_runcommand', pagecmd) |
| 82 |
|
| 83 |
|
| 84 |
attended = [b'annotate', b'cat', b'diff', b'export', b'glog', b'log', b'qdiff'] |