-
Notifications
You must be signed in to change notification settings - Fork 245
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
Long progress bar results in new-lines #144
Comments
You can use
Keep in mind that there can only be one |
Thanks for your reply @mibac138. Unfortunately, even when using Do you have any suggestions? |
Unfortunately, I think your best bet is to just shorten the style of the progress bar or expand your terminal. Alternatively you could also somewhat abuse the system and use two progressbars instead of one. Code: use std::cmp::min;
use std::thread;
use std::time::Duration;
use indicatif::{ProgressBar, ProgressStyle, MultiProgress};
fn main() {
let mut downloaded = 0;
let total_size = 231231231;
let mpb = MultiProgress::new();
let pb = mpb.add(ProgressBar::new(total_size));
pb.set_style(ProgressStyle::default_bar()
.template("{msg:>12.cyan.bold} {spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}]")
.progress_chars("#>-"));
let pb2 = mpb.add(ProgressBar::new(total_size));
pb2.set_style(ProgressStyle::default_bar()
.template("{_:>15}{bytes}/{total_bytes} ({bytes_per_sec}, {eta})"));
let handle = std::thread::spawn(move || {
mpb.join().unwrap();
});
pb.set_message("Downloading");
while downloaded < total_size {
let new = min(downloaded + 223211, total_size);
downloaded = new;
pb.set_position(new);
pb2.set_position(new);
thread::sleep(Duration::from_millis(1));
}
pb.set_style(
ProgressStyle::default_bar().template("{msg:>12.green.bold} downloading {total_bytes:.green} in {elapsed:.green}"),
);
pb.finish_with_message("Finished");
pb2.finish_and_clear();
handle.join().unwrap();
} |
I think that I'll use a shorter template if the console isn't wide enough. |
I just hit this too. In my case It doesn't seem like anyone would actually want the behavior of lines scrolling down the screen if the message is too long for the terminal. Shouldn't truncation be the default? It would also be really nice to avoid apps using this library needing to reason about terminal width themselves, which can otherwise be entirely delegated to indicatif. |
Description
When using a
ProgressBar
that is longer than the width of the terminal, the progress bar doesn't clear itself, but instead prints a new line for each update.CMD
Git Bash
Powershell
The above gifs show the following code:
P.S. - This library is awesome! Thanks for making it 😄
The text was updated successfully, but these errors were encountered: