console-rs / indicatif

A command line progress reporting library for Rust
MIT License
4.23k stars 240 forks source link

Spinner running faster than "steady tick" duration in v0.17 #457

Closed sharkdp closed 1 year ago

sharkdp commented 1 year ago

When upgrading to v0.17, I noticed that the spinner may update faster than the rate set in .enable_steady_tick(…).

Background: I use .enable_steady_tick(…) to get a consistent look of my progress bar spinner animation, independent from the actual speed of .inc(…) calls (which I don't know in advance - it might be faster or slower than the rate set for the steady tick). If I update the bar at a low rate, everything is fine. But if I call .inc(…) faster than the rate set in .enable_steady_tick(…), I would still expect the spinner to update at the low refresh rate - instead of flickering arbitrarily fast in v0.17. At least this is how it worked in v0.16, and the name of the function (steady tick) seems to indicate that this is the expected outcome, even if the documentation refers to a use case where the bar is updated at a low speed.

To reproduce this, compare the output of the two programs below, with v0.16 and v0.17 as respective indicatif versions:

v0.16 version (works fine, spinner updates every 200ms)

use indicatif::{ProgressBar, ProgressStyle};
use std::thread;
use std::time::Duration;

fn main() {
    let steps = 10000;

    let progressbar_style = ProgressStyle::default_spinner()
        .template(" {spinner} {wide_bar}");

    let bar = ProgressBar::new(steps);
    bar.set_style(progressbar_style);
    bar.enable_steady_tick(200);

    for _ in 0..steps {
        bar.inc(1);
        thread::sleep(Duration::from_millis(1));
    }
}

v0.17 version (spinner updates very fast, presumably every 1ms)

use indicatif::{ProgressBar, ProgressStyle};
use std::thread;
use std::time::Duration;

fn main() {
    let steps = 10000;

    let progressbar_style = ProgressStyle::default_spinner()
        .template(" {spinner} {wide_bar}")
        .unwrap();

    let bar = ProgressBar::new(steps);
    bar.set_style(progressbar_style);
    bar.enable_steady_tick(Duration::from_millis(200));

    for _ in 0..steps {
        bar.inc(1);
        thread::sleep(Duration::from_millis(1));
    }
}
djc commented 1 year ago

Sorry about that, I think #458 should fix this. Would be great if you can test this!

sharkdp commented 1 year ago

Thank you for the swift reply and fix! Just tested it and it works as expected!