Re: [GENERAL] psql: \pset pager 'always'?

From: greg(at)turnstep(dot)com
To: pgsql-general(at)postgresql(dot)org, pgsql-patches(at)postgresql(dot)org
Cc: antti(dot)haapala(at)iki(dot)fi
Subject: Re: [GENERAL] psql: \pset pager 'always'?
Date: 2002-09-11 19:29:06
Message-ID: 20020911193602.C1EED476944@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

> I'm really annoyed by that little 'feature' of psql that decides whether
> to use pager or not. I personally use GNU 'less' with options -S -F as my
> pager, which allows me to scroll vertically AS WELL AS horizontally on
> long input. So a "use pager always" option with no strange automagic
> behaviour would be nice.

Not a bad idea. 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 greg(at)turnstep(dot)com
PGP Key: 0x14964AC8 200209111525

Index: command.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/command.c,v
retrieving revision 1.80
diff -c -r1.80 command.c
*** command.c 2002/09/04 20:31:35 1.80
--- command.c 2002/09/11 19:24:41
***************
*** 1867,1877 ****
/* 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."));
}
--- 1867,1884 ----
/* toggle use of pager */
else if (strcmp(param, "pager") == 0)
{
! if (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 == 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: help.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/help.c,v
retrieving revision 1.56
diff -c -r1.56 help.c
*** help.c 2002/09/04 20:31:35 1.56
--- help.c 2002/09/11 19:24:41
***************
*** 159,165 ****
#endif

void
! slashUsage(bool pager)
{
FILE *output,
*pagerfd = NULL;
--- 159,165 ----
#endif

void
! slashUsage(unsigned small int pager)
{
FILE *output,
*pagerfd = NULL;
***************
*** 180,186 ****
struct winsize screen_size;

result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
! if (result == -1 || 50 > screen_size.ws_row)
{
#endif
pagerprog = getenv("PAGER");
--- 180,186 ----
struct winsize screen_size;

result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
! if (result == -1 || 50 > screen_size.ws_row || pager == 2)
{
#endif
pagerprog = getenv("PAGER");
Index: help.h
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/help.h,v
retrieving revision 1.9
diff -c -r1.9 help.h
*** help.h 2002/07/15 01:56:25 1.9
--- help.h 2002/09/11 19:24:41
***************
*** 10,16 ****

void usage(void);

! void slashUsage(bool pager);

void helpSQL(const char *topic);

--- 10,16 ----

void usage(void);

! void slashUsage(unsigned small int pager);

void helpSQL(const char *topic);

Index: print.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/print.c,v
retrieving revision 1.31
diff -c -r1.31 print.c
*** print.c 2002/09/01 23:30:46 1.31
--- print.c 2002/09/11 19:24:41
***************
*** 1022,1028 ****
lines++;

result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
! if (result == -1 || lines > screen_size.ws_row)
{
#endif
pagerprog = getenv("PAGER");
--- 1022,1028 ----
lines++;

result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
! if (result == -1 || lines > screen_size.ws_row || opt->pager == 2)
{
#endif
pagerprog = getenv("PAGER");
Index: print.h
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/print.h,v
retrieving revision 1.14
diff -c -r1.14 print.h
*** print.h 2002/09/04 20:31:36 1.14
--- print.h 2002/09/11 19:24:41
***************
*** 26,33 ****
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) */
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 */
--- 26,34 ----
enum printFormat format; /* one of the above */
bool expanded; /* expanded/vertical output (if supported
* by output format) */
! 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: startup.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/startup.c,v
retrieving revision 1.66
diff -c -r1.66 startup.c
*** startup.c 2002/09/06 02:33:47 1.66
--- startup.c 2002/09/11 19:24:41
***************
*** 137,143 ****
pset.popt.topt.format = PRINT_ALIGNED;
pset.queryFout = stdout;
pset.popt.topt.border = 1;
! pset.popt.topt.pager = true;
pset.popt.default_footer = true;

SetVariable(pset.vars, "VERSION", PG_VERSION_STR);
--- 137,143 ----
pset.popt.topt.format = PRINT_ALIGNED;
pset.queryFout = stdout;
pset.popt.topt.border = 1;
! pset.popt.topt.pager = 1;
pset.popt.default_footer = true;

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

-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html

iD8DBQE9f5klvJuQZxSWSsgRAuFGAJwNsHiudvGq+Xq8WpQO4bSrd+QUtwCgo1lB
iolPoprltuDfsb4YSjAHHs4=
=5Kt2
-----END PGP SIGNATURE-----

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2002-09-11 23:56:09 Re: fmgr.h: PG_NARGS() for number of arguments passed
Previous Message Lee Kindness 2002-09-11 13:25:01 fmgr.h: PG_NARGS() for number of arguments passed