libsmartcols: don't print empty column
The commit 0f9f927b6f
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 '🅰️b\n' | column -t -s ':' -o ':'
🅰️b
Fixed version:
$ printf '🅰️b\n' | column -t -s ':' -o ':'
🅰️b
Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
6691d53797
commit
a797704d5d
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue