]> granicus.if.org Git - postgresql/commitdiff
Here is a patch that does just that, while maintaining the
authorBruce Momjian <bruce@momjian.us>
Fri, 8 Nov 2002 19:12:21 +0000 (19:12 +0000)
committerBruce Momjian <bruce@momjian.us>
Fri, 8 Nov 2002 19:12:21 +0000 (19:12 +0000)
"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

doc/src/sgml/ref/psql-ref.sgml
src/bin/psql/command.c
src/bin/psql/common.c
src/bin/psql/help.c
src/bin/psql/help.h
src/bin/psql/print.h
src/bin/psql/startup.c

index 6e3525d76871021355bae70c5caf614a08ccb66d..bb8d8f5eb41cc6890c2cd9317cb35c57b1558515 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.79 2002/10/19 00:22:14 tgl Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.80 2002/11/08 19:12:21 momjian Exp $
 PostgreSQL documentation
 -->
 
@@ -1456,21 +1456,21 @@ lo_import 152801
          <term><literal>pager</literal></term>
          <listitem>
          <para>
-         Toggles the use of a pager for query and <application>psql</> help output. If the
-         environment variable <envar>PAGER</envar> is set, the output
-         is piped to the specified program. Otherwise a platform-dependent default (such as
+         Controls use of a pager for query and <application>psql</>
+         help output. If the environment variable <envar>PAGER</envar>
+         is set, the output is piped to the specified program.
+         Otherwise a platform-dependent default (such as
          <filename>more</filename>) is used.
          </para>
 
          <para>
-         In any case, <application>psql</application> only uses the
-         pager if it seems appropriate. That means among other things
-         that the output is to a terminal and that the table would
-         normally not fit on the screen. Because of the modular nature
-         of the printing routines it is not always possible to predict
-         the number of lines that will actually be printed. For that
-         reason <application>psql</application> might not appear very
-         discriminating about when to use the pager.
+         When the pager is off, the pager is not used. When the pager
+         is on, the pager is used only when appropriate, i.e. the
+         output is to a terminal and will not fit on the screen.
+         (<application>psql</> does not do a perfect job of estimating
+         when to use the pager.) <literal>\pset pager</> turns the
+         pager on and off. Pager can also be set to <literal>always</>,
+         which causes the pager to be always used.
          </para>
          </listitem>
          </varlistentry>
index 83ce799e51cfc5395583bdc12fe31474a643c287..bfe5b45e1efcd08709e4a601eb85b85becac33c0 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000-2002 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.84 2002/10/23 19:23:56 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.85 2002/11/08 19:12:21 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "command.h"
@@ -1873,11 +1873,18 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
        /* toggle use of pager */
        else if (strcmp(param, "pager") == 0)
        {
-               popt->topt.pager = !popt->topt.pager;
+               if (value && strcasecmp(value, "always") == 0)
+                               popt->topt.pager = 2;
+               else if (popt->topt.pager == 1)
+                               popt->topt.pager = 0;
+               else
+                               popt->topt.pager = 1;
                if (!quiet)
                {
-                       if (popt->topt.pager)
+                       if (popt->topt.pager == 1)
                                puts(gettext("Using pager is on."));
+                       else if (popt->topt.pager == 2)
+                               puts(gettext("Using pager is always."));
                        else
                                puts(gettext("Using pager is off."));
                }
index 55af65a3ae1cd2c3bad10b21981f7491b1ae61d6..fcd898877a2d2af1725270a5193d20c7403b228f 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.51 2002/10/29 19:35:33 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.52 2002/11/08 19:12:21 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "common.h"
@@ -548,7 +548,7 @@ PageOutput(int lines, bool pager)
                struct winsize screen_size;
 
                result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
-               if (result == -1 || lines > screen_size.ws_row)
+               if (result == -1 || lines > screen_size.ws_row || pager > 1)
                {
 #endif
                        pagerprog = getenv("PAGER");
index 6e5323c01acb7f6dd3bfe9c8944b2703486ee5c6..f9dd6145ae2ca7365451a01d6682f97e3f31bff0 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.60 2002/10/24 01:33:50 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.61 2002/11/08 19:12:21 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "common.h"
@@ -159,7 +159,7 @@ struct winsize
 #endif
 
 void
-slashUsage(bool pager)
+slashUsage(unsigned short int pager)
 {
        FILE       *output;
 
index 28a878646615644ca3a6742c7ffe443dc23d3e9c..7b3078dd85d40c8c7f61aeea60c9c3fc6fce61f5 100644 (file)
@@ -3,14 +3,14 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/help.h,v 1.10 2002/10/23 19:23:57 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/help.h,v 1.11 2002/11/08 19:12:21 momjian Exp $
  */
 #ifndef HELP_H
 #define HELP_H
 
 void           usage(void);
 
-void           slashUsage(bool pager);
+void           slashUsage(unsigned short int pager);
 
 void           helpSQL(const char *topic, bool pager);
 
index 09ec685bfef12322f6f858ad45b380b34e6d8268..f97bf9ead5244e9347e7e97ca1edbab7d61ad9e9 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/print.h,v 1.14 2002/09/04 20:31:36 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/print.h,v 1.15 2002/11/08 19:12:21 momjian Exp $
  */
 #ifndef PRINT_H
 #define PRINT_H
@@ -26,8 +26,9 @@ typedef struct _printTableOpt
        enum printFormat format;        /* one of the above */
        bool            expanded;               /* expanded/vertical output (if supported
                                                                 * by output format) */
-       bool            pager;                  /* use pager for output (if to stdout and
-                                                                * stdout is a tty) */
+       unsigned short int pager;       /* use pager for output (if to stdout and
+                                                                * stdout is a tty)
+                                                                * 0=off 1=on 2=always */
        bool            tuples_only;    /* don't output headers, row counts, etc. */
        unsigned short int border;      /* Print a border around the table.
                                                                 * 0=none, 1=dividing lines, 2=full */
index 16e7ed9c287a70b6e550b322304f6956420e5a62..3a9ab01e0e5a680465c6ccd9196d54a321675bad 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.68 2002/10/18 22:05:36 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.69 2002/11/08 19:12:21 momjian Exp $
  */
 #include "postgres_fe.h"
 
@@ -137,7 +137,7 @@ main(int argc, char *argv[])
        pset.popt.topt.format = PRINT_ALIGNED;
        pset.queryFout = stdout;
        pset.popt.topt.border = 1;
-       pset.popt.topt.pager = true;
+       pset.popt.topt.pager = 1;
        pset.popt.default_footer = true;
 
        SetVariable(pset.vars, "VERSION", PG_VERSION_STR);