diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2022-07-25 14:24:50 -0400 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2022-07-25 14:25:02 -0400 |
commit | a45388d6e0984abb02074f0300cd9c5cbda13848 (patch) | |
tree | 95689aab9fda59493f9f119f9e45b5f22f0d4fab /src/bin/psql/command.c | |
parent | b35617de37870756bdb0e00ffc0a42441e56eefa (diff) | |
download | postgresql-a45388d6e0984abb02074f0300cd9c5cbda13848.tar.gz postgresql-a45388d6e0984abb02074f0300cd9c5cbda13848.zip |
Add xheader_width pset option to psql
The setting controls tha maximum length of the header line in expanded
format output. Possible settings are full, column, page, or an integer.
the default is full, the current behaviour, and in this case the header
line is the length of the widest line of output. column causes the
header to be truncated to the width of the first column, page causes it
to be truncated to the width of the terminal page, and an integer causes
it to be truncated to that value. If the full value is less than the
page or integer value no truncation occurs. If given without an argument
this option prints its current setting.
Platon Pronko, somewhat modified by me.
Discussion: https://postgr.es/m/f03d38a3-db96-a56e-d1bc-dbbc80bbde4d@gmail.com
Diffstat (limited to 'src/bin/psql/command.c')
-rw-r--r-- | src/bin/psql/command.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index cac98804ab5..a81bd3307b4 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -2244,6 +2244,7 @@ exec_command_pset(PsqlScanState scan_state, bool active_branch) "unicode_border_linestyle", "unicode_column_linestyle", "unicode_header_linestyle", + "xheader_width", NULL }; @@ -4369,6 +4370,29 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet) popt->topt.expanded = !popt->topt.expanded; } + /* header line width in expanded mode */ + else if (strcmp(param, "xheader_width") == 0) + { + if (! value) + ; + else if (pg_strcasecmp(value, "full") == 0) + popt->topt.expanded_header_width_type = PRINT_XHEADER_FULL; + else if (pg_strcasecmp(value, "column") == 0) + popt->topt.expanded_header_width_type = PRINT_XHEADER_COLUMN; + else if (pg_strcasecmp(value, "page") == 0) + popt->topt.expanded_header_width_type = PRINT_XHEADER_PAGE; + else + { + popt->topt.expanded_header_width_type = PRINT_XHEADER_EXACT_WIDTH; + popt->topt.expanded_header_exact_width = atoi(value); + if (popt->topt.expanded_header_exact_width == 0) + { + pg_log_error("\\pset: allowed xheader_width values are full (default), column, page, or a number specifying the exact width."); + return false; + } + } + } + /* field separator for CSV format */ else if (strcmp(param, "csv_fieldsep") == 0) { @@ -4561,6 +4585,19 @@ printPsetInfo(const char *param, printQueryOpt *popt) printf(_("Expanded display is off.\n")); } + /* show xheader width value */ + else if (strcmp(param, "xheader_width") == 0) + { + if (popt->topt.expanded_header_width_type == PRINT_XHEADER_FULL) + printf(_("Expanded header width is 'full'.\n")); + else if (popt->topt.expanded_header_width_type == PRINT_XHEADER_COLUMN) + printf(_("Expanded header width is 'column'.\n")); + else if (popt->topt.expanded_header_width_type == PRINT_XHEADER_PAGE) + printf(_("Expanded header width is 'page'.\n")); + else if (popt->topt.expanded_header_width_type == PRINT_XHEADER_EXACT_WIDTH) + printf(_("Expanded header width is %d.\n"), popt->topt.expanded_header_exact_width); + } + /* show field separator for CSV format */ else if (strcmp(param, "csv_fieldsep") == 0) { @@ -4881,6 +4918,23 @@ pset_value_string(const char *param, printQueryOpt *popt) return pstrdup(_unicode_linestyle2string(popt->topt.unicode_column_linestyle)); else if (strcmp(param, "unicode_header_linestyle") == 0) return pstrdup(_unicode_linestyle2string(popt->topt.unicode_header_linestyle)); + else if (strcmp(param, "xheader_width") == 0) + { + if (popt->topt.expanded_header_width_type == PRINT_XHEADER_FULL) + return(pstrdup("full")); + else if (popt->topt.expanded_header_width_type == PRINT_XHEADER_COLUMN) + return(pstrdup("column")); + else if (popt->topt.expanded_header_width_type == PRINT_XHEADER_PAGE) + return(pstrdup("page")); + else + { + /* must be PRINT_XHEADER_EXACT_WIDTH */ + char wbuff[32]; + snprintf(wbuff, sizeof(wbuff), "%d", + popt->topt.expanded_header_exact_width); + return pstrdup(wbuff); + } + } else return pstrdup("ERROR"); } |