From 68916af3b94a72b93b428068986b5d98dc7f0255 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 29 Mar 2017 12:46:54 +0200 Subject: [PATCH] column: add --table-wrap Signed-off-by: Karel Zak --- text-utils/column.1 | 4 ++++ text-utils/column.c | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/text-utils/column.1 b/text-utils/column.1 index 8117b6bf93..0889bfe8cd 100644 --- a/text-utils/column.1 +++ b/text-utils/column.1 @@ -77,6 +77,10 @@ average) cells when calculate column width. The option has impact to the width calculation, but the printed text is not affected. The \fIcolumns\fP is comma separated list of the column names (see \fB\-\-table-columns\fP) or column number. +.IP "\fB\-W, \-\-table-wrap\fP \fIcolumns\fP" +Specify columns where is possible to use multi-line cell for long text when +necessary. The \fIcolumns\fP is comma separated list of the column names (see +\fB\-\-table-columns\fP) or column number. .IP "\fB\-n, \-\-table-name\fP \fIname\fP" Specify the table name used for JSON output. The defaout is "table". .IP "\fB\-x, \-\-fillrows\fP" diff --git a/text-utils/column.c b/text-utils/column.c index 66f7e6c545..5f5e4ea335 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -75,6 +75,7 @@ struct column_control { const char *tab_colright; /* --table-right */ const char *tab_coltrunc; /* --table-trunc */ const char *tab_colnoextrem; /* --table-noextreme */ + const char *tab_colwrap; /* --table-wrap */ wchar_t *input_separator; const char *output_separator; @@ -259,6 +260,11 @@ static void modify_table(struct column_control *ctl) if (ctl->tab_colnoextrem) apply_columnflag_from_list(ctl, ctl->tab_colnoextrem, SCOLS_FL_NOEXTREMES , _("failed to parse --table-noextreme list")); + + if (ctl->tab_colwrap) + apply_columnflag_from_list(ctl, ctl->tab_colwrap, + SCOLS_FL_WRAP , _("failed to parse --table-wrap list")); + } static int add_line_to_table(struct column_control *ctl, wchar_t *wcs) @@ -433,7 +439,8 @@ static void __attribute__((__noreturn__)) usage(int rc) fputs(_(" -N, --table-columns comma separated columns names\n"), out); fputs(_(" -R, --table-right right align text in these columns\n"), out); fputs(_(" -T, --table-truncate truncate text in the columns when necessary\n"), out); - fputs(_(" -E, --table-noextreme don't count long text from the columns to column width\n"), out); + fputs(_(" -E, --table-noextreme don't count long text from the columns to column width\n"), out); + fputs(_(" -W, --table-wrap wrap text in the columns when necessary\n"), out); fputs(_(" -n, --table-name table name for JSON output\n"), out); fputs(_(" -s, --separator possible table delimiters\n"), out); fputs(_(" -o, --output-separator columns separator for table output\n" @@ -472,6 +479,7 @@ int main(int argc, char **argv) { "table-right", required_argument, NULL, 'R' }, { "table-truncate", required_argument, NULL, 'T' }, { "table-noextreme", required_argument, NULL, 'E' }, + { "table-wrap", required_argument, NULL, 'W' }, { "table-name", required_argument, NULL, 'n' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 }, @@ -492,7 +500,7 @@ int main(int argc, char **argv) ctl.output_separator = " "; ctl.input_separator = mbs_to_wcs("\t "); - while ((c = getopt_long(argc, argv, "hVc:Jn:N:R:s:txo:T:E:", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "hVc:Jn:N:R:s:txo:T:E:W:", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); @@ -536,6 +544,9 @@ int main(int argc, char **argv) case 't': ctl.mode = COLUMN_MODE_TABLE; break; + case 'W': + ctl.tab_colwrap = optarg; + break; case 'x': ctl.mode = COLUMN_MODE_FILLROWS; break; -- 2.39.2