Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

per_sec does not respect width specifier #663

Open
rlee287 opened this issue Oct 22, 2024 · 3 comments
Open

per_sec does not respect width specifier #663

rlee287 opened this issue Oct 22, 2024 · 3 comments

Comments

@rlee287
Copy link
Contributor

rlee287 commented Oct 22, 2024

Reproducer (using indicatif 0.17.8, default feature set):

use indicatif::{ProgressBar, ProgressStyle};

fn main() {
    let pb_style = ProgressStyle::default_bar()
        .template("{bar:16} | {pos:>6}/{len:6} | {per_sec:>8}")
        .unwrap();

    let pb = ProgressBar::new(100000).with_style(pb_style);

    for _ in 0..1000 {
        std::thread::sleep(std::time::Duration::from_secs_f64(0.01));
        pb.inc(100);
    }
    pb.finish();
}

The progress bar that's left after the program runs:

████████████████ | 100000/100000 | 9,631.6687/s

Despite per_sec specifying a width of 8 characters, the final per_sec display is 12 characters wide. I would have expected the formatter to trim the number of digits after the decimal point to reduce the width instead.

Compressed asciinema recording of the above program running on my machine:

pb_per_sec.cast.gz

@djc
Copy link
Member

djc commented Oct 23, 2024

Have you tried main? IIRC there have been some improvements in this area.

@rlee287
Copy link
Contributor Author

rlee287 commented Oct 23, 2024

The same problem occurs when I specify a Git dependency for indicatif using the default commit (branch main, commit 5396704 as of time of writing).

@djc
Copy link
Member

djc commented Oct 24, 2024

Hmm, I'm a little skeptical that other width specifiers (either in indicatif or in the Rust formatting machinery) ever trim -- I think they mostly only expand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants