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,36 +58,33 @@ 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}}: ", "{{binary_bytes:.yellow}}{}{{binary_total_bytes:.yellow}} ",
"{{binary_bytes:.yellow}}{}{{binary_total_bytes:.yellow}} ", "({{eta}})",
"({{eta}})", ),
), style("/").magenta(),
style("/").magenta(), ))
)) .expect("style template is not valid"),
.expect("style template is not valid"), )
) });
.with_message(upl.get_name().to_owned());
bar.enable_steady_tick(Duration::from_millis(100)); if let Some(upl) = self.inner.peek_uploading() {
*slot = Some(bar); 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));
}
let bar = slot.as_ref().expect("somehow the slot holds None"); bar.set_position(upl.get_offset());
// BUG in `indicatif` crate?
bar.set_position(upl.get_offset()); // `set_position` does not force an immediate redraw, so we also call `inc_length` here
// BUG in `indicatif` crate? bar.inc_length(0);
// `set_position` does not force an immediate redraw, so we need to call `set_length` after };
bar.set_length(upl.get_size());
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)))
} }