From: | Gregory Stark <stark(at)enterprisedb(dot)com> |
---|---|
To: | "Bruce Momjian" <bruce(at)momjian(dot)us> |
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 12:05:35 |
Message-ID: | 87bq3z8nlc.fsf@oxford.xeocode.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-patches |
"Bruce Momjian" <bruce(at)momjian(dot)us> writes:
> Gregory Stark wrote:
>
>> Earlier I suggested -- and nobody refuted -- that we should follow the
>> precedents of ls and man and other tools which need to find the terminal
>> width: Explicitly set width takes precedence always, if it's not explicitly
>> set then you use the ioctl, and if that fails then you use the COLUMNS
>> environment variable.
>
> Yes, I like that better. Patch updated, same URL:
>
> ftp://momjian.us/pub/postgresql/mypatches/wrap
I think it should just be:
if (opt->format == PRINT_WRAP)
{
/* Get terminal width -- explicit setting takes precedence */
output_columns = opt->columns;
#ifdef TIOCGWINSZ
if (output_columns == 0 && isatty(fout))
{
struct winsize screen_size;
if (ioctl(fileno(fout), TIOCGWINSZ, &screen_size) != -1)
output_columns = screen_size.ws_col;
}
#endif
if (output_columns == 0)
{
const char *columns_env = getenv("COLUMNS");
if (columns_env)
output_columns = atoi(columns_env);
}
if (output_columns == 0)
output_columns = 79;
}
The differences this makes are that:
a) if you do -o /dev/tty (perhaps on some kind of cronjob) it will use the
ioctl.
b) If you dump to a file it will still respect COLUMNS. This might be a bit
weird since bash sets COLUMNS so your file width will be based on the size
of your terminal. But people also do things like COLUMNS=120 psql -o f ...
--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's 24x7 Postgres support!
From | Date | Subject | |
---|---|---|---|
Next Message | ITAGAKI Takahiro | 2008-04-24 12:11:37 | Re: Index AM change proposals, redux |
Previous Message | Simon Riggs | 2008-04-24 11:52:30 | Re: Index AM change proposals, redux |
From | Date | Subject | |
---|---|---|---|
Next Message | Albe Laurenz | 2008-04-24 12:22:20 | Re: Improve shutdown during online backup, take 4 |
Previous Message | Euler Taveira de Oliveira | 2008-04-24 04:51:40 | Re: lc_time and localized dates |