MichalGniadek/klask

Add an option to add a progress bar to the GUI

Closed this issue · 2 comments

For a process that takes a long time, I used indicatif in the command line to get a progress bar

It would be neat if you could feed a progress bar from indicatif to the config and display it in the GUI to visualize progression, maybe behind a feature flag?

The output at the bottom of the GUI updates dynamically (so not only when the process ends). It doesn't currently support clearing lines and other complex things required for updating progress bars, but if I added this you could use indicatif directly, and it would show up in the output!
This has an additional advantage — you can use the same code between GUI and CLI if you have them both.

I have been looking into it, and it turned out that I would probably have to dive into unsafe and windows/ unix api to get it working like I described in the previous comment. So I decided to add “native” progress bars because they are still a good idea!

image

And this is the code:

const MAX: u64 = 100;
for i in 0..=MAX {
    // You must pass in a value between [0, 1]
    klask::progress_bar("Static description", i as f32 / MAX as f32);
    klask::progress_bar_with_id(
        "Progress", // has to be a hashable id that identifies this progress bar
        &format!("Dynamic description [{}/{}]", i, MAX),
        i as f32 / MAX as f32,
    );

    thread::sleep(Duration::from_millis(20));
}

It doesn't use indicatif but you can easily plug values from indicatif::ProgressBar into it!