From 35d5d655c5bc58c52ae6d440eea69b39f1cfb4fc Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 9 Mar 2022 11:49:13 +0100 Subject: [PATCH] column: implement "--output-width unlimited" Addresses: https://github.com/util-linux/util-linux/issues/1618 Signed-off-by: Karel Zak --- text-utils/column.1.adoc | 2 ++ text-utils/column.c | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/text-utils/column.1.adoc b/text-utils/column.1.adoc index 33d7e0d9c2..54dacf5815 100644 --- a/text-utils/column.1.adoc +++ b/text-utils/column.1.adoc @@ -72,6 +72,8 @@ Use JSON output format to print the table, the option *--table-columns* is requi *-c, --output-width* _width_:: Output is formatted to a width specified as number of characters. The original name of this option is *--columns*; this name is deprecated since v2.30. Note that input longer than _width_ is not truncated by default. The default is a terminal width and the 80 columns in non-interactive mode. The column headers are never truncated. ++ +The placeholder "unlimited" (or 0) is possible to use to not restrict output width. This is recommended for example when output to the files rather than on terminal. *-d, --table-noheadings*:: Do not print header. This option allows the use of logical column names on the command line, but keeps the header hidden when printing the table. diff --git a/text-utils/column.c b/text-utils/column.c index bd5f778c7e..1cd9b16324 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -67,7 +67,7 @@ enum { struct column_control { int mode; /* COLUMN_MODE_* */ - size_t termwidth; + size_t termwidth; /* -1 uninilialized, 0 unlimited, >0 width (default is 80) */ struct libscols_table *tab; @@ -402,8 +402,10 @@ static void create_tree(struct column_control *ctl) static void modify_table(struct column_control *ctl) { - scols_table_set_termwidth(ctl->tab, ctl->termwidth); - scols_table_set_termforce(ctl->tab, SCOLS_TERMFORCE_ALWAYS); + if (ctl->termwidth > 0) { + scols_table_set_termwidth(ctl->tab, ctl->termwidth); + scols_table_set_termforce(ctl->tab, SCOLS_TERMFORCE_ALWAYS); + } if (ctl->tab_colright) apply_columnflag_from_list(ctl, ctl->tab_colright, @@ -759,7 +761,10 @@ int main(int argc, char **argv) switch(c) { case 'c': - ctl.termwidth = strtou32_or_err(optarg, _("invalid columns argument")); + if (strcmp(optarg, "unlimited") == 0) + ctl.termwidth = 0; + else + ctl.termwidth = strtou32_or_err(optarg, _("invalid columns argument")); break; case 'd': ctl.tab_noheadings = 1; -- 2.47.2