]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- fixed visibility handling for trailing columns 947/head
authorArvin Schnell <aschnell@suse.de>
Mon, 21 Oct 2024 07:10:04 +0000 (09:10 +0200)
committerArvin Schnell <aschnell@suse.de>
Mon, 21 Oct 2024 07:10:04 +0000 (09:10 +0200)
client/utils/Table.cc
testsuite/table.cc

index 7eb8e56eb350469a1ef5cf6ac7cd608cf653065f..d406a6b01eaa516d30064e3f81ddb08263bef18e 100644 (file)
@@ -53,6 +53,8 @@ namespace snapper
            size_t trim = -1;
        };
 
+       size_t last_visible_idx = 0;
+
        vector<ColumnVars> column_vars;
     };
 
@@ -92,6 +94,12 @@ namespace snapper
            calculate_widths(table, row, false, 0);
 
        calculate_abbriviated_widths(table);
+
+       // calculate last visible idx
+
+       for (size_t idx = 0; idx < column_vars.size(); ++idx)
+           if (!column_vars[idx].hidden)
+               last_visible_idx = idx;
     }
 
 
@@ -272,7 +280,7 @@ namespace snapper
                column = output_info.trimmed(column, column_params[idx].align, output_info.column_vars[idx].trim);
 
            bool first = idx == 0;
-           bool last = idx == output_info.column_vars.size() - 1;
+           bool last = idx == output_info.last_visible_idx;
 
            size_t extra = (idx == tree_idx) ? 2 * lasts.size() : 0;
 
@@ -353,7 +361,7 @@ namespace snapper
            for (size_t j = 0; j < output_info.column_vars[idx].width; ++j)
                s << glyph(1);
 
-           if (idx == output_info.column_vars.size() - 1)
+           if (idx == output_info.last_visible_idx)
                break;
 
            s << glyph(1) << glyph(2) << glyph(1);
index 0efb67067039c8cfdb6352bc9db411f7a25b617a..ca36db515b0139931884f3b060cc0ea16366275a 100644 (file)
@@ -205,3 +205,23 @@ BOOST_AUTO_TEST_CASE(test7)
 
     check(table, output);
 }
+
+
+BOOST_AUTO_TEST_CASE(test8)
+{
+    Table table({ "A", "B", Cell("Number", Id::NUMBER, Align::RIGHT) });
+
+    table.set_style(Style::LIGHT);
+    table.set_visibility(Id::NUMBER, Visibility::AUTO);
+
+    Table::Row row1(table, { "a", "b", "" });
+    table.add(row1);
+
+    vector<string> output = {
+       "A │ B",
+       "──┼──",
+       "a │ b"
+    };
+
+    check(table, output);
+}