I hope that I realized old-ascii logic correctly.
2014-04-11 19:10 GMT+04:00 Greg Stark <st...@mit.edu>: > Looks good. > > It's still not doing the old-ascii column dividers but to be honest > I'm not sure what the intended behaviour of old-ascii is. I've noticed > old-ascii only displays the line markers for dividing lines, not the > final one. That seems pretty useless and maybe it's why we switched to > the new "ascii" mode, I don't recall. > > This is the way old-ascii displays when two columns are wrapping -- it > seems pretty confused to me. The headers are displaying newline > markers from the ascii style instead of : indicators in the dividing > line. The : and ; markers are only displayed for the first column, not > the second one. > > Maybe since the : and ; markers aren't shown for the final column that > means the expanded mode doesn't have to do anything since the column > is only ever the final column. > > > +--------------------+-----------------+ > | x | x | > |+ y |+ y | > |+ z |+ z | > +--------------------+-----------------+ > | x | xxxxxxxxxxxxxxx | > | xx ; xxxx | > | xxx : xxxxxxxxxxxxxxx | > | xxxx ; xxx | > | xxxxx : xxxxxxxxxxxxxxx | > | xxxxxx ; xx | > | xxxxxxx : xxxxxxxxxxxxxxx | > | xxxxxxxx ; x | > | xxxxxxxxx : xxxxxxxxxxxxxxx | > | xxxxxxxxxx : xxxxxxxxxxxxxx | > | xxxxxxxxxxx : xxxxxxxxxxxxx | > | xxxxxxxxxxxx : xxxxxxxxxxxx | > | xxxxxxxxxxxxx : xxxxxxxxxxx | > | xxxxxxxxxxxxxx : xxxxxxxxxx | > | xxxxxxxxxxxxxxx : xxxxxxxxx | > | xxxxxxxxxxxxxxxx : xxxxxxxx | > | xxxxxxxxxxxxxxxxx : xxxxxxx | > | xxxxxxxxxxxxxxxxxx : xxxxxx | > | xxxxxxxxxxxxxxxxxx : xxxxx | > | x : xxxx | > | xxxxxxxxxxxxxxxxxx : xxx | > | xx : xx | > | xxxxxxxxxxxxxxxxxx : x | > | xxx : | > | xxxxxxxxxxxxxxxxxx : | > | xxxx : | > | xxxxxxxxxxxxxxxxxx : | > | xxxxx : | > | xxxxxxxxxxxxxxxxxx : | > | xxxxxx | > | xxxxxxxxxxxxxxxxxx | > | xxxxxxx | > +--------------------+-----------------+ > -- Best regards, Sergey Muraviov
From 69d845f05864a5d07a90ee20e10a5cb09b78d1d3 Mon Sep 17 00:00:00 2001 From: Sergey Muraviov <sergey.k.murav...@gmail.com> Date: Fri, 11 Apr 2014 20:55:17 +0400 Subject: [PATCH] Support for old-ascii mode --- src/bin/psql/print.c | 144 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 122 insertions(+), 22 deletions(-) diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c index 79fc43e..2c58cb5 100644 --- a/src/bin/psql/print.c +++ b/src/bin/psql/print.c @@ -1234,13 +1234,56 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout) fprintf(fout, "%s\n", cont->title); } + if (cont->opt->format == PRINT_WRAPPED) + { + int output_columns = 0; + + /* + * Choose target output width: \pset columns, or $COLUMNS, or ioctl + */ + if (cont->opt->columns > 0) + output_columns = cont->opt->columns; + else + { + 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 + } + + output_columns -= hwidth; + + if (opt_border == 0) + output_columns -= 1; + else + { + output_columns -= 3; /* -+- */ + + if (opt_border > 1) + output_columns -= 4; /* +--+ */ + } + + if (output_columns > 0 && dwidth > output_columns) + dwidth = output_columns; + } + /* print records */ for (i = 0, ptr = cont->cells; *ptr; i++, ptr++) { printTextRule pos; - int line_count, + int dline, + hline, dcomplete, - hcomplete; + hcomplete, + offset, + chars_to_output; if (cancel_pressed) break; @@ -1270,48 +1313,105 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout) pg_wcsformat((const unsigned char *) *ptr, strlen(*ptr), encoding, dlineptr, dheight); - line_count = 0; + dline = hline = 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); + fputs(dformat->leftvrule, fout); + + /* Header */ if (!hcomplete) { - fprintf(fout, "%-s%*s", hlineptr[line_count].ptr, - hwidth - hlineptr[line_count].width, ""); + int swidth = hwidth - hlineptr[hline].width - 1; + fputs(hline? format->header_nl_left: " ", fout); + fprintf(fout, "%-s", hlineptr[hline].ptr); + if (swidth > 0) /* spacer */ + fprintf(fout, "%*s", swidth, ""); - if (!hlineptr[line_count + 1].ptr) + if (!hlineptr[hline + 1].ptr) + { + fputs(" ", fout); hcomplete = 1; + } + else + { + fputs(format->header_nl_right, fout); + hline++; + } } else - fprintf(fout, "%*s", hwidth, ""); + fprintf(fout, "%*s", hwidth + 2, ""); - if (opt_border > 0) - fprintf(fout, " %s ", dformat->midvrule); - else - fputc(' ', fout); + /* 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); + } + /* Data */ if (!dcomplete) { - if (opt_border < 2) - fprintf(fout, "%s\n", dlineptr[line_count].ptr); + 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) + { + if (!dlineptr[dline + 1].ptr) + { + fputs(" ", fout); + dcomplete = 1; + } + else + { + fputs(format->nl_right, fout); + dline++; + offset = 0; + chars_to_output = dlineptr[dline].width; + } + } else - fprintf(fout, "%-s%*s %s\n", dlineptr[line_count].ptr, - dwidth - dlineptr[line_count].width, "", - dformat->rightvrule); + fputs(format->wrap_right, fout); + + if (opt_border == 2) + fputs(dformat->rightvrule, fout); - if (!dlineptr[line_count + 1].ptr) - dcomplete = 1; + fputs("\n", fout); } else { if (opt_border < 2) - fputc('\n', fout); + fputs("\n", fout); else - fprintf(fout, "%*s %s\n", dwidth, "", dformat->rightvrule); + fprintf(fout, "%*s %s\n", dwidth, "", dformat->rightvrule); } - line_count++; } } -- 1.9.0
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers