From: Karel Zak Date: Wed, 29 Mar 2017 10:38:52 +0000 (+0200) Subject: column: add --table-noextreme X-Git-Tag: v2.30-rc1~54 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1ae24ec2390055b41191e32a20787bda3d0e9c1e;p=thirdparty%2Futil-linux.git column: add --table-noextreme Signed-off-by: Karel Zak --- diff --git a/text-utils/column.1 b/text-utils/column.1 index ca33c1ef54..8117b6bf93 100644 --- a/text-utils/column.1 +++ b/text-utils/column.1 @@ -71,6 +71,12 @@ Specify columns where is allowed to truncate text when necessary, otherwise very long table entries may be printed on multiple lines. The \fIcolumns\fP is comma separated list of the column names (see \fB\-\-table-columns\fP) or column number. +.IP "\fB\-E, \-\-table-noextreme\fP \fIcolumns\fP" +Specify columns where is possible to ignore unusually long (longer than +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\-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 f9f191ec0d..66f7e6c545 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -72,8 +72,9 @@ struct column_control { char **tab_colnames; /* array with column names */ const char *tab_name; /* table name */ - const char *tab_colright; /* non-parsed --table-right */ - const char *tab_coltrunc; /* non-parsed --table-trunc */ + const char *tab_colright; /* --table-right */ + const char *tab_coltrunc; /* --table-trunc */ + const char *tab_colnoextrem; /* --table-noextreme */ wchar_t *input_separator; const char *output_separator; @@ -247,15 +248,17 @@ static void modify_table(struct column_control *ctl) { scols_table_set_termwidth(ctl->tab, ctl->termwidth); - /* align text in columns to right */ if (ctl->tab_colright) apply_columnflag_from_list(ctl, ctl->tab_colright, SCOLS_FL_RIGHT, _("failed to parse --table-right list")); - /* truncate text in columns */ if (ctl->tab_coltrunc) apply_columnflag_from_list(ctl, ctl->tab_coltrunc, SCOLS_FL_TRUNC , _("failed to parse --table-trunc list")); + + if (ctl->tab_colnoextrem) + apply_columnflag_from_list(ctl, ctl->tab_colnoextrem, + SCOLS_FL_NOEXTREMES , _("failed to parse --table-noextreme list")); } static int add_line_to_table(struct column_control *ctl, wchar_t *wcs) @@ -429,7 +432,8 @@ static void __attribute__((__noreturn__)) usage(int rc) fputs(_(" -t, --table create a table\n"), out); 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 these columns when necessary\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(_(" -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" @@ -467,6 +471,7 @@ int main(int argc, char **argv) { "table-columns", required_argument, NULL, 'N' }, { "table-right", required_argument, NULL, 'R' }, { "table-truncate", required_argument, NULL, 'T' }, + { "table-noextreme", required_argument, NULL, 'E' }, { "table-name", required_argument, NULL, 'n' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 }, @@ -487,11 +492,14 @@ 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:", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "hVc:Jn:N:R:s:txo:T:E:", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); switch(c) { + case 'E': + ctl.tab_colnoextrem = optarg; + break; case 'J': ctl.json = 1; ctl.mode = COLUMN_MODE_TABLE;