Commit Graph

59 Commits

Author SHA1 Message Date
Jun Wu
cbbb576b1c pager: skip uisetup if chg is detected
chg has its own pager implementation that it wants to skip pager's uisetup.
It is currently done by redirecting stdout to /dev/null, which has unintended
side effects. This patch makes pager aware of chg and skip uisetup directly
from pager. We may want to merge chg and pager's pager implementation to
make this unnecessary in the future.
2016-03-14 15:03:19 +00:00
Augie Fackler
e5e6b47d65 pager: use absolute_import 2016-02-28 22:15:00 -05:00
timeless
e4b7c3bfda pager: improve help for --pager=
try to clarify how to enable/disable the pager
2015-11-30 18:47:33 +00:00
Yuya Nishihara
1f3d02756b pager: recreate stdout to make it line-buffered
We want to see partial command results as soon as possible. But the buffering
mode of stdout (= pager's stdin) was set to fully-buffered because it isn't
associated with a tty. So, this patch recreates new stdout object to force its
buffering mode.

Because two file objects are associated with the same stdout fd and their
destructors will call close(), one of them must be closed carefully. Python
expects that the stdout fd never be closed even after sys.stdout.close() [1],
but newstdout has no such hack. So this patch calls newstdout.close()
immediately before duplicating the original stdout fd to sys.stdout.

  operation              sys.stdout  newstdout  fd
  ---------------------  ----------  ---------  --------
  newstdout.close()      open        closed     closed
  os.dup2(stdoutfd, ..)  open        closed     open
  del sys.stdout         closed      closed     open [1]

 [1]: https://hg.python.org/cpython/file/v2.7.10/Python/sysmodule.c#l1391
2015-10-03 15:16:33 +09:00
Yuya Nishihara
20505cecd5 pager: rename variables of backup fds
The next patch will add backup file objects, so the original variable names
would be confusing.
2015-10-03 18:48:21 +09:00
Yuya Nishihara
cadf85db0f pager: inline _pagersubprocess() into _runpager()
We don't need _pagersubprocess() because the fork version was removed
at 783efe565d9e.
2015-10-03 15:02:52 +09:00
Pierre-Yves David
54067fb1c4 pager: drop python 2.4 hack around subprocess
Farewell, we do not need you anymore.
2015-05-18 16:20:12 -05:00
Augie Fackler
f95a6caba1 extensions: document that testedwith = 'internal' is special
Extension authors (notably at companies using hg) have been
cargo-culting the `testedwith = 'internal'` bit from hg's own
extensions, which then defeats our "file bugs over here" logic in
dispatch. Let's be more aggressive about trying to give extension
authors a hint about what testedwith should say.
2015-04-28 16:44:37 -04:00
Gregory Szorc
b1321c4998 pager: ensure wrapped dispatch._runcommand runs before color's
An upcoming patch will teach color to potentially act differently if the
pager is active. Since both extensions wrap the same function
(dispatch._runcommand) to change behavior, we must guarantee that
pager's wrapped function runs before color's so color may read the
breadcrumb left by pager.
2015-02-06 12:09:09 -08:00
Gregory Szorc
df5acb8a96 pager: set an attribute on ui indicating that a pager is active
A subsequent patch will teach the color extension to do different things
depending on whether a pager is active. This patch leaves a breadcrumb
on the ui instance to allow it do that that.
2015-02-06 12:07:56 -08:00
Matt Mackall
8f271ab8db pager: add attend-<command> option
This lets users override attend settings locally on a command
granularity.
2014-05-09 13:32:56 -05:00
Matt Mackall
9f887e4452 pager: variable reorder 2014-05-09 13:10:23 -05:00
Matt Mackall
5c5576136a pager: break auto out of command check loop 2014-05-09 13:07:50 -05:00
Matt Mackall
e855b86a3a pager: break always out of command check loop 2014-05-09 13:05:52 -05:00
Matt Mackall
911703535d pager: break pager invocation out of command check loop 2014-05-09 12:58:53 -05:00
Mads Kiilerich
2629efac4f config: set a 'source' in most cases where config don't come from file but code
Some extensions set configuration settings that showed up in 'hg showconfig
--debug' with 'none' as source. That was confusing.

Instead, they will now tell which extension they come from.

This change tries to be consistent and specify a source everywhere - also where
it perhaps is less relevant.
2014-03-19 02:45:14 +01:00
David Soria Parra
d4d544f551 pager: honour internal aliases
If paging is configured for a command all it's internal defined aliases
will be paged as well. This will make attend=log cause 'hg history'
to run the pager. However custom aliases will not be paged by default.
2013-10-12 18:51:34 -07:00
Bryan O'Sullivan
4a4e45180d pager: add missing imports of errno and shlex
Found using Cython.
2013-04-12 17:35:56 -07:00
Matt Mackall
fb3c5e53c4 pager: catch ctrl-c on exit (issue3834) 2013-02-22 15:17:33 -06:00
Thomas Arendsen Hein
ef236f0ec1 pager: drop -S option for less in example for pager configuration
Using less -S will hide possibly important information when reviewing a
changeset, e.g. something wrong/dangerous after the 80th column, because
"less" will not give an indication that following characters are hidden.
2012-07-31 15:50:44 +02:00
Michael Bacarella
497a8d346f pager: work around bug in python 2.4's subprocess module (issue3533)
hg v2.2.2 fixed the pager on Windows, but broke it on Python 2.4.
This patch only uses the new behavior if Python >= 2.5 is detected.
2012-07-06 18:06:52 -04:00
Matt Mackall
99486917d1 pager: use ui._isatty infrastructure 2012-05-20 14:33:49 -05:00
Augie Fackler
96d44b39f7 hgext: mark all first-party extensions as such 2012-05-15 14:37:49 -05:00
David Soria Parra
7bbe0ff197 pager: check if signal.SIGPIPE exists
We have to check for signal.SIGPIPE before we attempt
to set it.
2012-05-12 09:43:12 +02:00
David Soria Parra
d6e40e51fb pager: remove quiet flag
With the pager running as a child process, exiting the pager doesn't
result in a broken pipe message. To distinguish the exit broken pipe code
from a mercurial abort we register the default action for SIGPIPE. This
results in a 141 exit code instead of a 255. On windows SIGPIPE doesn't
exists and a ValueError will be thrown.
2012-05-11 16:08:49 +02:00
Brodie Rao
6fdaf7d897 pager: preserve Hg's exit code (and fix Windows support) (issue3225)
This changes how the pager extension invokes the pager. Prior to this change,
the extension would fork Hg and exec the pager in the parent process. This
loses Hg exit code, and it doesn't work on Windows.

Now the pager is invoked using the subprocess library, and an atexit handler is
registered that makes Hg wait for the pager to exit before it exits itself.

Note that if you exit the pager before Hg is done running, you'll get an exit
code of 255, which is caused by Python blowing up due to a broken pipe. If you
set pager.quiet=True, you'll get the OS-level return code of 141.
2012-05-11 15:45:37 +02:00
Augie Fackler
3fddb45056 hgext: replace uses of hasattr with util.safehasattr 2011-07-25 20:37:12 -05:00
Idan Kamara
02f21a70dc util: add helper function isatty(fd) to check for tty-ness 2011-06-02 00:43:34 +03:00
Brodie Rao
2fb8bf1f24 pager: don't page stderr if it's being redirected (issue2541) 2011-01-04 00:24:34 +11:00
Kevin Bullock
deaad9124d pager: make example of setting pager less silly 2010-10-29 00:57:34 -05:00
Martin Geisler
94a99c16c9 pager: backout 211c3a983bd3 (issue2441) 2010-10-29 14:47:45 +02:00
Brodie Rao
64fa99143f pager: don't run pager if nothing is written to stdout/stderr
This decides when to run the pager based on the first call to
ui.write() and ui.write_err(). This has the side effect of not the
output of subprocesses that write output before hg does.
2010-10-10 12:21:49 -05:00
Brodie Rao
6b1702dd44 pager: add global --pager=<auto/boolean> option 2010-10-10 12:21:48 -05:00
Brodie Rao
5a1e1994ac help: refer to user configuration file more consistently
Currently, a number of commands and help topics mention the user hgrc
file in different ways. Among these are following:

1. .hgrc - "please specify your commit editor/username in your .hgrc
file", bookmarks, color, hgk, pager, hg help environment

2. $HOME/.hgrc - hg help paths, hgrc(5), hg(1)

3. ~/.hgrc - hgrc(5)

In addition to being inconsistent, none of these make sense on
Windows. This patch replaces the above with a more general term of
"[your] configuration file".
2010-08-27 22:36:35 -04:00
Yuya Nishihara
968bdb2fd0 pager: respect HGPLAIN
Pager shouldn't be enabled for scripting use.
2010-06-20 01:20:12 +09:00
Dan Villiom Podlaski Christiansen
e64c6d6314 pager: set ui.formatted() prior to redirecting stdout. 2010-06-07 15:34:48 +02:00
Brodie Rao
97e764bcba pager: exec pager using /bin/sh -c
This mimics the behavior of popen() and ensures setting the pager to something
like "LESS=FSRX less" will work.
2010-05-19 09:54:12 -05:00
Matt Mackall
0eed4acf96 Merge with stable 2010-05-16 14:38:32 -05:00
Brodie Rao
6239bef137 pager: fork and exec pager as parent process
With the pager as the child process instead of the parent process, the
termination of the parent Mercurial process can cause the terminal to return
before the pager exits. Inverting the relationship prevents that issue.

Platforms without fork() will continue to use util.popen().
2010-05-03 14:00:34 -05:00
Martin Geisler
f1853c5e82 Use hg role in help strings 2010-04-22 10:24:49 +02:00
Brodie Rao
0f2039e2cc pager: set ui.interactive=False when enabled
This stops interactive-only things like progress bars from showing up
inside the pager.
2010-02-19 22:16:42 -05:00
Matt Mackall
595d66f424 Update license to GPLv2+ 2010-01-19 22:20:08 -06:00
Martin Geisler
70de345b15 hgext: enable extensions without "hgext." prefix in help texts 2009-12-22 00:50:03 +01:00
Brodie Rao
4f62e5a654 pager: provide a default attend list
The default list includes commands which normally print large amounts of
text. This should be more user-friendly than paging all commands by default,
which can be confusing when the pager swallows input prompts (with, e.g.,
record, merge, HTTP/SSH authentication, etc.)
2009-11-12 10:29:40 -05:00
Martin Geisler
5cca165d9b pager: wrap docstrings at 70 characters 2009-07-26 01:56:02 +02:00
Martin Geisler
cf2fd9726e pager: use reST syntax for literal blocks 2009-07-23 00:24:03 +02:00
Martin Geisler
42ae308e52 pager: wrapped docstrings at 78 characters 2009-07-07 23:54:42 +02:00
Cédric Duval
dbcec5595d extensions: improve the consistency of synopses
Trying as much as possible to consistently:
 - use a present tense predicate followed by a direct object
 - verb referring directly to the functionality provided
   (ie. not "add command that does this" but simple "do that")
 - keep simple and to the point, leaving details for the long help
   (width is tight, possibly even more so for translations)

Thanks to timeless, Martin Geisler, Rafael Villar Burke, Dan Villiom
Podlaski Christiansen and others for the helpful suggestions.
2009-06-22 15:48:08 +02:00
Martin Geisler
750183bdad updated license to be explicit about GPL version 2 2009-04-26 01:08:54 +02:00
Martin Geisler
1978b6086c pager: word-wrap help texts at 70 characters 2009-04-04 23:18:13 +02:00