You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by David Wilson <dw...@botanicus.net> on 2004/09/03 13:46:23 UTC

Piping copious output to PAGER automatically.

Hi there,

First and foremost, congratulations on an excellent product. It is rare
to see an open source project so well built.

In #svn today, I suggested the addition of a feature which provoked a
little discussion, and it was suggested I post it here for
consideration.

Basically, in 99% of cases (and probably closer to 100% with
Subversion) when stdout is connected to a terminal device and we are
sending a large amount of output to stdout, there is a very high chance
that we are going to flood the user's terminal.

My basic idea is to test for something like the following or it's APR
equivalent:

    (isatty(fileno(stdout)) && (pager = getenv("PAGER")) && *pager)


If the condition succeeds, then use popen(3) (or the APR equivalent) to
pipe our copious output to the user's preferred PAGER instead of
directly to their screen.

The condition will fail if output is redirected to a file, for example,
with "svn diff > patch", and will also fail if PAGER is unset or
temporarily set to nothing, as in "PAGER= svn diff".

I first came across this function in Rick Faith's dict.org client
program, and have since found it to be a lovely little feature that has
never guessed wrong.

I feel it is rational behaviour since already the svn client behaves
interactively when it prompts for passwords, and since 99% of the time
when svn is connected to a TTY on stdout, it is being run interactively.

It isn't trying to be too smart as the user is asking all his system
programs to use his PAGER already, by voluntarily exporting the
environment variable in the first place.

The user has the choice of two overrides, namely:

    svn diff|cat
    PAGER= svn diff

Both of which will cause the test to fail.

A more conservative but less portable approach would be to query
TIOCGWINSZ first to check if our output is going to be larger than the
user's TTY can display, although I would personally be against this as I
regularly use my pager's stream saving functionality, which wouldn't be
available for small patches and logs.

Affected commands:

    svn cat
    svn blame
    svn diff
    svn help      (?)
    svn list      (?)
    svn log
    svn status


I am willing to provide a patch for the functionality, which would amount
to about 5 lines of change. It could also be made an optional feature
through ~/.subversion/config.

Thanks for your time,


David.

-- 
"Science is what we understand well enough to explain to a
computer. Art is everything else we do."
    -- Donald Knuth

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Piping copious output to PAGER automatically.

Posted by Marc Haisenko <ha...@webport.de>.
On Friday 03 September 2004 15:46, David Wilson wrote:
> Hi there,
>
> [...]
>
> My basic idea is to test for something like the following or it's APR
> equivalent:
>
>     (isatty(fileno(stdout)) && (pager = getenv("PAGER")) && *pager)
>
> [...]

Very nice idea ! Especially useful in connection with "svn log" ...

-- 
Marc Haisenko
Systemspezialist
Webport IT-Services GmbH
mailto: haisenko@webport.de

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Piping copious output to PAGER automatically.

Posted by Marc Haisenko <ha...@webport.de>.
On Sunday 05 September 2004 19:39, Tobias Ringström wrote:
> Max Bowsher wrote:
> > After being initially shocked by the violation of Unix tradition, I
> > eventually came to think that *if* the user has set PAGER, then they
> > probably would like this feature.
>
> I'm not so sure about that (and I'm still waiting for the shock to wear
> off). I've set PAGER mainly for man, but that does not mean that I'd
> like svn diff to use it by default. It's too much unlike the rest of the
> world, and what about svn cat, ls, log, etc? It's easy enough to type |
> $PAGER, or to write a wrapper script, IMO.
>
> /Tobias, promising to reconcider the day when ls uses PAGER by default

Pipes and redirects would be unaffected as the code would check whether stdout 
is a console or not. And if it is a console the pager would be used. So I 
personally think this really is in the UNIX tradition, and you could as well 
do "PAGER= svn ..." to switch that behaviour off. But I think most users 
would really appreciate such a feature (I know I do :-)
C'ya,
	Marc

-- 
Marc Haisenko
Systemspezialist
Webport IT-Services GmbH
mailto: haisenko@webport.de

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Piping copious output to PAGER automatically.

Posted by Tobias Ringström <to...@ringstrom.mine.nu>.
Max Bowsher wrote:

> After being initially shocked by the violation of Unix tradition, I 
> eventually came to think that *if* the user has set PAGER, then they 
> probably would like this feature.

I'm not so sure about that (and I'm still waiting for the shock to wear 
off). I've set PAGER mainly for man, but that does not mean that I'd 
like svn diff to use it by default. It's too much unlike the rest of the 
world, and what about svn cat, ls, log, etc? It's easy enough to type | 
$PAGER, or to write a wrapper script, IMO.

/Tobias, promising to reconcider the day when ls uses PAGER by default


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Piping copious output to PAGER automatically.

Posted by Greg Hudson <gh...@MIT.EDU>.
On Mon, 2004-09-06 at 03:48, Marc Haisenko wrote:
> > If the value of PAGER is "less", then it's pretty intrusive.  "svn log
> > -r N file" would clear the screen, display one (possibly short) log
> > message at the bottom of the screen, and would wait for user input
> > before returning to the prompt.
> 
> export PAGER=less -F
> 
> This fixes the described problem :-)

You said the behavior was unintrusive.  It is not unintrusive if the
PAGER setting is "less", which is a common configuration.  The fact that
there is a workaround does not make the proposed new Subversion behavior
any less intrusive.

Also, your proposed workaround is itself intrusive, since it may not be
what the user wants for programs like "man" which already use PAGER.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Piping copious output to PAGER automatically.

Posted by Marc Haisenko <ha...@webport.de>.
On Monday 06 September 2004 00:33, Greg Hudson wrote:
> On Sun, 2004-09-05 at 18:17, David Wilson wrote:
> > That's a fair point, but what of the case where we are more than likely
> > flooding the user's screen, and here is an obvious and unintrusive way
> > of preventing that?
>
> If the value of PAGER is "less", then it's pretty intrusive.  "svn log
> -r N file" would clear the screen, display one (possibly short) log
> message at the bottom of the screen, and would wait for user input
> before returning to the prompt.

export PAGER=less -F

This fixes the described problem :-)


-- 
Marc Haisenko
Systemspezialist
Webport IT-Services GmbH
mailto: haisenko@webport.de

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Piping copious output to PAGER automatically.

Posted by Max Bowsher <ma...@ukf.net>.
David Wilson wrote:
> On Sun, Sep 05, 2004 at 10:47:34AM -0700, Peter S. Housel wrote:
>
>> Setting PAGER just lets you choose *which* pager you want to use, for
>> programs that use one; it's not a license for arbitrary programs to
>> start piping things to PAGER.
>
> That's a fair point, but what of the case where we are more than likely
> flooding the user's screen, and here is an obvious and unintrusive way
> of preventing that?
>
> What are peoples' thoughts on making it a (default off) option, or one
> that can be applied like:
>
>    [miscellany]
>    auto-pager = cat diff blame
>
> The latter resolves the issue of which commands to apply the
> functionality to.

Ouch.

I've just realized that for this feature to be truly useful for me, it would 
need to support different pagers for different svn commands!

log => less - streamy display
diff => vimless - syntax highlighting, not streamy

Umm...

Maybe I'm better off using explicit pipes...

Max.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Piping copious output to PAGER automatically.

Posted by Greg Hudson <gh...@MIT.EDU>.
On Sun, 2004-09-05 at 18:17, David Wilson wrote:
> That's a fair point, but what of the case where we are more than likely
> flooding the user's screen, and here is an obvious and unintrusive way
> of preventing that?

If the value of PAGER is "less", then it's pretty intrusive.  "svn log
-r N file" would clear the screen, display one (possibly short) log
message at the bottom of the screen, and would wait for user input
before returning to the prompt.

In your original message, you suggested that we might buffer the first N
lines of data before deciding whether to invoke the pager.  We could do
that with a stream filter, but it's still a little intrusive; if the
output of a big command is trickling in slowly, it means I don't see the
output until a screenfull of it is ready.

If we provided this feature as an option, then it wouldn't be intrusive,
but it would be yet another knob which only 1% or fewer users would be
likely to use.  And it would be a weird feature which very few programs
have.

I have to wonder if what you really want is a shell feature which pipes
the output of all or selected commands to $PAGER.  Then you wouldn't
need to go around convincing every stdout-producing app to add this knob
(not that you've been doing so, but that's the logical conclusion of
your argument).  I bet zsh would be happy to add such a feature if it
isn't already present.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Piping copious output to PAGER automatically.

Posted by David Wilson <dw...@botanicus.net>.
On Sun, Sep 05, 2004 at 10:47:34AM -0700, Peter S. Housel wrote:

> Setting PAGER just lets you choose *which* pager you want to use, for
> programs that use one; it's not a license for arbitrary programs to
> start piping things to PAGER.

That's a fair point, but what of the case where we are more than likely
flooding the user's screen, and here is an obvious and unintrusive way
of preventing that?

What are peoples' thoughts on making it a (default off) option, or one
that can be applied like:

    [miscellany]
    auto-pager = cat diff blame

The latter resolves the issue of which commands to apply the
functionality to.


David.

-- 
Gentoo, for when 13 hours of your time is worth more than the 0.1
nanoseconds your CPU saves during use.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Piping copious output to PAGER automatically.

Posted by "Peter S. Housel" <ho...@acm.org>.
On Sun, 2004-09-05 at 10:08, Max Bowsher wrote:
> David Wilson wrote:
> > If the condition succeeds, then use popen(3) (or the APR equivalent) to
> > pipe our copious output to the user's preferred PAGER instead of
> > directly to their screen.
> 
> After being initially shocked by the violation of Unix tradition, I 
> eventually came to think that *if* the user has set PAGER, then they 
> probably would like this feature.

Setting PAGER just lets you choose *which* pager you want to use, for
programs that use one; it's not a license for arbitrary programs to
start piping things to PAGER.

-Peter-


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Piping copious output to PAGER automatically.

Posted by Max Bowsher <ma...@ukf.net>.
David Wilson wrote:
> Hi there,
>
> First and foremost, congratulations on an excellent product. It is rare
> to see an open source project so well built.
>
> In #svn today, I suggested the addition of a feature which provoked a
> little discussion, and it was suggested I post it here for
> consideration.
>
> Basically, in 99% of cases (and probably closer to 100% with
> Subversion) when stdout is connected to a terminal device and we are
> sending a large amount of output to stdout, there is a very high chance
> that we are going to flood the user's terminal.
>
> My basic idea is to test for something like the following or it's APR
> equivalent:
>
>    (isatty(fileno(stdout)) && (pager = getenv("PAGER")) && *pager)
>
>
> If the condition succeeds, then use popen(3) (or the APR equivalent) to
> pipe our copious output to the user's preferred PAGER instead of
> directly to their screen.

After being initially shocked by the violation of Unix tradition, I 
eventually came to think that *if* the user has set PAGER, then they 
probably would like this feature.

So, I'm actually +1 on this idea.

Max.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org