1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Revert psql changes to support wrapped expanded mode. That feature is

nice and we'll keep it in 9.5 but it'll take more time to iron out the
collateral damage on other queries and also on tools like
check_postgres.

revert dbe31616c9
revert 6513633b94
This commit is contained in:
Greg Stark
2014-08-18 11:28:57 +01:00
parent f304ddc5ce
commit 7e81c4b290
3 changed files with 23 additions and 1232 deletions

View File

@ -1161,7 +1161,6 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
struct lineptr *hlineptr,
*dlineptr;
bool is_pager = false;
int output_columns = 0; /* Width of interactive console */
if (cancel_pressed)
return;
@ -1235,90 +1234,24 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
fprintf(fout, "%s\n", cont->title);
}
/*
* Choose target output width: \pset columns, or $COLUMNS, or ioctl
*/
if (cont->opt->columns > 0)
output_columns = cont->opt->columns;
else if ((fout == stdout && isatty(fileno(stdout))) || is_pager)
{
if (cont->opt->env_columns > 0)
output_columns = cont->opt->env_columns;
#ifdef TIOCGWINSZ
else
{
struct winsize screen_size;
if (ioctl(fileno(stdout), TIOCGWINSZ, &screen_size) != -1)
output_columns = screen_size.ws_col;
}
#endif
}
if (cont->opt->format == PRINT_WRAPPED)
{
/*
* Calculate the available width to wrap the columns to after
* subtracting the maximum header width and separators. At a minimum
* enough to print "[ RECORD N ]"
*/
unsigned int width,
swidth;
if (opt_border == 0)
swidth = 1; /* "header data" */
else if (opt_border == 1)
swidth = 3; /* "header | data" */
else
swidth = 7; /* "| header | data |" */
/* Wrap to maximum width */
width = dwidth + swidth + hwidth;
if ((output_columns > 0) && (width > output_columns))
{
dwidth = output_columns - hwidth - swidth;
width = output_columns;
}
/* Wrap to minimum width */
if (!opt_tuples_only)
{
int delta = 1 + log10(cont->nrows) - width;
if (opt_border == 0)
delta += 6; /* "* RECORD " */
else if (opt_border == 1)
delta += 10; /* "-[ RECORD ]" */
else
delta += 15; /* "+-[ RECORD ]-+" */
if (delta > 0)
dwidth += delta;
}
else if (dwidth < 3)
dwidth = 3;
}
/* print records */
for (i = 0, ptr = cont->cells; *ptr; i++, ptr++)
{
printTextRule pos;
int dline,
hline,
int line_count,
dcomplete,
hcomplete,
offset,
chars_to_output;
hcomplete;
if (cancel_pressed)
break;
if (i == 0)
pos = PRINT_RULE_TOP;
else if (!(*(ptr + 1)))
pos = PRINT_RULE_BOTTOM;
else
pos = PRINT_RULE_MIDDLE;
/* Print record header (e.g. "[ RECORD N ]") above each record */
if (i % cont->ncolumns == 0)
{
if (!opt_tuples_only)
@ -1337,126 +1270,48 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
pg_wcsformat((const unsigned char *) *ptr, strlen(*ptr), encoding,
dlineptr, dheight);
/*
* Loop through header and data in parallel dealing with newlines and
* wrapped lines until they're both exhausted
*/
dline = hline = 0;
line_count = 0;
dcomplete = hcomplete = 0;
offset = 0;
chars_to_output = dlineptr[dline].width;
while (!dcomplete || !hcomplete)
{
/* Left border */
if (opt_border == 2)
fprintf(fout, "%s", dformat->leftvrule);
/* Header (never wrapped so just need to deal with newlines) */
fprintf(fout, "%s ", dformat->leftvrule);
if (!hcomplete)
{
int swidth,
twidth = hwidth + 1;
fprintf(fout, "%-s%*s", hlineptr[line_count].ptr,
hwidth - hlineptr[line_count].width, "");
fputs(hline ? format->header_nl_left : " ", fout);
strlen_max_width(hlineptr[hline].ptr, &twidth,
encoding);
fprintf(fout, "%-s", hlineptr[hline].ptr);
swidth = hwidth - twidth;
if (swidth > 0) /* spacer */
fprintf(fout, "%*s", swidth, " ");
if (hlineptr[hline + 1].ptr)
{
/* More lines after this one due to a newline */
fputs(format->header_nl_right, fout);
hline++;
}
else
{
/* This was the last line of the header */
fputs(" ", fout);
if (!hlineptr[line_count + 1].ptr)
hcomplete = 1;
}
}
else
{
/* Header exhausted but more data for column */
fprintf(fout, "%*s", hwidth + 2, "");
}
fprintf(fout, "%*s", hwidth, "");
/* Separator */
if (opt_border > 0)
{
if (offset)
fputs(format->midvrule_wrap, fout);
else if (!dline)
fputs(dformat->midvrule, fout);
else if (dline)
fputs(format->midvrule_nl, fout);
else
fputs(format->midvrule_blank, fout);
}
fprintf(fout, " %s ", dformat->midvrule);
else
fputc(' ', fout);
/* Data */
if (!dcomplete)
{
int target_width,
bytes_to_output,
swidth;
fputs(!dcomplete && !offset ? " " : format->wrap_left, fout);
target_width = dwidth;
bytes_to_output = strlen_max_width(dlineptr[dline].ptr + offset,
&target_width, encoding);
fputnbytes(fout, (char *) (dlineptr[dline].ptr + offset),
bytes_to_output);
chars_to_output -= target_width;
offset += bytes_to_output;
/* spacer */
swidth = dwidth - target_width;
if (swidth > 0)
fprintf(fout, "%*s", swidth, "");
if (chars_to_output)
{
/* continuing a wrapped column */
fputs(format->wrap_right, fout);
}
else if (dlineptr[dline + 1].ptr)
{
/* reached a newline in the column */
fputs(format->nl_right, fout);
dline++;
offset = 0;
chars_to_output = dlineptr[dline].width;
}
if (opt_border < 2)
fprintf(fout, "%s\n", dlineptr[line_count].ptr);
else
{
/* reached the end of the cell */
fputs(" ", fout);
fprintf(fout, "%-s%*s %s\n", dlineptr[line_count].ptr,
dwidth - dlineptr[line_count].width, "",
dformat->rightvrule);
if (!dlineptr[line_count + 1].ptr)
dcomplete = 1;
}
if (opt_border == 2)
fputs(dformat->rightvrule, fout);
fputs("\n", fout);
}
else
{
/*
* data exhausted (this can occur if header is longer than the
* data due to newlines in the header)
*/
if (opt_border < 2)
fputs("\n", fout);
fputc('\n', fout);
else
fprintf(fout, "%*s %s\n", dwidth, "", dformat->rightvrule);
fprintf(fout, "%*s %s\n", dwidth, "", dformat->rightvrule);
}
line_count++;
}
}