Skip to content

improve progress bar, add 'light' type #34

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

Merged
merged 7 commits into from
Sep 15, 2020
Merged

improve progress bar, add 'light' type #34

merged 7 commits into from
Sep 15, 2020

Conversation

epwalsh
Copy link
Owner

@epwalsh epwalsh commented Sep 14, 2020

Adds a method CacheBuilder::progress_bar to set the progress bar type, or to disable the progess bar entirely. The options are ProgressBar::Light and ProgressBar::Full. The default when using cached-path as a library is ProgressBar::Light, while the default from the command-line is ProgressBar::Full.

The full progress bar looks like this:

image

while the light progress bar looks like this (and only updates every 5 seconds):

image

@guillaume-be let me know what you think.

@guillaume-be
Copy link
Contributor

guillaume-be commented Sep 15, 2020

@epwalsh Thank you for working on this! I am mostly interested in the light progress bar so I will focus my comments on this.

  • I am not sure how indicatif flushes the output. Because the light option indicates a time ahead of the line, my guess is that it still refreshes the output and would increment a line for every progress bar step (most likely causing a lot of logging output).

In pure Rust, I believe the below idea would actually be a very lightweight solution that would keep printing without a line return at every step (would be interesting to do a test):

use std::io::{self, Write};
use std::{thread, time};

fn main() {
    eprint!("Downloading [http://xx.ot] to [~/y/y] [178MiB] .");
    let _ = io::stderr().flush();
    for _ in 0..10 {
        eprint!(".");
        thread::sleep(time::Duration::from_millis(250));
        let _ = io::stderr().flush();
    }
    eprint!(" ✓ Done!\n");
    let _ = io::stderr().flush();

    eprint!("Downloading [http://ww.ot] to [~/z/z] [256MiB] .");
    let _ = io::stderr().flush();
    for _ in 0..10 {
        eprint!(".");
        thread::sleep(time::Duration::from_millis(250));
        let _ = io::stderr().flush();
    }
    eprint!(" ✓ Done!\n");
    let _ = io::stderr().flush();
}

@epwalsh
Copy link
Owner Author

epwalsh commented Sep 15, 2020

@guillaume-be okay just made some updates.

@guillaume-be
Copy link
Contributor

Looks great!

@epwalsh
Copy link
Owner Author

epwalsh commented Sep 15, 2020

Great, I'll do another release once I merge this so we can push it upstream 👍

@epwalsh epwalsh merged commit 76a2257 into master Sep 15, 2020
@epwalsh epwalsh deleted the spinner-options branch September 15, 2020 21:10
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 this pull request may close these issues.

2 participants