]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
column: implement "--output-width unlimited"
authorKarel Zak <kzak@redhat.com>
Wed, 9 Mar 2022 10:49:13 +0000 (11:49 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 30 Mar 2022 09:14:30 +0000 (11:14 +0200)
Addresses: https://github.com/util-linux/util-linux/issues/1618
Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/column.1.adoc
text-utils/column.c

index 33d7e0d9c284eaa2da5186141cd6a750e4b20cc8..54dacf5815e6e24f97c98d65ae146f2da8787afb 100644 (file)
@@ -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.
index bd5f778c7e7a1eb48ff1d4ae327fa1217d5c064a..1cd9b163242b0f5f8eb81336dec0d27022e701bf 100644 (file)
@@ -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;