1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Add xheader_width pset option to psql

The setting controls tha maximum length of the header line in expanded
format output. Possible settings are full, column, page, or an integer.
the default is full, the current behaviour, and in this case the header
line is the length of the widest line of output. column causes the
header to be truncated to the width of the first column, page causes it
to be truncated to the width of the terminal page, and an integer causes
it to be truncated to that value. If the full value is less than the
page or integer value no truncation occurs. If given without an argument
this option prints its current setting.

Platon Pronko, somewhat modified by me.

Discussion: https://postgr.es/m/f03d38a3-db96-a56e-d1bc-dbbc80bbde4d@gmail.com
This commit is contained in:
Andrew Dunstan
2022-07-25 14:24:50 -04:00
parent b35617de37
commit a45388d6e0
7 changed files with 164 additions and 18 deletions

View File

@@ -1222,15 +1222,16 @@ cleanup:
static void
print_aligned_vertical_line(const printTextFormat *format,
const unsigned short opt_border,
print_aligned_vertical_line(const printTableOpt *topt,
unsigned long record,
unsigned int hwidth,
unsigned int dwidth,
int output_columns,
printTextRule pos,
FILE *fout)
{
const printTextLineFormat *lformat = &format->lrule[pos];
const printTextLineFormat *lformat = &get_line_style(topt)->lrule[pos];
const unsigned short opt_border = topt->border;
unsigned int i;
int reclen = 0;
@@ -1259,8 +1260,18 @@ print_aligned_vertical_line(const printTextFormat *format,
if (reclen-- <= 0)
fputs(lformat->hrule, fout);
if (reclen-- <= 0)
fputs(lformat->midvrule, fout);
if (reclen-- <= 0)
{
if (topt->expanded_header_width_type == PRINT_XHEADER_COLUMN)
{
fputs(lformat->rightvrule, fout);
}
else
{
fputs(lformat->midvrule, fout);
}
}
if (reclen-- <= 0
&& topt->expanded_header_width_type != PRINT_XHEADER_COLUMN)
fputs(lformat->hrule, fout);
}
else
@@ -1268,12 +1279,43 @@ print_aligned_vertical_line(const printTextFormat *format,
if (reclen-- <= 0)
fputc(' ', fout);
}
if (reclen < 0)
reclen = 0;
for (i = reclen; i < dwidth; i++)
fputs(opt_border > 0 ? lformat->hrule : " ", fout);
if (opt_border == 2)
fprintf(fout, "%s%s", lformat->hrule, lformat->rightvrule);
if (topt->expanded_header_width_type != PRINT_XHEADER_COLUMN)
{
if (topt->expanded_header_width_type == PRINT_XHEADER_PAGE
|| topt->expanded_header_width_type == PRINT_XHEADER_EXACT_WIDTH)
{
if (topt->expanded_header_width_type == PRINT_XHEADER_EXACT_WIDTH)
{
output_columns = topt->expanded_header_exact_width;
}
if (output_columns > 0)
{
if (opt_border == 0)
dwidth = Min(dwidth, Max(0, (int) (output_columns - hwidth)));
if (opt_border == 1)
dwidth = Min(dwidth, Max(0, (int) (output_columns - hwidth - 3)));
/*
* Handling the xheader width for border=2 doesn't make
* much sense because this format has an additional
* right border, but keep this for consistency.
*/
if (opt_border == 2)
dwidth = Min(dwidth, Max(0, (int) (output_columns - hwidth - 7)));
}
}
if (reclen < 0)
reclen = 0;
if (dwidth < reclen)
dwidth = reclen;
for (i = reclen; i < dwidth; i++)
fputs(opt_border > 0 ? lformat->hrule : " ", fout);
if (opt_border == 2)
fprintf(fout, "%s%s", lformat->hrule, lformat->rightvrule);
}
fputc('\n', fout);
}
@@ -1570,11 +1612,12 @@ print_aligned_vertical(const printTableContent *cont,
lhwidth++; /* for newline indicators */
if (!opt_tuples_only)
print_aligned_vertical_line(format, opt_border, record++,
lhwidth, dwidth, pos, fout);
print_aligned_vertical_line(cont->opt, record++,
lhwidth, dwidth, output_columns,
pos, fout);
else if (i != 0 || !cont->opt->start_table || opt_border == 2)
print_aligned_vertical_line(format, opt_border, 0, lhwidth,
dwidth, pos, fout);
print_aligned_vertical_line(cont->opt, 0, lhwidth,
dwidth, output_columns, pos, fout);
}
/* Format the header */
@@ -1760,8 +1803,8 @@ print_aligned_vertical(const printTableContent *cont,
if (cont->opt->stop_table)
{
if (opt_border == 2 && !cancel_pressed)
print_aligned_vertical_line(format, opt_border, 0, hwidth, dwidth,
PRINT_RULE_BOTTOM, fout);
print_aligned_vertical_line(cont->opt, 0, hwidth, dwidth,
output_columns, PRINT_RULE_BOTTOM, fout);
/* print footers */
if (!opt_tuples_only && cont->footers != NULL && !cancel_pressed)