console-rs / indicatif

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

`finish_with_message` method does not end message with newline #461

Closed lucatrv closed 1 year ago

lucatrv commented 1 year ago

I implemented the following spinner:

let pb = ProgressBar::new_spinner().with_style(
        ProgressStyle::with_template("{spinner:.bold.bright.yellow} {wide_msg}")
            .unwrap()
            .tick_chars("/|\\- "),
    );

Then if I issue:

pb.finish_with_message("Done");
println!("\nTest");

I do not get the expected line gap between "Done" and "Test". To make this work I need to issue:

pb.finish_with_message("Done");
println!();
println!("\nTest");

Apparently the finish_with_message method does not end its message with a newline.

I'm on:

chris-laplante commented 1 year ago

To check my understanding, you are seeing this:

  Done                                                                                                                                                                                                                                                        
Test

But you are expecting this:

  Done                                                                                                                                                                                                                                                        

Test

Is that right?

lucatrv commented 1 year ago

Yes that's correct, and now I found out that the same happens if I issue:

pb.finish_with_message("Done");
println!("Test");

So to recap, if I issue:

pb.finish_with_message("Done");
println!("Test");

or:

pb.finish_with_message("Done");
println!();
println!("Test");

or:

pb.finish_with_message("Done");
println!("\nTest");

I always get:

  Done
Test

While to get a newline gap:

  Done

Test

I have to issue:

pb.finish_with_message("Done");
println!();
println!("\nTest");
chris-laplante commented 1 year ago

While to get a newline gap:

  Done

Test

I have to issue:

pb.finish_with_message("Done");
println!();
println!("\nTest");

OK, thanks for clarifying. I don't see any behavior out of the ordinary here, and I'd say it is working as expected. One reason why finish_with_message doesn't automatically add a newline is that there is no requirement that the message be the last element of the progress bar. You could also do something like this:

ProgressStyle::with_template("{spinner:.bold.bright.yellow} {wide_msg} More text!")

... in which case it doesn't make sense to add \n automatically.

lucatrv commented 1 year ago

I agree that when the finish_with_message is run, whatever is defined in the template should be printed out, but IMHO after everything is printed out it should also be ended with a new line character, so that the bar/spinner is actually "finished".

Considering this example:

ProgressStyle::with_template("{spinner:.bold.bright.yellow} {wide_msg} More text!")

in my opinion a new line should be added after More text!.

chris-laplante commented 1 year ago

Considering this example:

ProgressStyle::with_template("{spinner:.bold.bright.yellow} {wide_msg} More text!")

in my opinion a new line should be added after More text!.

I don't think we'll be able to change the semantics of finish_with_message, sorry :/. Perhaps @djc can chime in. For your particular use case, I think that once #443 lands you should be able to do finish_with_message("Done\n") to add that extra newline.

djc commented 1 year ago

Yeah, I don't think it makes sense to change this -- in part, because there's some asymmetry here: if we print an extra newline, there's no trivial way for you to remove it, but it's usually pretty easy for you to print an extra newline.

lucatrv commented 1 year ago

For your particular use case, I think that once #443 lands you should be able to do finish_with_message("Done\n") to add that extra newline.

That would be a good solution, I tried that myself before opening this issue and it did not work. So I'll wait for #443 to be merged. Thanks!

chris-laplante commented 1 year ago

That would be a good solution, I tried that myself before opening this issue and it did not work. So I'll wait for #443 to be merged. Thanks!

Sure thing, thanks for understanding :)

lucatrv commented 1 year ago

@chris-laplante thanks a lot for your support!

Just for your information, another option would be to implement a new method finish_with_message_ln which runs finish_with_message and then adds a newline character. If that would be interesting for you to have I can issue a pull request, otherwise I will just wait for #443 to land.