Skip to content

Commit

Permalink
fix: Correct column widths for empty columns
Browse files Browse the repository at this point in the history
The minimum content width for a column is 1 char, but the
column_max_content_widths function on the table returned a `0` width for
fully empty columns.

This resulted in tables becoming larger than specified if there were any
empty columns.
  • Loading branch information
Nukesor committed Jun 16, 2023
1 parent 93555eb commit f8e4606
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,9 @@ impl Table {
// Get the max width for each cell of the row
let row_max_widths = row.max_content_widths();
for (index, width) in row_max_widths.iter().enumerate() {
let width = (*width).try_into().unwrap_or(u16::MAX);
let mut width = (*width).try_into().unwrap_or(u16::MAX);
// A column's content is at least 1 char wide.
width = std::cmp::max(1, width);

// Set a new max, if the current cell is the longest for that column.
let current_max = max_widths[index];
Expand Down

0 comments on commit f8e4606

Please sign in to comment.