Skip to content

Commit

Permalink
Fix panic when calculating padding spaces
Browse files Browse the repository at this point in the history
The user progress template can exceed the terminal width, so we use a
`saturating_sub` when calculating padding spaces to clamp it at 0 in
this case.
  • Loading branch information
sigmaSd authored and djc committed Feb 5, 2022
1 parent 2fb823d commit 5afa9a4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/draw_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ impl ProgressDrawState {
// Keep the cursor on the right terminal side
// So that next user writes/prints will happen on the next line
let line_width = console::measure_text_width(line);
term.write_str(&" ".repeat(term.width() - line_width))?;
term.write_str(&" ".repeat(term.width().saturating_sub(line_width)))?;
}
}

Expand Down

0 comments on commit 5afa9a4

Please sign in to comment.