Skip to content

Commit b26dfbb

Browse files
committed
Here is a patch that does just that, while maintaining the
"traditional" behavior, so the change should be transparent. Use the command "\pset pager always" to turn it on. Anything else does the normal toggle between "on" and "off" Greg Sabino Mullane
1 parent c2b716a commit b26dfbb

File tree

7 files changed

+34
-26
lines changed

7 files changed

+34
-26
lines changed

doc/src/sgml/ref/psql-ref.sgml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.79 2002/10/19 00:22:14 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.80 2002/11/08 19:12:21 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -1456,21 +1456,21 @@ lo_import 152801
14561456
<term><literal>pager</literal></term>
14571457
<listitem>
14581458
<para>
1459-
Toggles the use of a pager for query and <application>psql</> help output. If the
1460-
environment variable <envar>PAGER</envar> is set, the output
1461-
is piped to the specified program. Otherwise a platform-dependent default (such as
1459+
Controls use of a pager for query and <application>psql</>
1460+
help output. If the environment variable <envar>PAGER</envar>
1461+
is set, the output is piped to the specified program.
1462+
Otherwise a platform-dependent default (such as
14621463
<filename>more</filename>) is used.
14631464
</para>
14641465

14651466
<para>
1466-
In any case, <application>psql</application> only uses the
1467-
pager if it seems appropriate. That means among other things
1468-
that the output is to a terminal and that the table would
1469-
normally not fit on the screen. Because of the modular nature
1470-
of the printing routines it is not always possible to predict
1471-
the number of lines that will actually be printed. For that
1472-
reason <application>psql</application> might not appear very
1473-
discriminating about when to use the pager.
1467+
When the pager is off, the pager is not used. When the pager
1468+
is on, the pager is used only when appropriate, i.e. the
1469+
output is to a terminal and will not fit on the screen.
1470+
(<application>psql</> does not do a perfect job of estimating
1471+
when to use the pager.) <literal>\pset pager</> turns the
1472+
pager on and off. Pager can also be set to <literal>always</>,
1473+
which causes the pager to be always used.
14741474
</para>
14751475
</listitem>
14761476
</varlistentry>

src/bin/psql/command.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000-2002 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.84 2002/10/23 19:23:56 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.85 2002/11/08 19:12:21 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "command.h"
@@ -1873,11 +1873,18 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
18731873
/* toggle use of pager */
18741874
else if (strcmp(param, "pager") == 0)
18751875
{
1876-
popt->topt.pager = !popt->topt.pager;
1876+
if (value && strcasecmp(value, "always") == 0)
1877+
popt->topt.pager = 2;
1878+
else if (popt->topt.pager == 1)
1879+
popt->topt.pager = 0;
1880+
else
1881+
popt->topt.pager = 1;
18771882
if (!quiet)
18781883
{
1879-
if (popt->topt.pager)
1884+
if (popt->topt.pager == 1)
18801885
puts(gettext("Using pager is on."));
1886+
else if (popt->topt.pager == 2)
1887+
puts(gettext("Using pager is always."));
18811888
else
18821889
puts(gettext("Using pager is off."));
18831890
}

src/bin/psql/common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.51 2002/10/29 19:35:33 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.52 2002/11/08 19:12:21 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "common.h"
@@ -548,7 +548,7 @@ PageOutput(int lines, bool pager)
548548
struct winsize screen_size;
549549

550550
result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
551-
if (result == -1 || lines > screen_size.ws_row)
551+
if (result == -1 || lines > screen_size.ws_row || pager > 1)
552552
{
553553
#endif
554554
pagerprog = getenv("PAGER");

src/bin/psql/help.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.60 2002/10/24 01:33:50 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.61 2002/11/08 19:12:21 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "common.h"
@@ -159,7 +159,7 @@ struct winsize
159159
#endif
160160

161161
void
162-
slashUsage(bool pager)
162+
slashUsage(unsigned short int pager)
163163
{
164164
FILE *output;
165165

src/bin/psql/help.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/help.h,v 1.10 2002/10/23 19:23:57 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/help.h,v 1.11 2002/11/08 19:12:21 momjian Exp $
77
*/
88
#ifndef HELP_H
99
#define HELP_H
1010

1111
void usage(void);
1212

13-
void slashUsage(bool pager);
13+
void slashUsage(unsigned short int pager);
1414

1515
void helpSQL(const char *topic, bool pager);
1616

src/bin/psql/print.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/print.h,v 1.14 2002/09/04 20:31:36 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/print.h,v 1.15 2002/11/08 19:12:21 momjian Exp $
77
*/
88
#ifndef PRINT_H
99
#define PRINT_H
@@ -26,8 +26,9 @@ typedef struct _printTableOpt
2626
enum printFormat format; /* one of the above */
2727
bool expanded; /* expanded/vertical output (if supported
2828
* by output format) */
29-
bool pager; /* use pager for output (if to stdout and
30-
* stdout is a tty) */
29+
unsigned short int pager; /* use pager for output (if to stdout and
30+
* stdout is a tty)
31+
* 0=off 1=on 2=always */
3132
bool tuples_only; /* don't output headers, row counts, etc. */
3233
unsigned short int border; /* Print a border around the table.
3334
* 0=none, 1=dividing lines, 2=full */

src/bin/psql/startup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.68 2002/10/18 22:05:36 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.69 2002/11/08 19:12:21 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99

@@ -137,7 +137,7 @@ main(int argc, char *argv[])
137137
pset.popt.topt.format = PRINT_ALIGNED;
138138
pset.queryFout = stdout;
139139
pset.popt.topt.border = 1;
140-
pset.popt.topt.pager = true;
140+
pset.popt.topt.pager = 1;
141141
pset.popt.default_footer = true;
142142

143143
SetVariable(pset.vars, "VERSION", PG_VERSION_STR);

0 commit comments

Comments
 (0)