Hi. Thanks for your review.
2014-02-15 20:08 GMT+04:00 Emre Hasegeli <e...@hasegeli.com>: > Hi, > > This is my review about 3th version of the patch. It is an useful > improvement in my opinion. It worked well on my environment. > > 2013-12-11 17:43:06, Sergey Muraviov <sergey.k.murav...@gmail.com>: > > It works in expanded mode when either format option is set to wrapped > > (\pset format wrapped), or we have no pager, or pager doesn't chop long > > lines (so you can still use the trick). > > I do not like this logic on the IsWrappingNeeded function. It does not > seems right to check the environment variables for less. It would be hard > to explain this behavior to the users. It is better to make this only > the behavior of the wrapped format in expanded mode, in my opinion. > You are right. This logic is too complicated. New patch works with PRINT_WRAPPED option only. > > { > > if (opt_border < 2) > > fprintf(fout, "%s\n", > dlineptr[line_count].ptr); > > else > > fprintf(fout, "%-s%*s > %s\n", dlineptr[line_count].ptr, > > dwidth - > dlineptr[line_count].width, "", > > > dformat->rightvrule); > > } > > Is it necessary to keep this old print line code? It seems to me the new > code works well on (dlineptr[line_count].width <= dwidth) condition. > New code doesn't work with empty strings but I've done minor optimization for this case. -- Best regards, Sergey Muraviov
From 48ba7ed8c5ff82cdc1c912ff9ac966962f18ce54 Mon Sep 17 00:00:00 2001 From: Sergey Muraviov <sergey.k.murav...@gmail.com> Date: Sun, 16 Feb 2014 20:00:10 +0400 Subject: [PATCH] Now patch works with PRINT_WRAPPED option only --- src/bin/psql/print.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 71 insertions(+), 8 deletions(-) diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c index 79fc43e..d7bf412 100644 --- a/src/bin/psql/print.c +++ b/src/bin/psql/print.c @@ -1234,6 +1234,45 @@ 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++) { @@ -1292,20 +1331,45 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout) else fputc(' ', fout); - if (!dcomplete) + if ((!dcomplete) && (dlineptr[line_count].width > 0)) { - if (opt_border < 2) - fprintf(fout, "%s\n", dlineptr[line_count].ptr); - else - fprintf(fout, "%-s%*s %s\n", dlineptr[line_count].ptr, - dwidth - dlineptr[line_count].width, "", - dformat->rightvrule); + int offset = 0; + int chars_to_output = dlineptr[line_count].width; + while (chars_to_output > 0) + { + int target_width, bytes_to_output; + if (offset > 0) + { + if (opt_border == 2) + fprintf(fout, "%s ", dformat->leftvrule); + + fprintf(fout, "%*s", hwidth, " "); + + if (opt_border > 0) + fprintf(fout, " %s ", dformat->midvrule); + else + fputc(' ', fout); + } + + target_width = dwidth; + bytes_to_output = strlen_max_width(dlineptr[line_count].ptr + offset, + &target_width, encoding); + fputnbytes(fout, (char *)(dlineptr[line_count].ptr + offset), bytes_to_output); + chars_to_output -= target_width; + offset += bytes_to_output; + + if (opt_border < 2) + fputc('\n', fout); + else + fprintf(fout, "%*s %s\n", dwidth - target_width, "", dformat->rightvrule); + } if (!dlineptr[line_count + 1].ptr) dcomplete = 1; } else { + dcomplete = 1; if (opt_border < 2) fputc('\n', fout); else @@ -2175,7 +2239,6 @@ print_troff_ms_vertical(const printTableContent *cont, FILE *fout) /* Public functions */ /********************************/ - /* * PageOutput * -- 1.8.5.3
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers