In psql, use PSQL_PAGER in preference to PAGER, if it's set.
authorTom Lane
Tue, 5 Sep 2017 16:02:06 +0000 (12:02 -0400)
committerTom Lane
Tue, 5 Sep 2017 16:02:13 +0000 (12:02 -0400)
This allows the user's environment to set up a psql-specific choice
of pager, in much the same way that we provide PSQL_EDITOR to allow
a psql-specific override of the more widely known EDITOR variable.

Pavel Stehule, reviewed by Thomas Munro

Discussion: https://postgr.es/m/CAFj8pRD3RRk9S1eRbnGm_T6brc3Ss5mohraNzTSJquzx+pmtKA@mail.gmail.com

doc/src/sgml/ref/psql-ref.sgml
src/bin/psql/help.c
src/fe_utils/print.c
src/interfaces/libpq/fe-print.c

index 868de184184cff10dd31900f38bbadfc3ca5d9d8..fd2ca15d0aaf904e19f0a85fc2e4ab4255242e13 100644 (file)
@@ -2665,10 +2665,10 @@ lo_import 152801
           
           
           Controls use of a pager program for query and psql
-          help output. If the environment variable PAGER
-          is set, the output is piped to the specified program.
-          Otherwise a platform-dependent default (such as
-          more) is used.
+          help output.  If the environment variable PSQL_PAGER
+          or PAGER is set, the output is piped to the
+          specified program.  Otherwise a platform-dependent default program
+          (such as more) is used.
           
 
           
@@ -4106,21 +4106,6 @@ $endif
     
    
 
-   
-    PAGER
-
-    
-     
-      If the query results do not fit on the screen, they are piped
-      through this command.  Typical values are
-      more or less.  The default
-      is platform-dependent.  Use of the pager can be disabled by setting
-      PAGER to empty, or by using pager-related options of
-      the \pset command.
-     
-    
-   
-
    
     PGDATABASE
     PGHOST
@@ -4145,11 +4130,8 @@ $endif
       and \ev commands.
       These variables are examined in the order listed;
       the first that is set is used.
-     
-
-     
-      The built-in default editors are vi on Unix
-      systems and notepad.exe on Windows systems.
+      If none of them is set, the default is to use vi
+      on Unix systems or notepad.exe on Windows systems.
      
     
    
@@ -4192,6 +4174,27 @@ PSQL_EDITOR_LINENUMBER_ARG='--line '
     
    
 
+   
+    PSQL_PAGER
+    PAGER
+
+    
+     
+      If a query's results do not fit on the screen, they are piped
+      through this command. Typical values are more
+      or less.
+      Use of the pager can be disabled by setting PSQL_PAGER
+      or PAGER to an empty string, or by adjusting the
+      pager-related options of the \pset command.
+      These variables are examined in the order listed;
+      the first that is set is used.
+      If none of them is set, the default is to use more on most
+      platforms, but less on Cygwin.
+     
+
+    
+   
+
    
     PSQLRC
 
index 724cf8e761ef7245cce44f3ec73620d06a7533d9..9d366180af5c870740b524c55f653352c5b55daa 100644 (file)
@@ -459,8 +459,6 @@ helpVariables(unsigned short int pager)
 
    fprintf(output, _("  COLUMNS\n"
                      "    number of columns for wrapped format\n"));
-   fprintf(output, _("  PAGER\n"
-                     "    name of external pager program\n"));
    fprintf(output, _("  PGAPPNAME\n"
                      "    same as the application_name connection parameter\n"));
    fprintf(output, _("  PGDATABASE\n"
@@ -481,6 +479,8 @@ helpVariables(unsigned short int pager)
                      "    how to specify a line number when invoking the editor\n"));
    fprintf(output, _("  PSQL_HISTORY\n"
                      "    alternative location for the command history file\n"));
+   fprintf(output, _("  PSQL_PAGER, PAGER\n"
+                     "    name of external pager program\n"));
    fprintf(output, _("  PSQLRC\n"
                      "    alternative location for the user's .psqlrc file\n"));
    fprintf(output, _("  SHELL\n"
index f756f767e57b1cd209b442594093283b3c2a6898..8af5bbe97ea8c63f6b866519f114de8756a47278 100644 (file)
@@ -2870,7 +2870,9 @@ PageOutput(int lines, const printTableOpt *topt)
            const char *pagerprog;
            FILE       *pagerpipe;
 
-           pagerprog = getenv("PAGER");
+           pagerprog = getenv("PSQL_PAGER");
+           if (!pagerprog)
+               pagerprog = getenv("PAGER");
            if (!pagerprog)
                pagerprog = DEFAULT_PAGER;
            else
index 89bc4c54299d0ecf0b2c06991a369f8462a87d83..6dbf847280098d90419c0f60e13b3c70a7750529 100644 (file)
@@ -165,6 +165,13 @@ PQprint(FILE *fout, const PGresult *res, const PQprintOpt *po)
            screen_size.ws_row = 24;
            screen_size.ws_col = 80;
 #endif
+
+           /*
+            * Since this function is no longer used by psql, we don't examine
+            * PSQL_PAGER.  It's possible that the hypothetical external users
+            * of the function would like that to happen, but in the name of
+            * backwards compatibility, we'll stick to just examining PAGER.
+            */
            pagerenv = getenv("PAGER");
            /* if PAGER is unset, empty or all-white-space, don't use pager */
            if (pagerenv != NULL &&