mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-11-26 23:23:20 +03:00
Make the progress bar throttle effective after an initial delay.
This commit is contained in:
parent
fa46a56430
commit
cedd86768c
@ -48,6 +48,8 @@ pub enum Mode {
|
|||||||
|
|
||||||
/// The minimum duration between two progress bar redraw (to avoid flickering).
|
/// The minimum duration between two progress bar redraw (to avoid flickering).
|
||||||
const UPDATE_INTERVAL: Duration = Duration::from_millis(100);
|
const UPDATE_INTERVAL: Duration = Duration::from_millis(100);
|
||||||
|
/// The minimum duration for the progress bar to be throttle (some delay to let the UI stabilize)
|
||||||
|
const FIRST_THROTTLE: Duration = Duration::from_millis(16);
|
||||||
|
|
||||||
impl ParProgress {
|
impl ParProgress {
|
||||||
/// Creates a new instance.
|
/// Creates a new instance.
|
||||||
@ -56,7 +58,7 @@ impl ParProgress {
|
|||||||
max_running_displayed,
|
max_running_displayed,
|
||||||
mode,
|
mode,
|
||||||
color,
|
color,
|
||||||
throttle: Throttle::new(UPDATE_INTERVAL),
|
throttle: Throttle::new(UPDATE_INTERVAL, FIRST_THROTTLE),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,18 +157,24 @@ impl Mode {
|
|||||||
/// just putting stuff onto the terminal. We also want to avoid flickering by not drawing anything
|
/// just putting stuff onto the terminal. We also want to avoid flickering by not drawing anything
|
||||||
/// that goes away too quickly.
|
/// that goes away too quickly.
|
||||||
struct Throttle {
|
struct Throttle {
|
||||||
|
/// Creation time of the progress.
|
||||||
|
start: Instant,
|
||||||
/// Last time the progress bar has be refreshed on the terminal.
|
/// Last time the progress bar has be refreshed on the terminal.
|
||||||
last_update: Option<Instant>,
|
last_update: Option<Instant>,
|
||||||
/// Refresh interval
|
/// Refresh interval
|
||||||
interval: Duration,
|
interval: Duration,
|
||||||
|
/// First interval of non throttle to let the UI initialize
|
||||||
|
first_throttle: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Throttle {
|
impl Throttle {
|
||||||
/// Creates a new instances.
|
/// Creates a new instances.
|
||||||
fn new(interval: Duration) -> Self {
|
fn new(interval: Duration, first_throttle: Duration) -> Self {
|
||||||
Throttle {
|
Throttle {
|
||||||
|
start: Instant::now(),
|
||||||
last_update: None,
|
last_update: None,
|
||||||
interval,
|
interval,
|
||||||
|
first_throttle,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,6 +187,9 @@ impl Throttle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self) {
|
fn update(&mut self) {
|
||||||
|
if self.start.elapsed() < self.first_throttle {
|
||||||
|
return;
|
||||||
|
}
|
||||||
self.last_update = Some(Instant::now());
|
self.last_update = Some(Instant::now());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user