diff options
author | Karel Zak | 2014-03-19 17:10:50 +0100 |
---|---|---|
committer | Karel Zak | 2014-04-03 12:29:16 +0200 |
commit | 62d2e2e5389daf4120c945300e89705a91d93ff5 (patch) | |
tree | 53c35ad4d318217348b92315ea1fd345e1a36077 /libsmartcols | |
parent | libsmartcols: support alternative streams (diff) | |
download | kernel-qcow2-util-linux-62d2e2e5389daf4120c945300e89705a91d93ff5.tar.gz kernel-qcow2-util-linux-62d2e2e5389daf4120c945300e89705a91d93ff5.tar.xz kernel-qcow2-util-linux-62d2e2e5389daf4120c945300e89705a91d93ff5.zip |
libsmartcols: add SCOLS_FL_MAX
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols')
-rw-r--r-- | libsmartcols/src/libsmartcols.h.in | 11 | ||||
-rw-r--r-- | libsmartcols/src/table_print.c | 18 | ||||
-rw-r--r-- | libsmartcols/src/test.c | 5 |
3 files changed, 25 insertions, 9 deletions
diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in index 9bb7c6480..c5875fd1c 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 ee40c4090..8504c2c4d 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 2d0087e88..372e2722d 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")) { |