]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: reset wrap after calculation
authorKarel Zak <kzak@redhat.com>
Tue, 16 Apr 2024 08:49:31 +0000 (10:49 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 16 Apr 2024 08:49:31 +0000 (10:49 +0200)
Fixes: https://github.com/util-linux/util-linux/issues/2956
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/calculate.c
libsmartcols/src/print.c

index 84198da3bcacf8a8caf93bfdc409062a0d50fda6..deabb0794c5a38e21a5fa5aba21f5d4ab013fdf1 100644 (file)
@@ -413,10 +413,8 @@ int __scols_calculate(struct libscols_table *tb, struct ul_buffer *buf)
        size_t colsepsz;
        int sorted = 0;
 
-
        DBG(TAB, ul_debugobj(tb, "-----calculate-(termwidth=%zu)-----", tb->termwidth));
        tb->is_dummy_print = 1;
-
        colsepsz = scols_table_is_noencoding(tb) ?
                        mbs_width(colsep(tb)) :
                        mbs_safe_width(colsep(tb));
@@ -430,6 +428,11 @@ int __scols_calculate(struct libscols_table *tb, struct ul_buffer *buf)
        while (scols_table_next_column(tb, &itr, &cl) == 0) {
                int is_last;
 
+               memset(&cl->wstat, 0, sizeof(cl->wstat));
+               cl->width = 0;
+               cl->width_treeart = 0;
+               scols_column_reset_wrap(cl);
+
                if (scols_column_is_hidden(cl))
                        continue;
 
index a3ef4270a764b931306b047bf171e381bb9f33d3..89d6aba0923ff457aff2167bbaa4617fb751c603 100644 (file)
@@ -778,11 +778,11 @@ notree:
                }
        }
 
+done:
        /* reset wrapping after greatest chunk calculation */
        if (cal && scols_column_is_wrap(cl))
                scols_column_reset_wrap(cl);
 
-done:
        DBG(COL, ul_debugobj(cl, "__cursor_to_buffer rc=%d", rc));
        return rc;
 }
@@ -816,8 +816,12 @@ static int print_line(struct libscols_table *tb,
                rc = __cursor_to_buffer(tb, buf, 0);
                if (!rc)
                        rc = print_data(tb, buf);
-               if (!rc && scols_column_has_pending_wrap(cl))
-                       pending = 1;
+               if (!rc) {
+                       if (scols_column_has_pending_wrap(cl))
+                               pending = 1;
+                       else
+                               scols_column_reset_wrap(cl);
+               }
                scols_table_reset_cursor(tb);
        }
        fputs_color_line_close(tb);
@@ -841,10 +845,12 @@ static int print_line(struct libscols_table *tb,
                                rc = __cursor_to_buffer(tb, buf, 0);
                                if (!rc)
                                        rc = print_pending_data(tb, buf);
-                               if (!rc && scols_column_has_pending_wrap(cl))
-                                       pending = 1;
-                               if (!rc && !pending)
-                                       scols_column_reset_wrap(cl);
+                               if (!rc) {
+                                       if (scols_column_has_pending_wrap(cl))
+                                               pending = 1;
+                                       else
+                                               scols_column_reset_wrap(cl);
+                               }
                        } else
                                print_empty_cell(tb, cl, ln, NULL, ul_buffer_get_bufsiz(buf));
                        scols_table_reset_cursor(tb);