Skip to content

Commit 01a5075

Browse files
committed
- fixed visibility handling for trailing columns
1 parent 6e3a73f commit 01a5075

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

client/utils/Table.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ namespace snapper
5353
size_t trim = -1;
5454
};
5555

56+
size_t last_visible_idx = 0;
57+
5658
vector<ColumnVars> column_vars;
5759
};
5860

@@ -92,6 +94,12 @@ namespace snapper
9294
calculate_widths(table, row, false, 0);
9395

9496
calculate_abbriviated_widths(table);
97+
98+
// calculate last visible idx
99+
100+
for (size_t idx = 0; idx < column_vars.size(); ++idx)
101+
if (!column_vars[idx].hidden)
102+
last_visible_idx = idx;
95103
}
96104

97105

@@ -272,7 +280,7 @@ namespace snapper
272280
column = output_info.trimmed(column, column_params[idx].align, output_info.column_vars[idx].trim);
273281

274282
bool first = idx == 0;
275-
bool last = idx == output_info.column_vars.size() - 1;
283+
bool last = idx == output_info.last_visible_idx;
276284

277285
size_t extra = (idx == tree_idx) ? 2 * lasts.size() : 0;
278286

@@ -353,7 +361,7 @@ namespace snapper
353361
for (size_t j = 0; j < output_info.column_vars[idx].width; ++j)
354362
s << glyph(1);
355363

356-
if (idx == output_info.column_vars.size() - 1)
364+
if (idx == output_info.last_visible_idx)
357365
break;
358366

359367
s << glyph(1) << glyph(2) << glyph(1);

testsuite/table.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,23 @@ BOOST_AUTO_TEST_CASE(test7)
205205

206206
check(table, output);
207207
}
208+
209+
210+
BOOST_AUTO_TEST_CASE(test8)
211+
{
212+
Table table({ "A", "B", Cell("Number", Id::NUMBER, Align::RIGHT) });
213+
214+
table.set_style(Style::LIGHT);
215+
table.set_visibility(Id::NUMBER, Visibility::AUTO);
216+
217+
Table::Row row1(table, { "a", "b", "" });
218+
table.add(row1);
219+
220+
vector<string> output = {
221+
"A │ B",
222+
"──┼──",
223+
"a │ b"
224+
};
225+
226+
check(table, output);
227+
}

0 commit comments

Comments
 (0)