Skip to content

Commit ce4c34b

Browse files
Reduce flicker
1 parent c05d7f3 commit ce4c34b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/cargo/util/progress.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct State<'cfg> {
3131
throttle: Throttle,
3232
last_line: Option<String>,
3333
fixed_width: Option<usize>,
34+
last_pbar: u8,
3435
}
3536

3637
struct Format {
@@ -100,6 +101,7 @@ impl<'cfg> Progress<'cfg> {
100101
throttle: Throttle::new(),
101102
last_line: None,
102103
fixed_width: progress_config.width,
104+
last_pbar: 255,
103105
}),
104106
}
105107
}
@@ -214,13 +216,12 @@ impl<'cfg> State<'cfg> {
214216
// return back to the beginning of the line for the next print.
215217
self.try_update_max_width();
216218
if let Some(pbar) = self.format.progress(cur, max) {
219+
let prog = ((cur as f32) / (max as f32) * 100.0) as u8;
220+
if self.last_pbar != prog {
221+
write!(self.config.shell().err(), "{}", ProgressCode::Normal(prog))?;
222+
self.last_pbar = prog;
223+
}
217224
self.print(&pbar, msg)?;
218-
let prog = (cur as f32) / (max as f32) * 100.0;
219-
write!(
220-
self.config.shell().err(),
221-
"{}",
222-
ProgressCode::Normal(prog as u8)
223-
)?;
224225
}
225226
Ok(())
226227
}

0 commit comments

Comments
 (0)