Re: Proposed patch - psql wraps at window width

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Bryce Nesbitt <bryce2(at)obviously(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org, heikki(at)enterprisedb(dot)com
Subject: Re: Proposed patch - psql wraps at window width
Date: 2008-04-20 04:11:45
Message-ID: 200804200411.m3K4Bjm18947@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Bryce Nesbitt wrote:
> Bruce Momjian wrote:
> > I don't think you need to do that to get it applied --- there is nothing
> > windows-specific in your code.
> >
> > Is this ready to be applied? Do you want to send a final update or are
> > you still testing?
> >
> Looks good, but I suggest adding "give up if the header is too wide":
>
> if (tcolumns > 0 && tcolumns >= total_header_width)

OK, I have created a new version of the patch, attached. Bryce, I
included your code line above and the other changes you had in the new
version of print.c.

I also set it to use ioctl() width if the output is to the terminal, and
\pset column for other cases, and adjusted the documentation.

I played a little with how wrapping would look with values that
contained newlines:

test=> \pset format wrapped
Output format is wrapped.

test=> \pset columns 70
Target column width for "wrap" format is 70.

test=> select 1, 2, repeat('a', 80), repeat('b', 80), E'a\nb\nc', 1 from
generate_series(1,2)\g /rtmp/d


?column? | ?column? | repeat | repeat | ?column? | ?column?
----------+----------+------------+-------------+----------+----------
1 | 2 | aaaaaaaaaa | bbbbbbbbbbb | a | 1
; aaaaaaaaaa ; bbbbbbbbbbb
; aaaaaaaaaa ; bbbbbbbbbbb
; aaaaaaaaaa ; bbbbbbbbbbb
; aaaaaaaaaa ; bbbbbbbbbbb
; aaaaaaaaaa ; bbbbbbbbbbb
; aaaaaaaaaa ; bbbbbbbbbbb
; aaaaaaaaaa ; bbb
: b
: c
1 | 2 | aaaaaaaaaa | bbbbbbbbbbb | a | 1
; aaaaaaaaaa ; bbbbbbbbbbb
; aaaaaaaaaa ; bbbbbbbbbbb
; aaaaaaaaaa ; bbbbbbbbbbb
; aaaaaaaaaa ; bbbbbbbbbbb
; aaaaaaaaaa ; bbbbbbbbbbb
; aaaaaaaaaa ; bbbbbbbbbbb
; aaaaaaaaaa ; bbb
: b
: c
(2 rows)

Notice that the marker for wrapping is now ";". The marker is always on
the left edge, assuming you are not in the first column, in which case
there is no marker. This is how newline behaves and I copied that.
Also note that there is no separator for columns that don't wrap down
far enough. This is also how the newline case is handled. Is this the
way we want it to display? (Bryce, I am not sure your original code
handled this right.)

So, a query with only one column is going to be unclear whether it has
embedded newlines or wrapping has happening. One idea is for wrapping to
place a dash at the end of the value, so you have:

aaaaaaaaaa-
aaaaaaaaaa-
aaaa

or something like that.

Another issue is whether newlines should filter up into the rows already
used for wrapping in adjacent columns. Right now it doesn't do that but
we could.

I found a problem with the original patch related to multibyte. The code
was fine up until the wrapping happened, at which point 'width' was
assumed to equal characters and the value was chopped into width "byte"
chunks. It has to be done in width "character" chunks so each chunk has
the same number of characters and you don't split a multi-byte character
across a line. I fixed it by creating a new function
mb_strlen_max_width().

I also restructured some of the code and added comments.

Community, I am looking for feedback on how to handle some of my
questions above.

Bryce, I am sorry this patch is taking so many iterations but the
feature has to work perfectly in lots of complex configurations so it
takes longer to complete and apply.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

Attachment Content-Type Size
/pgpatches/wrap text/x-diff 31.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bryce Nesbitt 2008-04-20 06:46:32 Re: Proposed patch - psql wraps at window width
Previous Message Joshua D. Drake 2008-04-20 00:15:17 Re: get rid of psql welcome message

Browse pgsql-patches by date

  From Date Subject
Next Message Zoltan Boszormenyi 2008-04-20 05:14:03 Re: float4/float8/int64 passed by value with tsearch fixup
Previous Message Tom Lane 2008-04-20 01:06:47 Re: float4/float8/int64 passed by value with tsearchfixup