So here is patch for 9.4 7 new line styles, 2 new border styles, \pset border autocomplete
Regards Pavel 2013/11/21 Szymon Guz <mabew...@gmail.com> > On 21 November 2013 08:09, Pavel Stehule <pavel.steh...@gmail.com> wrote: > >> Hello >> >> I wrote new styles for psql table borders. >> >> http://postgres.cz/wiki/Pretty_borders_in_psql >> >> This patch is simply and I am think so some styles can be interesting for >> final presentation. >> >> Do you think so this feature is generally interesting and should be in >> core? >> >> Regards >> >> Pavel >> > > YES! > > - Szymon >
commit 170c25a680a43a9bd96e2ca923cbd2492d35ceda Author: root <root@localhost.localdomain> Date: Thu Nov 21 20:16:00 2013 +0100 initial diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 638d8cb..7b2b621 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -2271,7 +2271,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet) psql_error("\\pset: allowed formats are unaligned, aligned, wrapped, html, latex, troff-ms\n"); return false; } - } /* set table line style */ @@ -2285,12 +2284,27 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet) popt->topt.line_style = &pg_asciiformat_old; else if (pg_strncasecmp("unicode", value, vallen) == 0) popt->topt.line_style = &pg_utf8format; + else if (pg_strncasecmp("unicode2", value, vallen) == 0) + popt->topt.line_style = &pg_utf8format2; + else if (pg_strncasecmp("unicode-double1", value, vallen) == 0) + popt->topt.line_style = &pg_utf8double1format; + else if (pg_strncasecmp("unicode-double2", value, vallen) == 0) + popt->topt.line_style = &pg_utf8double2format; + else if (pg_strncasecmp("unicode-double3", value, vallen) == 0) + popt->topt.line_style = &pg_utf8double3format; + else if (pg_strncasecmp("unicode-double4", value, vallen) == 0) + popt->topt.line_style = &pg_utf8double4format; + else if (pg_strncasecmp("unicode-double5", value, vallen) == 0) + popt->topt.line_style = &pg_utf8double5format; + else if (pg_strncasecmp("unicode-bold1", value, vallen) == 0) + popt->topt.line_style = &pg_utf8bold1format; + else if (pg_strncasecmp("unicode-bold2", value, vallen) == 0) + popt->topt.line_style = &pg_utf8bold2format; else { psql_error("\\pset: allowed line styles are ascii, old-ascii, unicode\n"); return false; } - } /* set border style/width */ @@ -2298,7 +2312,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet) { if (value) popt->topt.border = atoi(value); - } /* set expanded/vertical mode */ diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c index 736225c..6f4473a 100644 --- a/src/bin/psql/print.c +++ b/src/bin/psql/print.c @@ -54,6 +54,8 @@ const printTextFormat pg_asciiformat = {"-", "+", "+", "+"}, {"-", "+", "+", "+"}, {"-", "+", "+", "+"}, + {"-", "+", "+", "+"}, + {"", "|", "|", "|"}, {"", "|", "|", "|"} }, "|", @@ -75,6 +77,8 @@ const printTextFormat pg_asciiformat_old = {"-", "+", "+", "+"}, {"-", "+", "+", "+"}, {"-", "+", "+", "+"}, + {"-", "+", "+", "+"}, + {"", "|", "|", "|"}, {"", "|", "|", "|"} }, ":", @@ -97,9 +101,13 @@ const printTextFormat pg_utf8format = {"\342\224\200", "\342\224\214", "\342\224\254", "\342\224\220"}, /* ─, ├, ┼, ┤ */ {"\342\224\200", "\342\224\234", "\342\224\274", "\342\224\244"}, + /* ─, ├, ┼, ┤ */ + {"\342\224\200", "\342\224\234", "\342\224\274", "\342\224\244"}, /* ─, └, ┴, ┘ */ {"\342\224\200", "\342\224\224", "\342\224\264", "\342\224\230"}, /* N/A, │, │, │ */ + {"", "\342\224\202", "\342\224\202", "\342\224\202"}, + /* N/A, │, │, │ */ {"", "\342\224\202", "\342\224\202", "\342\224\202"} }, /* │ */ @@ -121,6 +129,253 @@ const printTextFormat pg_utf8format = true }; +const printTextFormat pg_utf8format2 = { + "unicode2", + { + /* ─, ┌, ┬, ┐ */ + {"\342\224\200", "\342\224\214", "\342\224\254", "\342\224\220"}, + /* ─, ├, ┴, ┤ */ + {"\342\224\200", "\342\224\234", "\342\224\264", "\342\224\244"}, + /* ─, ├, ┼, ┤ */ + {"\342\224\200", "\342\224\234", "\342\224\274", "\342\224\244"}, + /* ─, └, ─, ┘ */ + {"\342\224\200", "\342\224\224", "\342\224\200", "\342\224\230"}, + /* N/A, │, │, │ */ + {"", "\342\224\202", "\342\224\202", "\342\224\202"}, + /* N/A, │, │, │ */ + {"", "\342\224\202", "\342\224\202", "\342\224\202"} + }, + /* │ */ + "\342\224\202", + /* │ */ + "\342\224\202", + /* │ */ + "\342\224\202", + " ", + " ", + " ", + " ", + " ", + " ", + false +}; + +const printTextFormat pg_utf8double1format = { + "unicode-double1", + { + /* ═, ╔, ╤, ╗ */ + {"\342\225\220", "\342\225\224", "\342\225\244", "\342\225\227"}, + /* ─, ╟, ┼, ╢ */ + {"\342\224\200", "\342\225\237", "\342\224\274", "\342\225\242"}, + /* ─, ╟, ┼, ╢ */ + {"\342\224\200", "\342\225\237", "\342\224\274", "\342\225\242"}, + /* ═, ╚, ╧, ╝ */ + {"\342\225\220", "\342\225\232", "\342\225\247", "\342\225\235"}, + /* N/A, ║, │, ║ */ + {"", "\342\225\221", "\342\224\202", "\342\225\221"}, + /* N/A, ║, │, ║ */ + {"", "\342\225\221", "\342\224\202", "\342\225\221"} + }, + /* │ */ + "\342\224\202", + /* │ */ + "\342\224\202", + /* │ */ + "\342\224\202", + " ", + " ", + " ", + " ", + " ", + " ", + false +}; + +const printTextFormat pg_utf8double2format = { + "unicode-double2", + { + /* ═, ╔, ╤, ╗ */ + {"\342\225\220", "\342\225\224", "\342\225\244", "\342\225\227"}, + /* ═, ╠, ╪, ╣ */ + {"\342\225\220", "\342\225\240", "\342\225\252", "\342\225\243"}, + /* ─, ╟, ┼, ╢ */ + {"\342\224\200", "\342\225\237", "\342\224\274", "\342\225\242"}, + /* ═, ╚, ╧, ╝ */ + {"\342\225\220", "\342\225\232", "\342\225\247", "\342\225\235"}, + /* N/A, ║, │, ║ */ + {"", "\342\225\221", "\342\224\202", "\342\225\221"}, + /* N/A, ║, │, ║ */ + {"", "\342\225\221", "\342\224\202", "\342\225\221"} + }, + /* │ */ + "\342\224\202", + /* │ */ + "\342\224\202", + /* │ */ + "\342\224\202", + " ", + " ", + " ", + " ", + " ", + " ", + false +}; + +const printTextFormat pg_utf8double3format = { + "unicode-double3", + { + /* ═, ╔, ╦, ╗ */ + {"\342\225\220", "\342\225\224", "\342\225\246", "\342\225\227"}, + /* ═, ╠, ╩, ╣ */ + {"\342\225\220", "\342\225\240", "\342\225\251", "\342\225\243"}, + /* ─, ╟, ┼, ╢ */ + {"\342\224\200", "\342\225\237", "\342\224\274", "\342\225\242"}, + /* ═, ╚, ═, ╝ */ + {"\342\225\220", "\342\225\232", "\342\225\220", "\342\225\235"}, + /* N/A, ║, ║, ║ */ + {"", "\342\225\221", "\342\225\221", "\342\225\221"}, + /* N/A, ║, │, ║ */ + {"", "\342\225\221", "\342\224\202", "\342\225\221"}, + }, + /* │ */ + "\342\224\202", + /* │ */ + "\342\224\202", + /* │ */ + "\342\224\202", + " ", + " ", + " ", + " ", + " ", + " ", + false +}; + +const printTextFormat pg_utf8double4format = { + "unicode-double4", + { + /* ═, ╔, ╦, ╗ */ + {"\342\225\220", "\342\225\224", "\342\225\246", "\342\225\227"}, + /* ═, ╠, ╬, ╣ */ + {"\342\225\220", "\342\225\240", "\342\225\254", "\342\225\243"}, + /* ─, ╟, ╫, ╢ */ + {"\342\224\200", "\342\225\237", "\342\225\253", "\342\225\242"}, + /* ═, ╚, ╩, ╝ */ + {"\342\225\220", "\342\225\232", "\342\225\251", "\342\225\235"}, + /* N/A, ║, ║, ║ */ + {"", "\342\225\221", "\342\225\221", "\342\225\221"}, + /* N/A, ║, ║, ║ */ + {"", "\342\225\221", "\342\225\221", "\342\225\221"} + }, + /* ║ */ + "\342\225\221", + /* ║ */ + "\342\225\221", + /* ║ */ + "\342\225\221", + " ", + " ", + " ", + " ", + " ", + " ", + false +}; + +const printTextFormat pg_utf8double5format = { + "unicode-double5", + { + /* ─, ┌, ┬, ┐ */ + {"\342\224\200", "\342\224\214", "\342\224\254", "\342\224\220"}, + /* ═, ╞, ╪, ╡ */ + {"\342\225\220", "\342\225\236", "\342\225\252", "\342\225\241"}, + /* ─, ├, ┼, ┤ */ + {"\342\224\200", "\342\224\234", "\342\224\274", "\342\224\244"}, + /* ─, └, ┴, ┘ */ + {"\342\224\200", "\342\224\224", "\342\224\264", "\342\224\230"}, + /* N/A, │, │, │ */ + {"", "\342\224\202", "\342\224\202", "\342\224\202"}, + /* N/A, │, │, │ */ + {"", "\342\224\202", "\342\224\202", "\342\224\202"} + }, + /* │ */ + "\342\224\202", + /* │ */ + "\342\224\202", + /* │ */ + "\342\224\202", + " ", + " ", + " ", + " ", + " ", + " ", + false +}; + +const printTextFormat pg_utf8bold1format = { + "unicode-bold1", + { + /* ─, ┌, ┬, ┐ */ + {"\342\224\200", "\342\224\214", "\342\224\254", "\342\224\220"}, + /* ━, ┝, ┿, ┥ */ + {"\342\224\201", "\342\224\235", "\342\224\277", "\342\224\245"}, + /* ─, ├, ┼, ┤ */ + {"\342\224\200", "\342\224\234", "\342\224\274", "\342\224\244"}, + /* ─, └, ┴, ┘ */ + {"\342\224\200", "\342\224\224", "\342\224\264", "\342\224\230"}, + /* N/A, │, │, │ */ + {"", "\342\224\202", "\342\224\202", "\342\224\202"}, + /* N/A, │, │, │ */ + {"", "\342\224\202", "\342\224\202", "\342\224\202"} + }, + /* │ */ + "\342\224\202", + /* │ */ + "\342\224\202", + /* │ */ + "\342\224\202", + " ", + " ", + " ", + " ", + " ", + " ", + false +}; + +const printTextFormat pg_utf8bold2format = { + "unicode-bold2", + { + /* ━, ┏, ┯, ┓ */ + {"\342\224\201", "\342\224\217", "\342\224\257", "\342\224\223"}, + /* ━, ┣, ┿, ┫ */ + {"\342\224\201", "\342\224\243", "\342\224\277", "\342\224\253"}, + /* ─, ┠, ┼, ┨ */ + {"\342\224\200", "\342\224\240", "\342\224\274", "\342\224\250"}, + /* ━, ┗, ┷, ┛ */ + {"\342\224\201", "\342\224\227", "\342\224\267", "\342\224\233"}, + /* N/A, │, │, │ */ + {"", "\342\224\203", "\342\224\202", "\342\224\203"}, + /* N/A, │, │, │ */ + {"", "\342\224\203", "\342\224\202", "\342\224\203"} + }, + /* │ */ + "\342\224\202", + /* │ */ + "\342\224\202", + /* │ */ + "\342\224\202", + " ", + " ", + " ", + " ", + " ", + " ", + false +}; /* Local functions */ static int strlen_max_width(unsigned char *str, int *target_width, int encoding); @@ -465,9 +720,9 @@ _print_horizontal_line(const unsigned int ncolumns, const unsigned int *widths, unsigned int i, j; - if (border == 1) + if (border == 1 || border == 3) fputs(lformat->hrule, fout); - else if (border == 2) + else if (border == 2 || border == 4) fprintf(fout, "%s%s", lformat->leftvrule, lformat->hrule); for (i = 0; i < ncolumns; i++) @@ -485,9 +740,9 @@ _print_horizontal_line(const unsigned int ncolumns, const unsigned int *widths, } } - if (border == 2) + if (border == 2 || border == 4) fprintf(fout, "%s%s", lformat->hrule, lformat->rightvrule); - else if (border == 1) + else if (border == 1 || border == 3) fputs(lformat->hrule, fout); fputc('\n', fout); @@ -505,6 +760,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout) unsigned short opt_border = cont->opt->border; const printTextFormat *format = get_line_style(cont->opt); const printTextLineFormat *dformat = &format->lrule[PRINT_RULE_DATA]; + const printTextLineFormat *hformat = &format->lrule[PRINT_RULE_ATTRNAME]; unsigned int col_count = 0, cell_count = 0; @@ -524,6 +780,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout) unsigned int total_header_width; unsigned int extra_row_output_lines = 0; unsigned int extra_output_lines = 0; + bool first_datarow = true; const char *const * ptr; @@ -538,8 +795,8 @@ print_aligned_text(const printTableContent *cont, FILE *fout) if (cancel_pressed) return; - if (opt_border > 2) - opt_border = 2; + if (opt_border > 4) + opt_border = 4; if (cont->ncolumns > 0) { @@ -817,7 +1074,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout) int more_col_wrapping; int curr_nl_line; - if (opt_border == 2) + if (opt_border == 2 || opt_border == 4) _print_horizontal_line(col_count, width_wrap, opt_border, PRINT_RULE_TOP, format, fout); @@ -831,8 +1088,8 @@ print_aligned_text(const printTableContent *cont, FILE *fout) memset(header_done, false, col_count * sizeof(bool)); while (more_col_wrapping) { - if (opt_border == 2) - fputs(dformat->leftvrule, fout); + if (opt_border == 2 || opt_border == 4) + fputs(hformat->leftvrule, fout); for (i = 0; i < cont->ncolumns; i++) { @@ -866,17 +1123,17 @@ print_aligned_text(const printTableContent *cont, FILE *fout) fout); if (opt_border != 0 && i < col_count - 1) - fputs(dformat->midvrule, fout); + fputs(hformat->midvrule, fout); } curr_nl_line++; - if (opt_border == 2) + if (opt_border == 2 || opt_border == 4) fputs(dformat->rightvrule, fout); fputc('\n', fout); } _print_horizontal_line(col_count, width_wrap, opt_border, - PRINT_RULE_MIDDLE, format, fout); + PRINT_RULE_HEADER, format, fout); } } @@ -884,6 +1141,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout) for (i = 0, ptr = cont->cells; *ptr; i += col_count, ptr += col_count) { bool more_lines; + bool first_line = true; if (cancel_pressed) break; @@ -909,8 +1167,17 @@ print_aligned_text(const printTableContent *cont, FILE *fout) { more_lines = false; + if ((opt_border == 3 || opt_border == 4) && !first_datarow && first_line) + { + _print_horizontal_line(col_count, width_wrap, opt_border, + PRINT_RULE_MIDDLE, format, fout); + first_line = false; + } + else if (first_datarow) + first_datarow = false; + /* left border */ - if (opt_border == 2) + if (opt_border == 2 || opt_border == 4) fputs(dformat->leftvrule, fout); /* for each column */ @@ -920,7 +1187,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout) struct lineptr *this_line = &col_lineptrs[j][curr_nl_line[j]]; int bytes_to_output; int chars_to_output = width_wrap[j]; - bool finalspaces = (opt_border == 2 || j < col_count - 1); + bool finalspaces = ((opt_border == 2 || opt_border == 4) || j < col_count - 1); /* Print left-hand wrap or newline mark */ if (opt_border != 0) @@ -1014,7 +1281,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout) fputs(format->wrap_right, fout); else if (wrap[j] == PRINT_LINE_WRAP_NEWLINE) fputs(format->nl_right, fout); - else if (opt_border == 2 || j < col_count - 1) + else if ((opt_border == 2 || opt_border == 4) || j < col_count - 1) fputc(' ', fout); /* Print column divider, if not the last column */ @@ -1032,7 +1299,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout) } /* end-of-row border */ - if (opt_border == 2) + if (opt_border == 2 || opt_border == 4) fputs(dformat->rightvrule, fout); fputc('\n', fout); @@ -1043,7 +1310,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout) { printTableFooter *footers = footers_with_default(cont); - if (opt_border == 2 && !cancel_pressed) + if ((opt_border == 2 || opt_border == 4) && !cancel_pressed) _print_horizontal_line(col_count, width_wrap, opt_border, PRINT_RULE_BOTTOM, format, fout); @@ -1098,7 +1365,7 @@ print_aligned_vertical_line(const printTableContent *cont, unsigned int i; int reclen = 0; - if (opt_border == 2) + if (opt_border == 2 || opt_border == 4) fprintf(fout, "%s%s", lformat->leftvrule, lformat->hrule); else if (opt_border == 1) fputs(lformat->hrule, fout); @@ -1136,7 +1403,7 @@ print_aligned_vertical_line(const printTableContent *cont, reclen = 0; for (i = reclen; i < dwidth; i++) fputs(opt_border > 0 ? lformat->hrule : " ", fout); - if (opt_border == 2) + if (opt_border == 2 || opt_border == 4) fprintf(fout, "%s%s", lformat->hrule, lformat->rightvrule); fputc('\n', fout); } @@ -1250,14 +1517,14 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout) else if (!(*(ptr + 1))) pos = PRINT_RULE_BOTTOM; else - pos = PRINT_RULE_MIDDLE; + pos = PRINT_RULE_HEADER; if (i % cont->ncolumns == 0) { if (!opt_tuples_only) print_aligned_vertical_line(cont, record++, hwidth, dwidth, pos, fout); - else if (i != 0 || !cont->opt->start_table || opt_border == 2) + else if (i != 0 || !cont->opt->start_table || opt_border == 2 || opt_border == 4) print_aligned_vertical_line(cont, 0, hwidth, dwidth, pos, fout); } @@ -1274,7 +1541,7 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout) dcomplete = hcomplete = 0; while (!dcomplete || !hcomplete) { - if (opt_border == 2) + if (opt_border == 2 || opt_border == 4) fprintf(fout, "%s ", dformat->leftvrule); if (!hcomplete) { @@ -1317,7 +1584,7 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout) if (cont->opt->stop_table) { - if (opt_border == 2 && !cancel_pressed) + if ((opt_border == 2 || opt_border == 4) && !cancel_pressed) print_aligned_vertical_line(cont, 0, hwidth, dwidth, PRINT_RULE_BOTTOM, fout); diff --git a/src/bin/psql/print.h b/src/bin/psql/print.h index 9cfa3b6..f5c527d 100644 --- a/src/bin/psql/print.h +++ b/src/bin/psql/print.h @@ -37,8 +37,10 @@ typedef enum printTextRule { /* Additional context for selecting line drawing characters */ PRINT_RULE_TOP, /* top horizontal line */ + PRINT_RULE_HEADER, /* header-data horizontal line */ PRINT_RULE_MIDDLE, /* intra-data horizontal line */ PRINT_RULE_BOTTOM, /* bottom horizontal line */ + PRINT_RULE_ATTRNAME, /* separators between attrnames */ PRINT_RULE_DATA /* data line (hrule is unused here) */ } printTextRule; @@ -54,7 +56,7 @@ typedef struct printTextFormat { /* A complete line style */ const char *name; /* for display purposes */ - printTextLineFormat lrule[4]; /* indexed by enum printTextRule */ + printTextLineFormat lrule[6]; /* indexed by enum printTextRule */ const char *midvrule_nl; /* vertical line for continue after newline */ const char *midvrule_wrap; /* vertical line for wrapped data */ const char *midvrule_blank; /* vertical line for blank data */ @@ -152,7 +154,15 @@ typedef struct printQueryOpt extern const printTextFormat pg_asciiformat; extern const printTextFormat pg_asciiformat_old; extern const printTextFormat pg_utf8format; - +extern const printTextFormat pg_utf8format2; + +extern const printTextFormat pg_utf8double1format; +extern const printTextFormat pg_utf8double2format; +extern const printTextFormat pg_utf8double3format; +extern const printTextFormat pg_utf8double4format; +extern const printTextFormat pg_utf8double5format; +extern const printTextFormat pg_utf8bold1format; +extern const printTextFormat pg_utf8bold2format; extern FILE *PageOutput(int lines, unsigned short int pager); extern void ClosePager(FILE *pagerpipe); diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 2a0bb71..5c74c9d 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -3355,10 +3355,20 @@ psql_completion(char *text, int start, int end) else if (strcmp(prev_wd, "linestyle") == 0) { static const char *const my_list[] = - {"ascii", "old-ascii", "unicode", NULL}; + {"ascii", "old-ascii", "unicode", "unicode2", "unicode-double1", + "unicode-double2", "unicode-double3", "unicode-double4", "unicode-double5", + "unicode-bold1", "unicode-bold2", NULL}; COMPLETE_WITH_LIST_CS(my_list); } + else if (strcmp(prev_wd, "border") == 0 && + strcmp(prev2_wd, "\\pset") == 0) + { + static const char *const list_PREPARE[] = + {"0", "1", "2", "3", "4", NULL}; + + COMPLETE_WITH_LIST(list_PREPARE); + } } else if (strcmp(prev_wd, "\\set") == 0) {
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers