Re: Proposed patch - psql wraps at window width - Mailing list pgsql-hackers
From | Gregory Stark |
---|---|
Subject | Re: Proposed patch - psql wraps at window width |
Date | |
Msg-id | 87y76w4wsb.fsf@oxford.xeocode.com Whole thread Raw |
In response to | Re: Proposed patch - psql wraps at window width (Bruce Momjian <bruce@momjian.us>) |
Responses |
Re: Proposed patch - psql wraps at window width
Re: Proposed patch - psql wraps at window width |
List | pgsql-hackers |
"Bruce Momjian" <bruce@momjian.us> writes: > Gregory Stark wrote: >> "Bruce Momjian" <bruce@momjian.us> writes: >> >> > We do look at COLUMNS if the ioctl() fails, but not for file/pipe >> > output. >> >> Yeah, it looks like your most recent patch still has the bug that if the user >> specifies wrapped there are some complicated rules creating cases where it >> will ignore the user's request and use un-wrapped output instead. > > Can you be more specific? You mean if the headings don't fit? Yea, > that is true. I am thinking of adding a \pset auto format to \x in > those cases, but that if for later. [No I wasn't thinking of that, that's an interesting case too though I think we might need to think a bit harder about cases that wrap poorly. If you have long column headings we could wrap those too. But what if you have enough space for just a few characters per column and you have long text fields in those columns?] I just meant the same thing I've been on about all week. Currently the decision about whether to use wrapped mode is tied up with the decision on what width to use and the result is that we ignore -Pformat=wrapped according to some arcane set of rules. The cases where we ignore the user's selected format are quite complex and not accurately described in the documentation. They're also not accurately described by your "not for file/pipe output" description either. An accurate description would appear to be something like: <quote>Wrapped</quote> is like <literal>aligned</> but wraps to a targetwidth of <literal>\pset columns</> or the width ofthe screen (unless screensize determination fails or output has been redirected using -o or \o inwhich case it is ignoredand psql uses normal aligned mode unless \psetcolumns is used). It's confusing and inconsistent. I think it's better to pick a simple set of general principles and code to that. Trying to code to presumed use cases often ends up with code which handles corner cases poorly or inconsistently. I think the behaviour should be simply: format=autoisatty(fout) ? format := wrapped : format := aligned format=wrappedcolumns := \pset columns || ioctl(fout) || getenv(COLUMNS) || 79 [Note in the above that the ioctl is on fout, not stdout!] That would be easy to explain in the documentation as two simple consistent rules. And as a bonus it would be consistent with other programs which use these variables. So the description I would code to is simply: "Wrapped" is like aligned but wraps to \pset columns or an automaticallydetermined screen size. The screen size is determinedautomatically if outputis to a terminal which supports that, if that fails then by checking theCOLUMNS environmentvariable, and if that's unset then by defaulting to 79. "Auto" selects "wrapped" format when output is a terminal and "aligned"format otherwise. -- Gregory Stark EnterpriseDB http://www.enterprisedb.com Ask me about EnterpriseDB's Slony Replication support!
pgsql-hackers by date: