Re: [NOVICE] encoding problems - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: [NOVICE] encoding problems
Date
Msg-id 200805072032.m47KWh723442@momjian.us
Whole thread Raw
In response to Re: [NOVICE] encoding problems  (Alvaro Herrera <alvherre@commandprompt.com>)
Responses Re: [NOVICE] encoding problems
List pgsql-patches
Alvaro Herrera wrote:
> Bruce Momjian wrote:
> > Alvaro Herrera wrote:
>
> > > Surely psql computes the width of all cells before printing anything.
> >
> > It does, but if you have a value that has a tab, how do you know what
> > tab stop you are on because you don't know the final width of the
> > previous columns at that time, so there is no way to know the width of
> > that cell.
>
> My point is that you don't need to align the tabstops with the start of
> the line, but with the start of the _column_.  So the width of the
> previous column doesn't matter.

Alvaro, using spaces instead of the terminal hard tabs was a very good
idea.  The output is now:

    test=> \x
    Expanded display is on.

    test=> \df+ xx
    List of functions
    -[ RECORD 1 ]-------+--------------------
    Schema              | public
    Name                | xx
    Result data type    | text
    Argument data types |
    Volatility          | volatile
    Owner               | postgres
    Language            | sql
    Source code         | SELECT  'a'::text
                        : WHERE   1 = 1
    Description         |


Patch attached.  It substitutes spaces for the tab.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: src/bin/psql/mbprint.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/mbprint.c,v
retrieving revision 1.30
diff -c -c -r1.30 mbprint.c
*** src/bin/psql/mbprint.c    16 Apr 2008 18:18:00 -0000    1.30
--- src/bin/psql/mbprint.c    7 May 2008 20:27:39 -0000
***************
*** 315,320 ****
--- 315,328 ----
                  linewidth += 2;
                  ptr += 2;
              }
+             else if (*pwcs == '\t')        /* Tab */
+             {
+                 do
+                 {
+                     *ptr++ = ' ';
+                     linewidth++;
+                 } while (linewidth % 8 != 0);
+             }
              else if (w < 0)        /* Other control char */
              {
                  sprintf((char *) ptr, "\\x%02X", *pwcs);

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] bug in numeric_power() function
Next
From: Bruce Momjian
Date:
Subject: Re: [GENERAL] pgbench not setting scale size correctly?