Re: Proposed patch - psql wraps at window width

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
Cc: Brendan Jurd <direvus(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Bryce Nesbitt <bryce2(at)obviously(dot)com>, heikki(at)enterprisedb(dot)com
Subject: Re: Proposed patch - psql wraps at window width
Date: 2008-04-24 19:52:10
Message-ID: 200804241952.m3OJqAh17966@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Gregory Stark wrote:
> "Bruce Momjian" <bruce(at)momjian(dot)us> writes:
>
> > 'ls' and 'ls | more' generate different outputs, and I have never heard
> > anyone call that "bunk".
>
> The analogue of that would be making psql default to wrapped mode if isatty is
> true and normal mode if it's false. I wouldn't be entirely against that but I
> don't really care much either way.

Yea, we have to discuss any default changes once we are done.

> Note that there's still -C and -1 to override that default. And if you specify
> -C or isatty returns true it *always* uses the same deterministic logic to
> determine the width: -w first, then ioctl, then COLUMNS.

Interesting. That is a powerful argument. I see if I do:

ls -C > /tmp/x

/tmp/x is wrapped, but if I make the window wider (on Ubuntu), the file
ouput is not wider. It seems to default to 72 columns as a target, even
though $COLUMNS is updated. This seems to indicate that 'ls' doesn't
check the terminal width at all when doing output.

What that would translate into for psql is that the interactive behavior
is as posted in the patch (try ioctl, then try $COLUMNS), but for
file/pipe, wrap is to 72 but can be overridden with \pset columns.

> > Also, this does work:
> >
> > psql -Pformat=wrapped -Pcolumns=70 -c "select repeat('a', 100)" test | more
> >
> > If you want non-terminal output to wrap, you have to specify the width
> > --- that seems only reasonable because the file case really needs to
> > have the width specified.
>
> No it's not reasonable. I promise you users will report this as a bug.
>
> This isn't anything new. Offhand I could only think of two precedents, ls and
> man, but I'm sure there are others. They both use the same basic logic. And
> not just GNU, FreeBSD and Solaris document the same behaviour.
>
> I'm puzzled what you think should happen for the above. You think it should
> just ignore the user's -Pformat=wrapped ?

Well, I have two people who don't want wrap to ever affect file/pipe
output, and now have two who want wrapped to try to affect file/pipe,
even if it has to read $COLUMNS. Obviously someone is going to be
unhappy in the end.

The only distinction I can think of is that 'ls' uses per-command flags,
while psql \pset format is for all commands, but you are kind of right
it is like 'ls'.

I can modify the patch for further review. I need feedback.

--
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. +

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Gregory Stark 2008-04-24 20:17:44 Re: Proposed patch - psql wraps at window width
Previous Message Simon Riggs 2008-04-24 19:28:19 Re: MERGE Specification

Browse pgsql-patches by date

  From Date Subject
Next Message Peter Eisentraut 2008-04-24 19:52:37 Re: BUG #4128: The postmaster.opts.default file is begin ignored
Previous Message Bruce Momjian 2008-04-24 19:22:16 Re: Proposed patch - psql wraps at window width