From: Karel Zak Date: Thu, 12 Mar 2026 09:40:45 +0000 (+0100) Subject: libsmartcols: enlarge columns with absolute width hint X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bbc305bb1ad39c7dc998491a700d4f8c3907b85f;p=thirdparty%2Futil-linux.git libsmartcols: enlarge columns with absolute width hint The width hint is strictly followed only if SCOLS_FL_STRICTWIDTH is specified. The previous patch ensures minimal space usage for all other columns. This patch enlarges columns with an absolute hint (> 1.0) until the hints are satisfied and there is free space on screen. Signed-off-by: Karel Zak --- diff --git a/libsmartcols/src/calculate.c b/libsmartcols/src/calculate.c index 91c831cea..efcb5b6af 100644 --- a/libsmartcols/src/calculate.c +++ b/libsmartcols/src/calculate.c @@ -214,12 +214,13 @@ static int count_column_width(struct libscols_table *tb, /* this is default, may be later reduced */ cl->width = st->width_max; - /* enlarge to minimal width */ + /* enlarge to minimal width (usually header width) */ if (cl->width <= st->width_min && !scols_column_is_strict_width(cl)) cl->width = st->width_min; - /* use absolute size for large columns */ - else if (cl->width_hint >= 1 && cl->width < (size_t) cl->width_hint + /* use absolute width if specified (usually "strictwidth" columns) */ + else if (cl->width_hint >= 1 + && cl->width < (size_t) cl->width_hint && st->width_min < (size_t) cl->width_hint) cl->width = (size_t) cl->width_hint; @@ -560,6 +561,35 @@ int __scols_calculate(struct libscols_table *tb, struct ul_buffer *buf) } } + if (width < tb->outwidth) { + DBG(TAB, ul_debugobj(tb, " enlarge (absolute, available %zu)", + tb->outwidth - width)); + + /* try enlarging all columns with absolute hint */ + while (width < tb->outwidth) { + int changed = 0; + + scols_reset_iter(&itr, SCOLS_ITER_BACKWARD); + while (scols_table_next_column(tb, &itr, &cl) == 0) { + if (scols_column_is_hidden(cl)) + continue; + if (cl->width_hint < 1.0) + continue; + if (cl->width >= (size_t) cl->width_hint) + continue; + DBG(COL, ul_debugobj(cl, " add +1 (%s)", + cl->header.data)); + cl->width++; + width++; + changed++; + if (width == tb->outwidth) + break; + } + if (!changed) + break; + } + + } if (width < tb->outwidth && scols_table_is_maxout(tb)) { DBG(TAB, ul_debugobj(tb, " enlarge (max-out, available %zu)", tb->outwidth - width)); @@ -578,6 +608,7 @@ int __scols_calculate(struct libscols_table *tb, struct ul_buffer *buf) break; } } + } else if (width < tb->outwidth) { /* enlarge the last column */ DBG(TAB, ul_debugobj(tb, " enlarge (last column, available %zu)",