Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 42ec8ad

Browse files
committed
Add "\pset linestyle ascii/unicode" option to psql, allowing our traditional
ASCII-art style of table output to be upgraded to use Unicode box drawing characters if desired. By default, psql will use the Unicode characters whenever client_encoding is UTF8. The patch forces linestyle=ascii in pg_regress usage, ensuring we don't break the regression tests in Unicode locales. Roger Leigh
1 parent b140711 commit 42ec8ad

File tree

8 files changed

+276
-90
lines changed

8 files changed

+276
-90
lines changed

doc/src/sgml/ref/psql-ref.sgml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.231 2009/10/08 16:34:00 alvherre Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.232 2009/10/13 21:04:01 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -1760,6 +1760,39 @@ lo_import 152801
17601760
</listitem>
17611761
</varlistentry>
17621762

1763+
<varlistentry>
1764+
<term><literal>linestyle</literal></term>
1765+
<listitem>
1766+
<para>
1767+
Sets the border line drawing style to one
1768+
of <literal>ascii</literal> or <literal>unicode</literal>.
1769+
Unique abbreviations are allowed. (That would mean one
1770+
letter is enough.)
1771+
</para>
1772+
1773+
<para>
1774+
<quote>ASCII</quote> uses plain <acronym>ASCII</acronym> characters.
1775+
</para>
1776+
1777+
<para>
1778+
<quote>Unicode</quote> uses Unicode box-drawing characters.
1779+
</para>
1780+
1781+
<para>
1782+
When the selected output format is one that draws lines or boxes
1783+
around the data, this setting controls how the lines are drawn.
1784+
Plain <acronym>ASCII</acronym> characters work everywhere, but
1785+
Unicode characters look nicer on displays that recognize them.
1786+
</para>
1787+
1788+
<para>
1789+
If this option has not been set, the default behavior is to
1790+
use Unicode characters if the client character set encoding
1791+
is UTF-8, otherwise <acronym>ASCII</acronym> characters.
1792+
</para>
1793+
</listitem>
1794+
</varlistentry>
1795+
17631796
<varlistentry>
17641797
<term><literal>expanded</literal> (or <literal>x</literal>)</term>
17651798
<listitem>

src/bin/psql/command.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.209 2009/10/07 22:14:24 alvherre Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.210 2009/10/13 21:04:01 tgl Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "command.h"
@@ -1788,6 +1788,26 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
17881788
printf(_("Output format is %s.\n"), _align2string(popt->topt.format));
17891789
}
17901790

1791+
/* set table line style */
1792+
else if (strcmp(param, "linestyle") == 0)
1793+
{
1794+
if (!value)
1795+
;
1796+
else if (pg_strncasecmp("ascii", value, vallen) == 0)
1797+
popt->topt.line_style = &pg_asciiformat;
1798+
else if (pg_strncasecmp("unicode", value, vallen) == 0)
1799+
popt->topt.line_style = &pg_utf8format;
1800+
else
1801+
{
1802+
psql_error("\\pset: allowed line styles are ascii, unicode\n");
1803+
return false;
1804+
}
1805+
1806+
if (!quiet)
1807+
printf(_("Line style is %s.\n"),
1808+
get_line_style(&popt->topt)->name);
1809+
}
1810+
17911811
/* set border style/width */
17921812
else if (strcmp(param, "border") == 0)
17931813
{

src/bin/psql/mbprint.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.35 2009/06/11 14:49:08 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.36 2009/10/13 21:04:01 tgl Exp $
77
*
88
* XXX this file does not really belong in psql/. Perhaps move to libpq?
99
* It also seems that the mbvalidate function is redundant with existing
@@ -30,8 +30,8 @@
3030

3131
typedef unsigned int pg_wchar;
3232

33-
static int
34-
get_utf8_id(void)
33+
int
34+
pg_get_utf8_id(void)
3535
{
3636
static int utf8_id = -1;
3737

@@ -40,7 +40,7 @@ get_utf8_id(void)
4040
return utf8_id;
4141
}
4242

43-
#define PG_UTF8 get_utf8_id()
43+
#define PG_UTF8 pg_get_utf8_id()
4444

4545

4646
static pg_wchar

src/bin/psql/mbprint.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/bin/psql/mbprint.h,v 1.13 2009/06/11 14:49:08 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/bin/psql/mbprint.h,v 1.14 2009/10/13 21:04:01 tgl Exp $ */
22
#ifndef MBPRINT_H
33
#define MBPRINT_H
44

@@ -9,8 +9,8 @@ struct lineptr
99
int width;
1010
};
1111

12+
extern int pg_get_utf8_id(void);
1213
extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding);
13-
1414
extern int pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding);
1515
extern void pg_wcsformat(unsigned char *pwcs, size_t len, int encoding, struct lineptr * lines, int count);
1616
extern void pg_wcssize(unsigned char *pwcs, size_t len, int encoding,

0 commit comments

Comments
 (0)