From a797704d5d7bed1f665c17e2bce1ed4028250e37 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 4 Jun 2018 15:20:28 +0200 Subject: 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 Signed-off-by: Karel Zak --- libsmartcols/src/table_print.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'libsmartcols') 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; -- cgit v1.2.3-55-g7522