Skip to content

Commit 5afa9a4

Browse files
sigmaSddjc
authored andcommitted
Fix panic when calculating padding spaces
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.
1 parent 2fb823d commit 5afa9a4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/draw_target.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ impl ProgressDrawState {
454454
// Keep the cursor on the right terminal side
455455
// So that next user writes/prints will happen on the next line
456456
let line_width = console::measure_text_width(line);
457-
term.write_str(&" ".repeat(term.width() - line_width))?;
457+
term.write_str(&" ".repeat(term.width().saturating_sub(line_width)))?;
458458
}
459459
}
460460

0 commit comments

Comments
 (0)