Skip to content

Commit

Permalink
Handle empty columns in estimate output
Browse files Browse the repository at this point in the history
  • Loading branch information
dalegaard committed Jan 17, 2022
1 parent 1af9f5c commit 04d38ac
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tool/src/cmd/estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ impl EstimateCmd {

let num_columns =
((available_width - column) / (column + spacing.len()) + 1).max(1);
let num_chunks = layer_times.len() / num_columns
let chunk_size = layer_times.len() / num_columns
+ usize::from(layer_times.len() % num_columns != 0);
let columnized = layer_times.chunks(num_chunks).collect::<Vec<_>>();
let columnized = layer_times.chunks(chunk_size).collect::<Vec<_>>();
for line in 0.. {
if columnized
.iter()
Expand All @@ -254,7 +254,9 @@ impl EstimateCmd {

print!("{offset}");
for i in 0..num_columns {
if let Some((t, l)) = columnized[i].get(line) {
if let Some((t, l)) =
columnized.get(i).and_then(|col| col.get(line))
{
if i > 0 {
print!("{spacing}");
}
Expand Down

0 comments on commit 04d38ac

Please sign in to comment.