Re: Proposed patch - psql wraps at window width - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: Proposed patch - psql wraps at window width
Date
Msg-id 200805052339.m45NdxB08562@momjian.us
Whole thread Raw
In response to Re: Proposed patch - psql wraps at window width  (Bryce Nesbitt <bryce2@obviously.com>)
Responses Re: Proposed patch - psql wraps at window width  (Gregory Stark <stark@enterprisedb.com>)
Re: Proposed patch - psql wraps at window width  (Bruce Momjian <bruce@momjian.us>)
List pgsql-hackers
Bryce Nesbitt wrote:
> 
> > OK, so COLUMNS should take precedence.  I assume this is going to
> > require us to read the COLUMNS environment variable in psql _before_
> > readline sets it, and that COLUMNS will only affect screen output, like
> > ioctl().  Is that consistent?
> >   
> This whole thing is confusing enough at the point, I think a complete 
> proposal needs to be articulated. It is hard to comment on a fragment of 
> an idea.
> 
> The main cases to cover are:  (1) how to specify wrap for tty's

In order of precedence:
\pset columns$COLUMNSiotcl()

>  (2) how to specify wrap for pipes
\pset columns

> (3) how to get wrapped on platforms that don't 
> have the ioctl (presumably windows without cygwin)   
\pset columns$COLUMNS

> (4) how to set up 
> different defaults for tty's and pipes (e.g. wrap interactive tty's, but 
> leave output aligned for scripts).
> 
> And perhaps, as a bonus comment on (5) the idea of having psql NOT 
> source .psqlrc
      -X      --no-psqlrc

> I hope at some point someone will actually try the actual core wrapping 
> code, and comment on it.

I tested it and it worked well once I modified it.

Updated patch with clearer documentation that matches the above
behavior:
ftp://momjian.us/pub/postgresql/mypatches/wrap

FYI, I looked into 'ls -C' hanlding a little more and ls (GNU coreutils)
5.97 honors COLUMNS _only_ in file/pipe output, not for screen output. 
What the C code does is to read COLUMNS, then overwrite that value with
ioctl() if it works.

Do we want to follow that behavior?  ls has a '-w' option to specify the
width, like our \pset columns.  However, the manual page seems backwards:
      -w, --width=COLS             assume screen width instead of current value

The GNU 'ls' manual does not mention COLUMNS.

BSD 'ls' used COLUMNS only when outputing to the screen, and ioctl
fails.  However, the BSD manual says:
    COLUMNS    If this variable contains a string representing a decimal    integer, it is used as the column position
widthfor    displaying multiple-text-column output.  The ls utility    calculates how many pathname text columns to
displaybased    on the width pro- vided.  (See -C.)
 

Again, I think the manual is wrong.

So it seem GNU ls and BSD ls are inconsistent, which I think means we
should design our API the best we can, rather than rely on how others
interpret COLUMNS.

--  Bruce Momjian  <bruce@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +


pgsql-hackers by date:

Previous
From: Greg Smith
Date:
Subject: Re: [0/4] Proposal of SE-PostgreSQL patches
Next
From: Bruce Momjian
Date:
Subject: Re: Proposed patch - psql wraps at window width