console-rs / indicatif

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

Duplicate bars if the message is too long #520

Closed kmanc closed 1 year ago

kmanc commented 1 year ago

I haven't been able to nail down exactly what the cause is for this, so a little bit of trial and error might be required to reproduce, but I've noticed that if I set a bar message to something that is "too long" my MultiProgress / ProgressBar combination starts behaving oddly. Is there anyone who can shed some light on why that is?

Rough setup

use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use std::sync::Arc;

let mp = Arc::new(MultiProgress::new());
let bar = mp.clone().add(ProgressBar::new(0));
let style = ProgressStyle::with_template("{msg}").unwrap();
bar.set_style(style);
let message = "SOMETHING HERE";
bar.set_message(message.clone());
let message = format!("{message} LONGER");
bar.finish_with_message(message);

I've found that if I keep making "message" longer, eventually the bars start double or triple printing. I've poked around in the codebase but I'm not sure why that is, so any insight would be appreciated.

Thanks!

eggyal commented 1 year ago

Just ran into this myself and, at least in my case, it was because something else was being written to the terminal "behind" the MultiProgress, which caused it to redraw (in the wrong place). Using MultiProgress::suspend for that other output resolved the issue for me.

kmanc commented 1 year ago

Interesting! I don't think that is/was the case for me, and I think the little POC above can replicate without that condition, but I wonder if that points to a particular reason why this might occur. Thanks for reporting!

djc commented 1 year ago

@kmanc have you tried #533? Would be good to know if that fixes your issue.

azriel91 commented 1 year ago

Heya @djc, I've tried the latest code on main and it fixes the issue for me :v:.

djc commented 1 year ago

Thanks! Going to optimistically close this, please reopen if you're still seeing this with current main.

lgarron commented 1 year ago

Thanks! Going to optimistically close this, please reopen if you're still seeing this with current main.

I just tried 7c9465b75b2d8a284cde24bcf57636aa8489e2e0, and while https://github.com/console-rs/indicatif/pull/533 seems to be well resolved when the terminal is too narrow, this issue still seems to occur if the terminal is not tall enough.

OS: macOS Venture 13.4 cargo: 1.68.2 Repro branch: https://github.com/lgarron/folderify/tree/indicatif-v0.17.4