console-rs / indicatif

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

Handle newline in msg and empty msg #540

Closed RDruon closed 1 year ago

RDruon commented 1 year ago

Using println() with a new line at the beginning of the message trigger some artifacts, see below:

newline_artifact.rs

use indicatif::ProgressBar;

fn main() {
    let pb = ProgressBar::new(1024);
    pb.inc(1);
    pb.println("\nShould be a new line before this message and no duplicate progress bar");
    pb.finish_with_message("done");
}

Output on main: image Output with this patch: image


Using println() with an empty string does not trigger new line: empty_msg.rs

use indicatif::ProgressBar;

fn main() {
    let pb = ProgressBar::new(1024);
    pb.inc(1);
    pb.println("");
    pb.println("There should an empty line before this message");
    pb.finish_with_message("done");
}

Output on main: image

Output with this patch: image

New test in render.rs showcase both issue

RDruon commented 1 year ago

This makes sense to me, modulo the formatting issue found in CI.

I fixed the format issue