[PATCH 5/6] psql: print_aligned_text uses table formatting - Mailing list pgsql-hackers

From Roger Leigh
Subject [PATCH 5/6] psql: print_aligned_text uses table formatting
Date
Msg-id 1250956790-18404-6-git-send-email-rleigh@debian.org
Whole thread Raw
In response to [PATCH 4/6] psql: Pass table formatting object to text output functions  (Roger Leigh <rleigh@debian.org>)
Responses Re: [PATCH 5/6] psql: print_aligned_text uses table formatting  (Alvaro Herrera <alvherre@commandprompt.com>)
List pgsql-hackers
Convert print_aligned_text, and its helper function, to use
table formatting in place of hardcoded ASCII characters.

Signed-off-by: Roger Leigh <rleigh@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,            /*
leftborder */            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



pgsql-hackers by date:

Previous
From: Roger Leigh
Date:
Subject: [PATCH 6/6] psql: print_aligned_vertical uses table formatting
Next
From: Roger Leigh
Date:
Subject: [PATCH 7/7] psql: Don't print leading - with expanded=1 and border=0