]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: add SCOLS_FL_MAX
authorKarel Zak <kzak@redhat.com>
Wed, 19 Mar 2014 16:10:50 +0000 (17:10 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 3 Apr 2014 10:29:16 +0000 (12:29 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/libsmartcols.h.in
libsmartcols/src/table_print.c
libsmartcols/src/test.c

index 9bb7c64801013c763cbeac79f660edeea25bfa00..c5875fd1c6aa1b5e6e806bf1448b587023eabcbe 100644 (file)
@@ -42,15 +42,16 @@ enum {
        SCOLS_FL_ASCII       = (1 << 2),
        SCOLS_FL_NOHEADINGS  = (1 << 3),
        SCOLS_FL_EXPORT      = (1 << 4),
+       SCOLS_FL_MAX         = (1 << 5),
 
        /*
         * Column flags
         */
-       SCOLS_FL_TRUNC       = (1 << 5),   /* truncate fields data if necessary */
-       SCOLS_FL_TREE        = (1 << 6),   /* use tree "ascii art" */
-       SCOLS_FL_RIGHT       = (1 << 7),   /* align to the right */
-       SCOLS_FL_STRICTWIDTH = (1 << 8),   /* don't reduce width if column is empty */
-       SCOLS_FL_NOEXTREMES  = (1 << 9),   /* ignore extreme fields when count column width*/
+       SCOLS_FL_TRUNC       = (1 << 15),   /* truncate fields data if necessary */
+       SCOLS_FL_TREE        = (1 << 16),   /* use tree "ascii art" */
+       SCOLS_FL_RIGHT       = (1 << 17),   /* align to the right */
+       SCOLS_FL_STRICTWIDTH = (1 << 18),   /* don't reduce width if column is empty */
+       SCOLS_FL_NOEXTREMES  = (1 << 19),   /* ignore extreme fields when count column width*/
 };
 
 extern struct libscols_iter *scols_new_iter(int direction);
index ee40c4090ac96cac8094c24a2e77d4d4736f1023..8504c2c4d24184100ffc6821618af28fec42ab76 100644 (file)
@@ -77,7 +77,7 @@ static void print_data(struct libscols_table *tb,
        }
        width = cl->width;
 
-       if (is_last_column(tb, cl) && len < width)
+       if (is_last_column(tb, cl) && len < width && !(tb->flags & SCOLS_FL_MAX))
                width = len;
 
        /* truncate data */
@@ -436,8 +436,20 @@ static void recount_widths(struct libscols_table *tb, char *buf, size_t bufsz)
                                        break;
                        }
                }
-               if (width < tb->termwidth) {
-                       /* enalarge the last column */
+
+               if (width < tb->termwidth && (tb->flags & SCOLS_FL_MAX)) {
+                       /* try enlarge all columns */
+                       while (width < tb->termwidth) {
+                               scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
+                               while (scols_table_next_column(tb, &itr, &cl) == 0) {
+                                       cl->width++;
+                                       width++;
+                                       if (width == tb->termwidth)
+                                               break;
+                               }
+                       }
+               } else if (width < tb->termwidth) {
+                       /* enlarge the last column */
                        struct libscols_column *cl = list_entry(
                                tb->tb_columns.prev, struct libscols_column, cl_columns);
 
index 2d0087e88c3beccbc97227e899bfa2047db4faa2..372e2722d96f970c39be88b682e7484013744d75 100644 (file)
@@ -37,9 +37,12 @@ int main(int argc, char *argv[])
        int flags = 0, notree = 0, clone = 0, i, color = 0;
 
        if (argc == 2 && !strcmp(argv[1], "--help")) {
-               printf("%s [--ascii | --raw | --list | --clone | --clonetree]\n",
+               printf("%s [--max | --ascii | --raw | --export | --list | "
+                      "--color | --colortree | --clone | --clonetree]\n",
                                program_invocation_short_name);
                return EXIT_SUCCESS;
+       } else if (argc == 2 && !strcmp(argv[1], "--max")) {
+               flags |= SCOLS_FL_MAX;
        } else if (argc == 2 && !strcmp(argv[1], "--ascii")) {
                flags |= SCOLS_FL_ASCII;
        } else if (argc == 2 && !strcmp(argv[1], "--raw")) {