[RFC MERGE] Pipe long winded commands through a pager
John Arbash Meinel
john at arbash-meinel.com
Fri Jan 6 13:49:43 GMT 2006
Martin Pool wrote:
> 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.
>
On Windows you most likely do not have 'cat', and you certainly don't
have 'less'. So some care needs to be taken so that nothing is done
unless PAGER exists.
You might have 'more', but it is pretty crappy.
>
>> - 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.
>
Actually, with my encodings work, it would be pretty easy to tie in a
pager. Basically, I'm already giving the commands a custom output pipe
(self.outf). We could just add another level to make it a pipe into a
subprocess, rather than directly to sys.stdout.
I don't think code deeper than the commands.py or builtins.py should
have direct access to sys.stdout anyway, so I don't think we need to
modify it.
I also don't prefer decorator syntax if we can do something like:
class cmd_foo():
pager = True
John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060106/f74f8a44/attachment.pgp
More information about the bazaar
mailing list