[RFC MERGE] Pipe long winded commands through a pager

Martin Pool mbp at sourcefrog.net
Fri Jan 6 06:08:24 GMT 2006


On Fri, 2005-12-16 at 01:09 -0600, Michael Ellerman wrote:
> Heyho,
> 
> Martin suggested rather than using less(diff|log|status..) plugins, we could 
> send all long winded commands through a pager.
> 
> I've done a hack job implementation so people can get a feel for it and decide 
> if they like it, check it out:
> 
> http://michael.ellerman.id.au/files/bzr/pager

Attached is the diff to merge into head.

I like the feature concept but would like to see if we can fix some of
these issues.  	

> Things that work:
>  - if stdout is not a tty we don't use the pager
>  - we use PAGER and PAGER_ARGUMENTS so people can customise.
>  - we fallback to cat if we can't find a pager
>  - doesn't break lessdiff (I like the colours :)
> 
> Stuff that needs fixing:
>  - No way to enable/disable it completely.
>  - when there's no pager we still have to run cat which is ineffcient, I can't 
>    think of a way around this though.

There are ways to do it.  One thing that might work is to select for
write on the new pipe.  (Not sure if this will work.)  Another is to
pause for a short time to see if the child process exits.  A more
complex but robust approach is to open two pipes, mark one of them
close-on-exec, then try to exec the child process.  If the exec fails,
the child can write back some kind of indicator. 

However, if we only do this when $PAGER is set and if the user has the
option to turn the behaviour off then the complexity is probably not
needed.

>  - still uses my pipes code, I couldn't get it working right with subprocess.

+def pager(func, *args, **kwargs):
+    # Only page if we have a tty on stdout
+    if hasattr(sys.stdin, 'isatty') and sys.stdout.isatty():
+        pipe = Pipe()

I presume that "stdin" should be "stdout"?

It would be much nicer to use subprocess rather than forking ourselves,
and that might give more hope of working on Windows, if that's possible.
What went wrong?

Needing to run things through cat is a bit ugly.  I can imagine some
workarounds to detect whether the pager can be run or not but it's
probably not worth worrying about for the moment.

I'd like to add a user configuration setting that says whether to have
an automatic pager or not.

Thanks.
-- 
Martin

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pager.diff
Type: text/x-patch
Size: 6390 bytes
Desc: 
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060106/225de8a5/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060106/225de8a5/attachment.pgp 


More information about the bazaar mailing list