diff options
Diffstat (limited to 'libsmartcols/src/calculate.c')
-rw-r--r-- | libsmartcols/src/calculate.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/libsmartcols/src/calculate.c b/libsmartcols/src/calculate.c index 8dd65a254..a1224adee 100644 --- a/libsmartcols/src/calculate.c +++ b/libsmartcols/src/calculate.c @@ -32,7 +32,6 @@ static void dbg_columns(struct libscols_table *tb) dbg_column(tb, cl); } - /* * This function counts column width. * @@ -141,14 +140,21 @@ int __scols_calculate(struct libscols_table *tb, struct libscols_buffer *buf) struct libscols_iter itr; size_t width = 0, width_min = 0; /* output width */ int stage, rc = 0; - int extremes = 0; + int extremes = 0, group_ncolumns = 0; size_t colsepsz; - DBG(TAB, ul_debugobj(tb, "recounting widths (termwidth=%zu)", tb->termwidth)); + DBG(TAB, ul_debugobj(tb, "-----calculate-(termwidth=%zu)-----", tb->termwidth)); colsepsz = mbs_safe_width(colsep(tb)); + if (has_groups(tb)) { + rc = scols_groups_calculate_grpset(tb); + if (rc) + goto done; + group_ncolumns = 1; + } + /* set basic columns width */ scols_reset_iter(&itr, SCOLS_ITER_FORWARD); @@ -157,6 +163,13 @@ int __scols_calculate(struct libscols_table *tb, struct libscols_buffer *buf) if (scols_column_is_hidden(cl)) continue; + + /* we print groups chart only for the for the first tree column */ + if (scols_column_is_tree(cl) && group_ncolumns == 1) { + cl->is_groups = 1; + group_ncolumns++; + } + rc = count_column_width(tb, cl, buf); if (rc) goto done; @@ -165,7 +178,8 @@ int __scols_calculate(struct libscols_table *tb, struct libscols_buffer *buf) width += cl->width + (is_last ? 0 : colsepsz); /* separator for non-last column */ width_min += cl->width_min + (is_last ? 0 : colsepsz); - extremes += cl->is_extreme; + if (cl->is_extreme) + extremes++; } if (!tb->is_term) { |