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

finish_with_message method does not end message with newline #461

Closed
lucatrv opened this issue Aug 6, 2022 · 9 comments
Closed

finish_with_message method does not end message with newline #461

lucatrv opened this issue Aug 6, 2022 · 9 comments

Comments

@lucatrv
Copy link

lucatrv commented Aug 6, 2022

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:

  • Windows 10 x64
  • rustc 1.62.1
  • indicatif 0.17.0
@chris-laplante
Copy link
Collaborator

chris-laplante commented Aug 15, 2022

To check my understanding, you are seeing this:

  Done                                                                                                                                                                                                                                                        
Test

But you are expecting this:

  Done                                                                                                                                                                                                                                                        

Test

Is that right?

@lucatrv
Copy link
Author

lucatrv commented Aug 17, 2022

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
Copy link
Collaborator

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
Copy link
Author

lucatrv commented Aug 17, 2022

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
Copy link
Collaborator

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
Copy link
Collaborator

djc commented Aug 17, 2022

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
Copy link
Author

lucatrv commented Aug 17, 2022

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!

@lucatrv lucatrv closed this as completed Aug 17, 2022
@chris-laplante
Copy link
Collaborator

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
Copy link
Author

lucatrv commented Aug 18, 2022

@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.

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

3 participants