fix some progressbar issues

This commit is contained in:
Jörn-Michael Miehe 2025-06-24 01:11:11 +00:00
parent 686e0c3e5c
commit e61214a589

View file

@ -58,14 +58,9 @@ impl AppState {
} }
fn with_progressbar(&self, drop_bar: bool, f: impl FnOnce(&ProgressBar)) { fn with_progressbar(&self, drop_bar: bool, f: impl FnOnce(&ProgressBar)) {
let Some(upl) = self.inner.peek_uploading() else {
return;
};
let mut slot = self.progress.borrow_mut(); let mut slot = self.progress.borrow_mut();
if slot.is_none() { let bar = &*slot.get_or_insert_with(|| {
let bar = ProgressBar::no_length() ProgressBar::no_length().with_style(
.with_style(
ProgressStyle::with_template(&format!( ProgressStyle::with_template(&format!(
concat!( concat!(
"{{bar:50.cyan/blue}} {{msg:.magenta}}: ", "{{bar:50.cyan/blue}} {{msg:.magenta}}: ",
@ -76,18 +71,20 @@ impl AppState {
)) ))
.expect("style template is not valid"), .expect("style template is not valid"),
) )
.with_message(upl.get_name().to_owned()); });
if let Some(upl) = self.inner.peek_uploading() {
if bar.length().is_none() {
bar.set_length(upl.get_size());
bar.set_message(upl.get_name().to_owned());
bar.enable_steady_tick(Duration::from_millis(100)); bar.enable_steady_tick(Duration::from_millis(100));
*slot = Some(bar);
} }
let bar = slot.as_ref().expect("somehow the slot holds None");
bar.set_position(upl.get_offset()); bar.set_position(upl.get_offset());
// BUG in `indicatif` crate? // BUG in `indicatif` crate?
// `set_position` does not force an immediate redraw, so we need to call `set_length` after // `set_position` does not force an immediate redraw, so we also call `inc_length` here
bar.set_length(upl.get_size()); bar.inc_length(0);
};
f(bar); f(bar);
@ -162,7 +159,6 @@ impl AppState {
self.http self.http
.share_create(&args.get_uri(), &args.alias, args.get_share_request())?; .share_create(&args.get_uri(), &args.alias, args.get_share_request())?;
self.with_progressbar(true, ProgressBar::abandon);
Ok(Self::new(self.http, CacheFile::from_args(args, share_id))) Ok(Self::new(self.http, CacheFile::from_args(args, share_id)))
} }