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

MultiProgress:println doesn't behave correctly when no progress bars have been added yet #447

Open
chris-laplante opened this issue Jul 11, 2022 · 4 comments
Assignees

Comments

@chris-laplante
Copy link
Collaborator

Try this render test:

#[test]
fn multi_progress_println_newline() {
    let in_mem = InMemoryTerm::new(10, 10);
    let mp =
        MultiProgress::with_draw_target(ProgressDrawTarget::term_like(Box::new(in_mem.clone())));

    mp.println("This line is tooooooo long for the terminal\r\n").unwrap();
    mp.println("but it should wrap correctly\r\n").unwrap();

    assert_eq!(in_mem.contents(), "This line\nis toooooo\no long for\n the termi\nnal\nbut it sho\nuld wrap c\norrectly");
}

It fails like this:

---- multi_progress_println_newline stdout ----
thread 'multi_progress_println_newline' panicked at 'assertion failed: `(left == right)`
  left: `"This line\nis toooooo\no long for\n the termi\nnalbut it\nshould wra\np correctl\ny"`,
 right: `"This line\nis toooooo\no long for\n the termi\nnal\nbut it sho\nuld wrap c\norrectly"`', tests/render.rs:607:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The issue is that the underlying DrawState::draw_to_term method assumes that the last line to be drawn doesn't contain a newline. This is true when progress bars are involved, but not true when just calling MultiProgress:println with no progress bars.

I think we need to add some extra logic to draw_to_term so that it behaves differently when no progress bars are present.

The workaround I am using right now is to just use MultiProgress::suspend and then use eprintln! inside that.

@chris-laplante chris-laplante self-assigned this Jul 11, 2022
@chris-laplante
Copy link
Collaborator Author

FYI this is related to #442 I think

@djc
Copy link
Collaborator

djc commented Jul 25, 2022

I think we need to add some extra logic to draw_to_term so that it behaves differently when no progress bars are present.

Seems reasonable.

@Ekleog
Copy link

Ekleog commented Feb 6, 2023

FWIW, this is what it manifests as:

Screenshot from 2023-02-07 00-18-08

fn main() {
    let progress = indicatif::MultiProgress::new();
    progress.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n").unwrap();
    progress.println("bbb\n").unwrap();
}

@Ekleog
Copy link

Ekleog commented Dec 16, 2023

I had some fixes for this issue in #518 ; but they bitrotted before the end of code review; and I don't have any time to allocate it any longer.

Anyone looking at this, feel free to take over #518; as it's probably one rebase away from being able to fix this issue, and I introduced a test there which would easily be able to tell whether the fix actually works :)

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

Successfully merging a pull request may close this issue.

3 participants