Re: Unicode UTF-8 table formatting for psql text output - Mailing list pgsql-hackers

From Roger Leigh
Subject Re: Unicode UTF-8 table formatting for psql text output
Date
Msg-id 20090823004901.GA10788@codelibre.net
Whole thread Raw
In response to Re: Unicode UTF-8 table formatting for psql text output  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Unicode UTF-8 table formatting for psql text output  (Greg Stark <gsstark@mit.edu>)
Re: Unicode UTF-8 table formatting for psql text output  (Roger Leigh <rleigh@codelibre.net>)
Re: Unicode UTF-8 table formatting for psql text output  (Alvaro Herrera <alvherre@commandprompt.com>)
List pgsql-hackers
On Sat, Aug 22, 2009 at 07:42:10PM -0400, Robert Haas wrote:
> On Sat, Aug 22, 2009 at 2:13 PM, Roger Leigh<rleigh@debian.org> wrote:
> > Further minor cleanups to tweak column alignment in a corner case,
> > and to correct indentation to match the rest of the code.
>
> Please read the guidelines here:
> http://wiki.postgresql.org/wiki/Submitting_a_Patch
>
> I don't think it's very helpful to submit a patch intended to do
> basically one thing split up over 10 threads.  The PostgreSQL style is
> heavyweight commits, and I don't believe that there's any reason to
> suppose that someone would want to commit any one of these 9 pieces
> without the other 8.

OK.  I have attached a single patch which combines the nine patches
into one.  I did read the patch page above, but it didn't mention
anything on patch size, so I split it into incremental logical
changes in order to make it easily reviewable.  6-9 can be viewed
as a whole, since 7-9 are minor fixes to 6.

The other information requested on that page:

project: postgresql
patch name: psql-utf8-table-1.patch
purpose: adds support for Unicode UTF-8 box drawing to the text
  table drawing functions print_aligned_text and
  print_aligned_vertical.
for: discussion or application.  Testing shows identical formatting
  to current code.
branch: HEAD
compiles: yes
platform-specific: POSIX, but contains appropriate preprocessor
  conditionals for portability.  Not tested on non-POSIX platform,
  but conditional taken from elsewhere (port/chklocale.c).  Only
  two lines of the patch are platform-specific, the rest is
  plain portable C.
regression tests: No.  I'm not aware of any psql regression tests
  testing output formatting.
  Manually confirmed output is unchanged with border=0/1/2 and
  expanded=0/1.
use: Use a locale with LC_CTYPE CODESET=UTF-8.
performance: Not tested, but should be minimal effect.  There's
  an additional pointer dereference during string formatting
  in some places.  Temporary copies of data are used in some
  functions e.g. of format->lrule[] for convenience and to potentially
  save on the number of dereferences, though any optimising compiler
  should make this cost zero (all data and pointers are const).
comments:

psql: Abstract table formatting characters used for different line types.

printTextLineFormat describes the characters used to draw vertical lines across
a horizontal rule at the left side, middle and right hand side. These are
included in the formatting for an entire table (printTextFormat).  The
printTextRule enum is used as an offset into the printTextFormat line rules
(lrule), allowing specification of line styles for the top, middle and bottom
horizontal lines in a table.  The other printTextFormat members, hrule and
vrule define the formatting needed to draw horizontal and vertical rules.
Add table formats for ASCII and UTF-8.  Default to using the ASCII table.
However, if a UTF-8 locale codeset is in use, switch to the UTF-8 table.
print_aligned_text and print_aligned_vertical, and their helper fuctions pass
the table formatting and (where applicable) line style information to allow
correct printing of table lines.
Convert print_aligned_text, and its helper function, to use table formatting in
place of hardcoded ASCII characters.  Convert print_aligned_vertical to use
table formatting in place of hardcoded ASCII characters, and add helper
function print_aligned_vertical_line to format individual lines.


Regards,
Roger

--
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.

Attachment

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Unicode UTF-8 table formatting for psql text output
Next
From: Robert Haas
Date:
Subject: 8.5 release timetable, again