From: Karel Zak Date: Wed, 19 Mar 2014 16:10:50 +0000 (+0100) Subject: libsmartcols: add SCOLS_FL_MAX X-Git-Tag: v2.25-rc1~378 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=62d2e2e5389daf4120c945300e89705a91d93ff5;p=thirdparty%2Futil-linux.git libsmartcols: add SCOLS_FL_MAX Signed-off-by: Karel Zak --- diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in index 9bb7c64801..c5875fd1c6 100644 --- a/libsmartcols/src/libsmartcols.h.in +++ b/libsmartcols/src/libsmartcols.h.in @@ -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); diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c index ee40c4090a..8504c2c4d2 100644 --- a/libsmartcols/src/table_print.c +++ b/libsmartcols/src/table_print.c @@ -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); diff --git a/libsmartcols/src/test.c b/libsmartcols/src/test.c index 2d0087e88c..372e2722d9 100644 --- a/libsmartcols/src/test.c +++ b/libsmartcols/src/test.c @@ -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")) {