Thread: [HACKERS] psql: Activate pager only for height, not width

[HACKERS] psql: Activate pager only for height, not width

From
Brendan Jurd
Date:
Hello hackers,

I am often frustrated by the default behaviour of the psql pager, which will activate a pager if the output is deemed to be "too wide" for the terminal, regardless of the number of lines output, and of the pager_min_lines setting.

This behaviour is sometimes desirable, but in my use patterns it is more often the case that I want the pager to activate for output longer than terminal height, whereas for output a little wider than the terminal, I am happy for there to be some wrapping.  This is especially the case with "\d" output for tables, where, at 80 columns, very often the only wrapping is in the table borders and constraint/trigger definitions.

Usually I turn the pager off completely, and only switch it on when I am about to execute something that will return many rows, but what I'd really like is some way to tell psql to activate the pager as normal for height, but to ignore width.  My first thought was an alternate mode to \pset pager -- to {'on' | 'off' | 'always'} we could add 'height'.

Another option is to add the ability to specify the number of columns which psql considers "too wide", analogous to pager_min_lines.  I could then set pager_min_cols to something around 150 which would work nicely for my situation.

I don't have strong opinions about how the options are constructed, as long as it is possible to obtain the behaviour.

I would be happy to produce a patch, if this seems like an acceptable feature add.

Regards,
BJ

Re: [HACKERS] psql: Activate pager only for height, not width

From
Jeff Janes
Date:
On Sun, May 28, 2017 at 10:09 PM, Brendan Jurd <direvus@gmail.com> wrote:
Hello hackers,

I am often frustrated by the default behaviour of the psql pager, which will activate a pager if the output is deemed to be "too wide" for the terminal, regardless of the number of lines output, and of the pager_min_lines setting.

This behaviour is sometimes desirable, but in my use patterns it is more often the case that I want the pager to activate for output longer than terminal height, whereas for output a little wider than the terminal, I am happy for there to be some wrapping.  This is especially the case with "\d" output for tables, where, at 80 columns, very often the only wrapping is in the table borders and constraint/trigger definitions.

Usually I turn the pager off completely, and only switch it on when I am about to execute something that will return many rows, but what I'd really like is some way to tell psql to activate the pager as normal for height, but to ignore width.  My first thought was an alternate mode to \pset pager -- to {'on' | 'off' | 'always'} we could add 'height'.

Another option is to add the ability to specify the number of columns which psql considers "too wide", analogous to pager_min_lines.  I could then set pager_min_cols to something around 150 which would work nicely for my situation.

I don't have strong opinions about how the options are constructed, as long as it is possible to obtain the behaviour.

I would be happy to produce a patch, if this seems like an acceptable feature add.

I'd like a feature like this.  I often run into the problem where one or two lines of an EXPLAIN plan are wide enough to wrap, which causes the pager to kick in.  Then when I exit the pager, it clears the contents so I can't see that plan vertically adjacent to the one I'm trying to compare it to.  I'd rather have the pager kick in if greater than some settable number of the lines are too wide, or if the wrapped lines would push the height above the height limit.  If just one line is too wide, I'd rather just deal with them being wrapped.

(You can configure the pager not to redraw the screen when exited, but I want it to redraw the screen after looking at 10,000 rows, just not after looking ten rows, one of which was 170 characters wide)
 
Cheers,

Jeff

Re: [HACKERS] psql: Activate pager only for height, not width

From
Christoph Berg
Date:
Re: Jeff Janes 2017-05-29 <CAMkU=1wBpDrHdjSvABtFRB1TguC+LBJJwpV79kxyMOkeUi2B3Q@mail.gmail.com>
> > Usually I turn the pager off completely, and only switch it on when I am
> > about to execute something that will return many rows, but what I'd really
> > like is some way to tell psql to activate the pager as normal for height,
> > but to ignore width.  My first thought was an alternate mode to \pset pager
> > -- to {'on' | 'off' | 'always'} we could add 'height'.

This bugs me pretty often as well. Height seems to be a more sensible
trigger; maybe not by default, but I could imagine setting that as
default in my .psqlrc.

> > Another option is to add the ability to specify the number of columns
> > which psql considers "too wide", analogous to pager_min_lines.  I could
> > then set pager_min_cols to something around 150 which would work nicely for
> > my situation.

Oh interesting, I didn't know about pager_min_lines. That sounds
useful as well. +1 on the analogous pager_min_cols option.

> (You can configure the pager not to redraw the screen when exited, but I
> want it to redraw the screen after looking at 10,000 rows, just not after
> looking ten rows, one of which was 170 characters wide)

Another thing you can do which has somewhat solved the above issue for
me is PAGER="less -S" which tells less not to wrap lines but let the 
user scroll left/right using the arrow keys.

Christoph



Re: [HACKERS] psql: Activate pager only for height, not width

From
Brendan Jurd
Date:
On Tue, 30 May 2017 at 05:30 Christoph Berg <myon@debian.org> wrote:
Oh interesting, I didn't know about pager_min_lines. That sounds
useful as well. +1 on the analogous pager_min_cols option.

On closer inspection, I note that psql already has a 'columns' \pset option, which does control the width for triggering the pager, but also controls the width for wrapping and auto-expanded mode purposes.  So, I can set 'columns' to get the pager behaviour that I want, but I also get unwanted effects where I'd rather let the default (terminal width) apply.

So if we were to add a 'pager_min_cols', we'd have to decide how it interacts with 'columns'.  For example, to determine whether to trigger the pager, we look for 'pager_min_cols' first, and if that is not set, then fall back to 'columns'.  For all other width purposes, 'columns' would continue to apply as present.

However, my feeling is that this is becoming a bit too fiddly.  If 'columns' did not already exist then 'pager_min_cols' would make more sense, but as it does already exist, my preference is to leave 'columns' as-is, and go for a height-only option to 'pager' instead.

Thoughts?

Cheers,
BJ