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

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: [GENERAL] psql: \pset pager 'always'?
Дата
Msg-id 200211081910.gA8JAFu29222@candle.pha.pa.us
обсуждение исходный текст
Список pgsql-patches
OK, I have applied the following patch for 7.4.  I made the following
changes:

    o  Pager code is now centralized in PageOutput
    o  You used 'small' when you meant 'short' in a few places
    o  Added documentation
    o  Fixed bug where '\pset pager' crashed psql

---------------------------------------------------------------------------

greg@turnstep.com wrote:
> > 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"

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: doc/src/sgml/ref/psql-ref.sgml
===================================================================
RCS file: /cvsroot/pgsql-server/doc/src/sgml/ref/psql-ref.sgml,v
retrieving revision 1.79
diff -c -c -r1.79 psql-ref.sgml
*** doc/src/sgml/ref/psql-ref.sgml    19 Oct 2002 00:22:14 -0000    1.79
--- doc/src/sgml/ref/psql-ref.sgml    8 Nov 2002 19:09:26 -0000
***************
*** 1456,1476 ****
        <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
        <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.
        </para>
        </listitem>
        </varlistentry>
--- 1456,1476 ----
        <term><literal>pager</literal></term>
        <listitem>
        <para>
!       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>
!       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: src/bin/psql/command.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/command.c,v
retrieving revision 1.84
diff -c -c -r1.84 command.c
*** src/bin/psql/command.c    23 Oct 2002 19:23:56 -0000    1.84
--- src/bin/psql/command.c    8 Nov 2002 19:09:34 -0000
***************
*** 1873,1883 ****
      /* 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."));
          }
--- 1873,1890 ----
      /* toggle use of pager */
      else if (strcmp(param, "pager") == 0)
      {
!         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 == 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: src/bin/psql/common.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/common.c,v
retrieving revision 1.51
diff -c -c -r1.51 common.c
*** src/bin/psql/common.c    29 Oct 2002 19:35:33 -0000    1.51
--- src/bin/psql/common.c    8 Nov 2002 19:09:36 -0000
***************
*** 548,554 ****
          struct winsize screen_size;

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

          result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
!         if (result == -1 || lines > screen_size.ws_row || pager > 1)
          {
  #endif
              pagerprog = getenv("PAGER");
Index: src/bin/psql/help.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/help.c,v
retrieving revision 1.60
diff -c -c -r1.60 help.c
*** src/bin/psql/help.c    24 Oct 2002 01:33:50 -0000    1.60
--- src/bin/psql/help.c    8 Nov 2002 19:09:38 -0000
***************
*** 159,165 ****
  #endif

  void
! slashUsage(bool pager)
  {
      FILE       *output;

--- 159,165 ----
  #endif

  void
! slashUsage(unsigned short int pager)
  {
      FILE       *output;

Index: src/bin/psql/help.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/help.h,v
retrieving revision 1.10
diff -c -c -r1.10 help.h
*** src/bin/psql/help.h    23 Oct 2002 19:23:57 -0000    1.10
--- src/bin/psql/help.h    8 Nov 2002 19:09:38 -0000
***************
*** 10,16 ****

  void        usage(void);

! void        slashUsage(bool pager);

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

--- 10,16 ----

  void        usage(void);

! void        slashUsage(unsigned short int pager);

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

Index: src/bin/psql/print.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/print.h,v
retrieving revision 1.14
diff -c -c -r1.14 print.h
*** src/bin/psql/print.h    4 Sep 2002 20:31:36 -0000    1.14
--- src/bin/psql/print.h    8 Nov 2002 19:09:39 -0000
***************
*** 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: src/bin/psql/startup.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/startup.c,v
retrieving revision 1.68
diff -c -c -r1.68 startup.c
*** src/bin/psql/startup.c    18 Oct 2002 22:05:36 -0000    1.68
--- src/bin/psql/startup.c    8 Nov 2002 19:09:41 -0000
***************
*** 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);

В списке pgsql-patches по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: one last patch - array lower and upper bound
Следующее
От: Joe Conway
Дата:
Сообщение: _getPlan missing support for some Plan node elements