psql \pset pager always for 7.3.2 (patch) - Mailing list pgsql-patches
From | reece@in-machina.com |
---|---|
Subject | psql \pset pager always for 7.3.2 (patch) |
Date | |
Msg-id | Pine.LNX.4.44.0302251122210.2581-100000@localhost.localdomain Whole thread Raw |
Responses |
Re: psql \pset pager always for 7.3.2 (patch)
|
List | pgsql-patches |
# This patch implements tri-state pager usage: off, on, and always. It was # adapted for 7.3.2 from a one provided by greg@turnstep.com and which # Bruce Momjian indicated was scheduled for 7.4. (See # http://archives.postgresql.org/pgsql-patches/2002-09/msg00163.php ) # \pset pager off (internally, int pager=0) and \pset pager on (pager=1) # operate as in 7.3.2. \pset pager always (pager=2) causes psql to always # invoke the pager. This is particularly useful when using less with the # environment setting LESS=-FXS, which causes less to display and exit # immediately if the text fits entirely within the horizontal and vertical # terminal size (unlike \pset pager on, which only accounts for the number # of rows). # NOTE: If you appear to get no output when executing a psql command, be # sure that you're including -X in LESS. # Apply with # $ cd postgresql-7.3.2; patch -p1 <pager-always.patch # 2003/02/25 (Tue) 11:13 Reece Hart <reece@in-machina.com> diff -ur --exclude='*.rej' --exclude='*.o' --exclude='*.orig' postgresql-7.3.2/src/bin/psql/command.c postgresql-7.3.2-pa/src/bin/psql/command.c --- postgresql-7.3.2/src/bin/psql/command.c Thu Jan 23 21:23:55 2003 +++ postgresql-7.3.2-pa/src/bin/psql/command.c Tue Feb 25 11:04:26 2003 @@ -1873,14 +1873,29 @@ /* toggle use of pager */ else if (strcmp(param, "pager") == 0) { - popt->topt.pager = !popt->topt.pager; - if (!quiet) - { - if (popt->topt.pager) - puts(gettext("Using pager is on.")); - else - puts(gettext("Using pager is off.")); - } + if (value != NULL) + { + if (strcasecmp(value, "always") == 0) + popt->topt.pager = 2; + else if (strcasecmp(value, "off") == 0) + popt->topt.pager = 0; + else if (strcasecmp(value, "on") == 0) + popt->topt.pager = 1; + else + psql_error("\\pset: optional argument must be one of off|on|always\n"); + } + else + popt->topt.pager = !popt->topt.pager; + + if (!quiet) + { + 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.")); + } } /* disable "(x rows)" footer */ Only in postgresql-7.3.2-pa/src/bin/psql: command.c.~1~ diff -ur --exclude='*.rej' --exclude='*.o' --exclude='*.orig' postgresql-7.3.2/src/bin/psql/common.c postgresql-7.3.2-pa/src/bin/psql/common.c --- postgresql-7.3.2/src/bin/psql/common.c Tue Oct 29 11:35:33 2002 +++ postgresql-7.3.2-pa/src/bin/psql/common.c Tue Feb 25 09:44:57 2003 @@ -530,7 +530,7 @@ * Tests if pager is needed and returns appropriate FILE pointer. */ FILE * -PageOutput(int lines, bool pager) +PageOutput(int lines, int pager) { /* check whether we need / can / are supposed to use pager */ if (pager @@ -548,7 +548,7 @@ 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 == 2) { #endif pagerprog = getenv("PAGER"); diff -ur --exclude='*.rej' --exclude='*.o' --exclude='*.orig' postgresql-7.3.2/src/bin/psql/common.h postgresql-7.3.2-pa/src/bin/psql/common.h --- postgresql-7.3.2/src/bin/psql/common.h Tue Oct 29 11:35:33 2002 +++ postgresql-7.3.2-pa/src/bin/psql/common.h Tue Feb 25 09:45:11 2003 @@ -37,7 +37,7 @@ extern bool SendQuery(const char *query); -extern FILE *PageOutput(int lines, bool pager); +extern FILE *PageOutput(int lines, int pager); /* sprompt.h */ extern char *simple_prompt(const char *prompt, int maxlen, bool echo); diff -ur --exclude='*.rej' --exclude='*.o' --exclude='*.orig' postgresql-7.3.2/src/bin/psql/help.c postgresql-7.3.2-pa/src/bin/psql/help.c --- postgresql-7.3.2/src/bin/psql/help.c Wed Oct 23 18:33:50 2002 +++ postgresql-7.3.2-pa/src/bin/psql/help.c Tue Feb 25 09:45:44 2003 @@ -159,7 +159,7 @@ #endif void -slashUsage(bool pager) +slashUsage(int pager) { FILE *output; @@ -241,7 +241,7 @@ * */ void -helpSQL(const char *topic, bool pager) +helpSQL(const char *topic, int pager) { #define VALUE_OR_NULL(a) ((a) ? (a) : "") diff -ur --exclude='*.rej' --exclude='*.o' --exclude='*.orig' postgresql-7.3.2/src/bin/psql/help.h postgresql-7.3.2-pa/src/bin/psql/help.h --- postgresql-7.3.2/src/bin/psql/help.h Wed Oct 23 12:23:57 2002 +++ postgresql-7.3.2-pa/src/bin/psql/help.h Tue Feb 25 09:45:36 2003 @@ -10,9 +10,9 @@ void usage(void); -void slashUsage(bool pager); +void slashUsage(int pager); -void helpSQL(const char *topic, bool pager); +void helpSQL(const char *topic, int pager); void print_copyright(void); diff -ur --exclude='*.rej' --exclude='*.o' --exclude='*.orig' postgresql-7.3.2/src/bin/psql/print.h postgresql-7.3.2-pa/src/bin/psql/print.h --- postgresql-7.3.2/src/bin/psql/print.h Wed Sep 4 13:31:36 2002 +++ postgresql-7.3.2-pa/src/bin/psql/print.h Mon Feb 24 16:57:31 2003 @@ -26,8 +26,9 @@ 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 */ Only in postgresql-7.3.2-pa/src/bin/psql: psql diff -ur --exclude='*.rej' --exclude='*.o' --exclude='*.orig' postgresql-7.3.2/src/bin/psql/startup.c postgresql-7.3.2-pa/src/bin/psql/startup.c --- postgresql-7.3.2/src/bin/psql/startup.c Fri Oct 18 15:05:36 2002 +++ postgresql-7.3.2-pa/src/bin/psql/startup.c Mon Feb 24 16:57:31 2003 @@ -137,7 +137,7 @@ 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); -- Reece Hart, http://www.in-machina.com/~reece/, GPG:0x25EC91A0
pgsql-patches by date: