diff options
author | Andrew Dunstan | 2015-03-28 15:07:41 +0000 |
---|---|---|
committer | Andrew Dunstan | 2015-03-28 15:07:41 +0000 |
commit | 7655f4ccea570d57c4d473cd66b755c03c904942 (patch) | |
tree | 66c54949a4abf3816b9826709728317889053bd5 /src/bin/psql/print.c | |
parent | cfe12763c32437bc708a64ce88a90c7544f16185 (diff) |
Add a pager_min_lines setting to psql
If set, the pager will not be used unless this many lines are to be
displayed, even if that is more than the screen depth. Default is zero,
meaning it's disabled.
There is probably more work to be done in giving the user control over
when the pager is used, particularly when wide output forces use of the
pager regardless of how many lines there are, but this is a start.
Diffstat (limited to 'src/bin/psql/print.c')
-rw-r--r-- | src/bin/psql/print.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c index f6f93108413..9c12dbe049a 100644 --- a/src/bin/psql/print.c +++ b/src/bin/psql/print.c @@ -811,7 +811,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout) if (!is_pager && fout == stdout && output_columns > 0 && (output_columns < total_header_width || output_columns < width_total)) { - fout = PageOutput(INT_MAX, cont->opt->pager); /* force pager */ + fout = PageOutput(INT_MAX, cont->opt); /* force pager */ is_pager = true; } @@ -2497,15 +2497,19 @@ print_troff_ms_vertical(const printTableContent *cont, FILE *fout) * PageOutput * * Tests if pager is needed and returns appropriate FILE pointer. + * + * If the topt argument is NULL no pager is used. */ FILE * -PageOutput(int lines, unsigned short int pager) +PageOutput(int lines, const printTableOpt *topt) { /* check whether we need / can / are supposed to use pager */ - if (pager && isatty(fileno(stdin)) && isatty(fileno(stdout))) + if (topt && topt->pager && isatty(fileno(stdin)) && isatty(fileno(stdout))) { const char *pagerprog; FILE *pagerpipe; + unsigned short int pager = topt->pager; + int min_lines = topt->pager_min_lines; #ifdef TIOCGWINSZ int result; @@ -2514,7 +2518,9 @@ PageOutput(int lines, unsigned short int pager) result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size); /* >= accounts for a one-line prompt */ - if (result == -1 || lines >= screen_size.ws_row || pager > 1) + if (result == -1 + || (lines >= screen_size.ws_row && lines >= min_lines) + || pager > 1) { #endif pagerprog = getenv("PAGER"); @@ -2814,7 +2820,7 @@ IsPagerNeeded(const printTableContent *cont, const int extra_lines, bool expande lines++; } - *fout = PageOutput(lines + extra_lines, cont->opt->pager); + *fout = PageOutput(lines + extra_lines, cont->opt); *is_pager = (*fout != stdout); } else |