Commit 42ec8ad6 authored by Tom Lane's avatar Tom Lane

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
parent b1407116
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.231 2009/10/08 16:34:00 alvherre Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.232 2009/10/13 21:04:01 tgl Exp $
PostgreSQL documentation
-->
......@@ -1760,6 +1760,39 @@ lo_import 152801
</listitem>
</varlistentry>
<varlistentry>
<term><literal>linestyle</literal></term>
<listitem>
<para>
Sets the border line drawing style to one
of <literal>ascii</literal> or <literal>unicode</literal>.
Unique abbreviations are allowed. (That would mean one
letter is enough.)
</para>
<para>
<quote>ASCII</quote> uses plain <acronym>ASCII</acronym> characters.
</para>
<para>
<quote>Unicode</quote> uses Unicode box-drawing characters.
</para>
<para>
When the selected output format is one that draws lines or boxes
around the data, this setting controls how the lines are drawn.
Plain <acronym>ASCII</acronym> characters work everywhere, but
Unicode characters look nicer on displays that recognize them.
</para>
<para>
If this option has not been set, the default behavior is to
use Unicode characters if the client character set encoding
is UTF-8, otherwise <acronym>ASCII</acronym> characters.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>expanded</literal> (or <literal>x</literal>)</term>
<listitem>
......
......@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.209 2009/10/07 22:14:24 alvherre Exp $
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.210 2009/10/13 21:04:01 tgl Exp $
*/
#include "postgres_fe.h"
#include "command.h"
......@@ -1788,6 +1788,26 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
printf(_("Output format is %s.\n"), _align2string(popt->topt.format));
}
/* set table line style */
else if (strcmp(param, "linestyle") == 0)
{
if (!value)
;
else if (pg_strncasecmp("ascii", value, vallen) == 0)
popt->topt.line_style = &pg_asciiformat;
else if (pg_strncasecmp("unicode", value, vallen) == 0)
popt->topt.line_style = &pg_utf8format;
else
{
psql_error("\\pset: allowed line styles are ascii, unicode\n");
return false;
}
if (!quiet)
printf(_("Line style is %s.\n"),
get_line_style(&popt->topt)->name);
}
/* set border style/width */
else if (strcmp(param, "border") == 0)
{
......
......@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.35 2009/06/11 14:49:08 momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.36 2009/10/13 21:04:01 tgl Exp $
*
* XXX this file does not really belong in psql/. Perhaps move to libpq?
* It also seems that the mbvalidate function is redundant with existing
......@@ -30,8 +30,8 @@
typedef unsigned int pg_wchar;
static int
get_utf8_id(void)
int
pg_get_utf8_id(void)
{
static int utf8_id = -1;
......@@ -40,7 +40,7 @@ get_utf8_id(void)
return utf8_id;
}
#define PG_UTF8 get_utf8_id()
#define PG_UTF8 pg_get_utf8_id()
static pg_wchar
......
/* $PostgreSQL: pgsql/src/bin/psql/mbprint.h,v 1.13 2009/06/11 14:49:08 momjian Exp $ */
/* $PostgreSQL: pgsql/src/bin/psql/mbprint.h,v 1.14 2009/10/13 21:04:01 tgl Exp $ */
#ifndef MBPRINT_H
#define MBPRINT_H
......@@ -9,8 +9,8 @@ struct lineptr
int width;
};
extern int pg_get_utf8_id(void);
extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding);
extern int pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding);
extern void pg_wcsformat(unsigned char *pwcs, size_t len, int encoding, struct lineptr * lines, int count);
extern void pg_wcssize(unsigned char *pwcs, size_t len, int encoding,
......
This diff is collapsed.
......@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/print.h,v 1.40 2009/06/11 14:49:08 momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/print.h,v 1.41 2009/10/13 21:04:01 tgl Exp $
*/
#ifndef PRINT_H
#define PRINT_H
......@@ -23,10 +23,37 @@ enum printFormat
/* add your favourite output format here ... */
};
typedef struct printTextLineFormat
{
/* Line drawing characters to be used in various contexts */
const char *hrule; /* horizontal line character */
const char *leftvrule; /* left vertical line (+horizontal) */
const char *midvrule; /* intra-column vertical line (+horizontal) */
const char *rightvrule; /* right vertical line (+horizontal) */
} printTextLineFormat;
typedef enum printTextRule
{
/* Additional context for selecting line drawing characters */
PRINT_RULE_TOP, /* top horizontal line */
PRINT_RULE_MIDDLE, /* intra-data horizontal line */
PRINT_RULE_BOTTOM, /* bottom horizontal line */
PRINT_RULE_DATA /* data line (hrule is unused here) */
} printTextRule;
typedef struct printTextFormat
{
/* A complete line style */
const char *name; /* for display purposes */
printTextLineFormat lrule[4]; /* indexed by enum printTextRule */
const char *midvrule_cont; /* vertical line for continue after newline */
const char *midvrule_wrap; /* vertical line for wrapped data */
const char *midvrule_blank; /* vertical line for blank data */
} printTextFormat;
typedef struct printTableOpt
{
enum printFormat format; /* one of the above */
enum printFormat format; /* see enum above */
bool expanded; /* expanded/vertical output (if supported by
* output format) */
unsigned short int border; /* Print a border around the table. 0=none,
......@@ -37,6 +64,7 @@ typedef struct printTableOpt
bool start_table; /* print start decoration, eg <table> */
bool stop_table; /* print stop decoration, eg </table> */
unsigned long prior_records; /* start offset for record counters */
const printTextFormat *line_style; /* line style (NULL for default) */
char *fieldSep; /* field separator for unaligned text mode */
char *recordSep; /* record separator for unaligned text mode */
bool numericLocale; /* locale-aware numeric units separator and
......@@ -96,6 +124,10 @@ typedef struct printQueryOpt
} printQueryOpt;
extern const printTextFormat pg_asciiformat;
extern const printTextFormat pg_utf8format;
extern FILE *PageOutput(int lines, unsigned short int pager);
extern void ClosePager(FILE *pagerpipe);
......@@ -118,6 +150,7 @@ extern void printQuery(const PGresult *result, const printQueryOpt *opt,
FILE *fout, FILE *flog);
extern void setDecimalLocale(void);
extern const printTextFormat *get_line_style(const printTableOpt *opt);
#ifndef __CYGWIN__
#define DEFAULT_PAGER "more"
......
......@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.186 2009/10/08 16:34:01 alvherre Exp $
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.187 2009/10/13 21:04:01 tgl Exp $
*/
/*----------------------------------------------------------------------
......@@ -2264,8 +2264,8 @@ psql_completion(char *text, int start, int end)
{
static const char *const my_list[] =
{"format", "border", "expanded",
"null", "fieldsep", "tuples_only", "title", "tableattr", "pager",
"recordsep", NULL};
"null", "fieldsep", "tuples_only", "title", "tableattr",
"linestyle", "pager", "recordsep", NULL};
COMPLETE_WITH_LIST(my_list);
}
......
......@@ -11,7 +11,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/test/regress/pg_regress_main.c,v 1.6 2009/06/11 14:49:15 momjian Exp $
* $PostgreSQL: pgsql/src/test/regress/pg_regress_main.c,v 1.7 2009/10/13 21:04:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -59,7 +59,7 @@ psql_start_test(const char *testname,
add_stringlist_item(expectfiles, expectfile);
snprintf(psql_cmd, sizeof(psql_cmd),
SYSTEMQUOTE "\"%s%spsql\" -X -a -q -d \"%s\" < \"%s\" > \"%s\" 2>&1" SYSTEMQUOTE,
SYSTEMQUOTE "\"%s%spsql\" -X -a -q -P linestyle=ascii -d \"%s\" < \"%s\" > \"%s\" 2>&1" SYSTEMQUOTE,
psqldir ? psqldir : "",
psqldir ? "/" : "",
dblist->str,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment