Convert print_aligned_text, and its helper function, to use
table formatting in place of hardcoded ASCII characters.

Signed-off-by: Roger Leigh <rle...@debian.org>
---
 src/bin/psql/print.c |   50 +++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index 641fd63..84f6bdc 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -394,29 +394,41 @@ _print_horizontal_line(const unsigned int ncolumns, const 
unsigned int *widths,
        unsigned int i,
                                j;
 
+       const printTextLineFormat *lformat = &format->lrule[pos];
+
        if (border == 1)
-               fputc('-', fout);
+               fputs(format->hrule, fout);
        else if (border == 2)
-               fputs("+-", fout);
+       {
+               fputs(lformat->leftvrule, fout);
+               fputs(format->hrule, fout);
+       }
 
        for (i = 0; i < ncolumns; i++)
        {
                for (j = 0; j < widths[i]; j++)
-                       fputc('-', fout);
+                       fputs(format->hrule, fout);
 
                if (i < ncolumns - 1)
                {
                        if (border == 0)
                                fputc(' ', fout);
                        else
-                               fputs("-+-", fout);
+                       {
+                               fputs(format->hrule, fout);
+                               fputs(lformat->midvrule, fout);
+                               fputs(format->hrule, fout);
+                       }
                }
        }
 
        if (border == 2)
-               fputs("-+", fout);
+       {
+               fputs(format->hrule, fout);
+               fputs(lformat->rightvrule, fout);
+       }
        else if (border == 1)
-               fputc('-', fout);
+               fputs(format->hrule, fout);
 
        fputc('\n', fout);
 }
@@ -752,7 +764,7 @@ print_aligned_text(const printTableContent *cont, const 
printTextFormat *format,
                        while (more_col_wrapping)
                        {
                                if (opt_border == 2)
-                                       fprintf(fout, "|%c", curr_nl_line ? '+' 
: ' ');
+                                       fprintf(fout, "%s%c", format->vrule, 
curr_nl_line ? '+' : ' ');
                                else if (opt_border == 1)
                                        fputc(curr_nl_line ? '+' : ' ', fout);
 
@@ -783,13 +795,16 @@ print_aligned_text(const printTableContent *cont, const 
printTextFormat *format,
                                                if (opt_border == 0)
                                                        fputc(curr_nl_line ? 
'+' : ' ', fout);
                                                else
-                                                       fprintf(fout, " |%c", 
curr_nl_line ? '+' : ' ');
+                                                       fprintf(fout, " %s%c", 
format->vrule, curr_nl_line ? '+' : ' ');
                                        }
                                }
                                curr_nl_line++;
 
                                if (opt_border == 2)
-                                       fputs(" |", fout);
+                               {
+                                       fputc(' ', fout);
+                                       fputs(format->vrule, fout);
+                               }
                                else if (opt_border == 1)
                                        fputc(' ', fout);
                                fputc('\n', fout);
@@ -841,7 +856,10 @@ print_aligned_text(const printTableContent *cont, const 
printTextFormat *format,
 
                        /* left border */
                        if (opt_border == 2)
-                               fputs("| ", fout);
+                       {
+                               fputs(format->vrule, fout);
+                               fputc(' ', fout);
+                       }
                        else if (opt_border == 1)
                                fputc(' ', fout);
 
@@ -922,14 +940,20 @@ print_aligned_text(const printTableContent *cont, const 
printTextFormat *format,
                                        else if (curr_nl_line[j + 1] != 0)
                                                fputs(" : ", fout);
                                        else
+                                       {
                                                /* Ordinary line */
-                                               fputs(" | ", fout);
+                                               fputc(' ', fout);
+                                               fputs(format->vrule, fout);
+                                               fputc(' ', fout);
+                                       }
                                }
                        }
 
                        /* end-of-row border */
-                       if (opt_border == 2)
-                               fputs(" |", fout);
+                       if (opt_border == 2) {
+                               fputc(' ', fout);
+                               fputs(format->vrule, fout);
+                       }
                        fputc('\n', fout);
 
                } while (more_lines);
-- 
1.6.3.3


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to