hgext/pager.py
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
Sat, 06 Sep 2008 12:49:20 +0200
changeset 6996 fecf060f32a1
parent 6456 db5324d3c257
child 6457 7ef281e78c64
permissions -rw-r--r--
inotify: deactivate inotify status on failure workaround issue1208, add test fix traceback handling (socket.error is a singleton in this case)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
     1
# pager.py - display output using a pager
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
     2
#
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
     3
# Copyright 2008 David Soria Parra <dsp@php.net>
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
     4
#
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
     6
# of the GNU General Public License, incorporated herein by reference.
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
     7
#
6324
ee1077b41d5c pager: further simplify code, clean up comments
Matt Mackall <mpm@selenic.com>
parents: 6323
diff changeset
     8
# To load the extension, add it to your .hgrc file:
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
     9
#
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    10
#   [extension]
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    11
#   hgext.pager =
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    12
#
6324
ee1077b41d5c pager: further simplify code, clean up comments
Matt Mackall <mpm@selenic.com>
parents: 6323
diff changeset
    13
# To set the pager that should be used, set the application variable:
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    14
#
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    15
#   [pager]
6324
ee1077b41d5c pager: further simplify code, clean up comments
Matt Mackall <mpm@selenic.com>
parents: 6323
diff changeset
    16
#   pager = LESS='FSRX' less
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    17
#
6324
ee1077b41d5c pager: further simplify code, clean up comments
Matt Mackall <mpm@selenic.com>
parents: 6323
diff changeset
    18
# If no pager is set, the pager extensions uses the environment
ee1077b41d5c pager: further simplify code, clean up comments
Matt Mackall <mpm@selenic.com>
parents: 6323
diff changeset
    19
# variable $PAGER. If neither pager.pager, nor $PAGER is set, no pager
ee1077b41d5c pager: further simplify code, clean up comments
Matt Mackall <mpm@selenic.com>
parents: 6323
diff changeset
    20
# is used.
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    21
#
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    22
# If you notice "BROKEN PIPE" error messages, you can disable them
6324
ee1077b41d5c pager: further simplify code, clean up comments
Matt Mackall <mpm@selenic.com>
parents: 6323
diff changeset
    23
# by setting:
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    24
#
6324
ee1077b41d5c pager: further simplify code, clean up comments
Matt Mackall <mpm@selenic.com>
parents: 6323
diff changeset
    25
#   [pager]
ee1077b41d5c pager: further simplify code, clean up comments
Matt Mackall <mpm@selenic.com>
parents: 6323
diff changeset
    26
#   quiet = True
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    27
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    28
import sys, os, signal
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    29
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    30
def uisetup(ui):
6324
ee1077b41d5c pager: further simplify code, clean up comments
Matt Mackall <mpm@selenic.com>
parents: 6323
diff changeset
    31
    p = ui.config("pager", "pager", os.environ.get("PAGER"))
6456
db5324d3c257 Pager extension: switch it off if --debugger is set
Gilles Moris <gilles.moris@free.fr>
parents: 6455
diff changeset
    32
    if p and sys.stdout.isatty() and '--debugger' not in sys.argv:
6324
ee1077b41d5c pager: further simplify code, clean up comments
Matt Mackall <mpm@selenic.com>
parents: 6323
diff changeset
    33
        if ui.configbool('pager', 'quiet'):
ee1077b41d5c pager: further simplify code, clean up comments
Matt Mackall <mpm@selenic.com>
parents: 6323
diff changeset
    34
            signal.signal(signal.SIGPIPE, signal.SIG_DFL)
ee1077b41d5c pager: further simplify code, clean up comments
Matt Mackall <mpm@selenic.com>
parents: 6323
diff changeset
    35
        sys.stderr = sys.stdout = os.popen(p, "wb")