]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
column: use NOEXTREMES for the last column
authorKarel Zak <kzak@redhat.com>
Mon, 3 Apr 2017 12:43:13 +0000 (14:43 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 2 May 2017 10:18:00 +0000 (12:18 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/column.1
text-utils/column.c

index d138ec613e133cdb6df1ed6394f4fb5fb46b57d4..25fa7bab66586a93a093c689e2f45841a963c159 100644 (file)
@@ -87,7 +87,9 @@ very long table entries may be printed on multiple lines.
 .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.
+calculation and table formatting, but the printed text is not affected.
+
+The option is used for the last visible column by default.
 .IP "\fB\-W, \-\-table-wrap\fP \fIcolumns\fP"
 Specify columns where is possible to use multi-line cell for long text when
 necessary.
index d618978f4a8280ae7b53a6ae28a9af916f5e54e0..3b582ca1da9f4ff1b1fe577030c67edba857db98 100644 (file)
@@ -230,6 +230,24 @@ static struct libscols_column *string_to_column(struct column_control *ctl, cons
        return scols_table_get_column(ctl->tab, colnum);
 }
 
+static struct libscols_column *get_last_visible_column(struct column_control *ctl)
+{
+       struct libscols_iter *itr;
+       struct libscols_column *cl, *last = NULL;
+
+       itr = scols_new_iter(SCOLS_ITER_FORWARD);
+       if (!itr)
+               err_oom();
+
+       while (scols_table_next_column(ctl->tab, itr, &cl) == 0) {
+               if (scols_column_get_flags(cl) & SCOLS_FL_HIDDEN)
+                       continue;
+               last = cl;
+       }
+
+       scols_free_iter(itr);
+       return last;
+}
 
 static int column_set_flag(struct libscols_column *cl, int fl)
 {
@@ -344,6 +362,12 @@ static void modify_table(struct column_control *ctl)
                apply_columnflag_from_list(ctl, ctl->tab_colhide,
                                SCOLS_FL_HIDDEN , _("failed to parse --table-hide list"));
 
+       if (!ctl->tab_colnoextrem) {
+               struct libscols_column *cl = get_last_visible_column(ctl);
+               if (cl)
+                       column_set_flag(cl, SCOLS_FL_NOEXTREMES);
+       }
+
        if (ctl->tree)
                create_tree(ctl);