linya
linya copied to clipboard
Add support for unknown-size bars
I'm using this library for showing download progress. Occasionally, servers don't specify a Content-Length header, so the total download size is unknown.
This lead to my code calling progress.bar(0) which works, but leads to a panic later on when progress.set_and_draw(&bar, value) is called:
thread 'main' panicked at 'attempt to divide by zero', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/linya-0.2.1/src/lib.rs:200:28
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
My current workaround is this:
let bar_size = if download_size > 0 { download_size } else { 1 };
let progress_bar = progress.bar(bar_size, &url);
This works, but it's not apparent to the user that his progress bar is not finished yet. It would be nice if there was some kind of spinner style bar when the total size is 0 (that is updated manually each time set_and_draw is used), and some explicit way to mark the bar as finished.
(Thanks for this great library btw, finally one that actually supports multibars with a single thread).
Spinner support has been on my mind for some time. It seems like a definite lack of an important feature here.