console-rs / indicatif

A command line progress reporting library for Rust
MIT License
4.22k stars 238 forks source link

`ProgressBar::with_message` does nothing? #528

Closed lnicola closed 1 year ago

lnicola commented 1 year ago

I couldn't find an example or an existing issue about this. What does the message do?

Minimal example:

use std::{thread, time::Duration};

use indicatif::ProgressBar;

fn main() {
    let pb = ProgressBar::new(100).with_message("Frobbing the widget");
    for _ in 0..100 {
        thread::sleep(Duration::from_millis(30));
        pb.inc(1);
    }
}
djc commented 1 year ago

Right, I suppose the API is a little confusing. with_message() sets a message, but the message only shows up if you're using a template that includes a {message} field. Want to submit a documentation clarification PR?

lnicola commented 1 year ago

So something like

use std::{thread, time::Duration};

use indicatif::{ProgressBar, ProgressStyle};

fn main() {
    let style = ProgressStyle::with_template("{message} {wide_bar} {pos}/{len}")
        .expect("compile-time constant");
    let pb = ProgressBar::new(100)
        .with_style(style)
        .with_message("Frobbing the widget");
    for _ in 0..100 {
        thread::sleep(Duration::from_millis(30));
        pb.inc(1);
    }
}

?

djc commented 1 year ago

Yup!

lnicola commented 1 year ago

But it still doesn't show up :smile:.

chris-laplante commented 1 year ago

But it still doesn't show up 😄.

Instead of {message}, it should be {msg}