diff options
author | Karel Zak | 2018-06-04 15:20:28 +0200 |
---|---|---|
committer | Karel Zak | 2018-06-04 15:20:28 +0200 |
commit | a797704d5d7bed1f665c17e2bce1ed4028250e37 (patch) | |
tree | 9668465f063b7718005c60c3dd515046a72ddbec | |
parent | mount: keep MS_MOVE as flag (diff) | |
download | kernel-qcow2-util-linux-a797704d5d7bed1f665c17e2bce1ed4028250e37.tar.gz kernel-qcow2-util-linux-a797704d5d7bed1f665c17e2bce1ed4028250e37.tar.xz kernel-qcow2-util-linux-a797704d5d7bed1f665c17e2bce1ed4028250e37.zip |
libsmartcols: don't print empty column
The commit 0f9f927b6f62cb7f488fadfad76c4a5defdefe36 forces
libsmartcols to use one byte as a minimal column width. This seems
like a bug if the column is empty and without header.
$ printf ':a:b\n' | column -t -s ':' -o ':'
:a:b
Fixed version:
$ printf ':a:b\n' | column -t -s ':' -o ':'
:a:b
Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r-- | libsmartcols/src/table_print.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c index 10126fd79..ae8d2da1c 100644 --- a/libsmartcols/src/table_print.c +++ b/libsmartcols/src/table_print.c @@ -1067,7 +1067,7 @@ static int count_column_width(struct libscols_table *tb, { struct libscols_line *ln; struct libscols_iter itr; - int count = 0, rc = 0; + int count = 0, rc = 0, no_header = 0; size_t sum = 0; assert(tb); @@ -1083,7 +1083,9 @@ static int count_column_width(struct libscols_table *tb, if (scols_cell_get_data(&cl->header)) { size_t len = mbs_safe_width(scols_cell_get_data(&cl->header)); cl->width_min = max(cl->width_min, len); - } + } else + no_header = 1; + if (!cl->width_min) cl->width_min = 1; } @@ -1139,6 +1141,11 @@ static int count_column_width(struct libscols_table *tb, cl->width = (size_t) cl->width_hint; + + /* Column without header and data, set minimal size to zero (default is 1) */ + if (cl->width_max == 0 && no_header && cl->width_min == 1 && cl->width <= 1) + cl->width = cl->width_min = 0; + done: ON_DBG(COL, dbg_column(tb, cl)); return rc; |