ProgressBar handling simplification

This commit is contained in:
Jörn-Michael Miehe 2025-06-26 00:08:18 +00:00
parent 3258b8fb74
commit 5adbf8cb38
3 changed files with 4 additions and 8 deletions

View file

@ -1,6 +1,6 @@
use std::{fmt, io, time::Duration}; use std::{fmt, io, time::Duration};
use indicatif::{ProgressBar, ProgressDrawTarget}; use indicatif::ProgressBar;
use log::{debug, warn}; use log::{debug, warn};
use crate::{ use crate::{
@ -62,7 +62,6 @@ impl AppState {
if let Some(upl) = self.inner.peek_uploading() { if let Some(upl) = self.inner.peek_uploading() {
if bar.length().is_none() { if bar.length().is_none() {
bar.set_draw_target(ProgressDrawTarget::stderr());
bar.set_length(upl.get_size()); bar.set_length(upl.get_size());
bar.set_message(upl.get_name().to_owned()); bar.set_message(upl.get_name().to_owned());
bar.enable_steady_tick(Duration::from_millis(100)); bar.enable_steady_tick(Duration::from_millis(100));
@ -70,8 +69,7 @@ impl AppState {
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 also call `inc_length` here // `set_position` does not force an immediate redraw like e.g. `inc_length`
bar.inc_length(0);
} }
f(bar); f(bar);

View file

@ -6,7 +6,7 @@ use std::{
time::Duration, time::Duration,
}; };
use indicatif::{ProgressBar, ProgressDrawTarget}; use indicatif::ProgressBar;
use log::{info, trace}; use log::{info, trace};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -87,7 +87,6 @@ impl CacheFile {
}; };
let bar = new_progressbar(); let bar = new_progressbar();
bar.set_draw_target(ProgressDrawTarget::stderr());
bar.set_length(total_size); bar.set_length(total_size);
bar.enable_steady_tick(Duration::from_millis(50)); bar.enable_steady_tick(Duration::from_millis(50));
@ -115,7 +114,6 @@ impl CacheFile {
info!("hashing files {files:?}"); info!("hashing files {files:?}");
let bar = new_progressbar(); let bar = new_progressbar();
bar.set_draw_target(ProgressDrawTarget::stderr());
// BOOKMARK assumption: total file size < 2 EiB // BOOKMARK assumption: total file size < 2 EiB
bar.set_length(files.iter().map(FileTrait::get_size).sum()); bar.set_length(files.iter().map(FileTrait::get_size).sum());
bar.enable_steady_tick(Duration::from_millis(50)); bar.enable_steady_tick(Duration::from_millis(50));

View file

@ -63,7 +63,7 @@ where
#[must_use] #[must_use]
#[allow(clippy::missing_panics_doc)] #[allow(clippy::missing_panics_doc)]
pub fn new_progressbar() -> ProgressBar { pub fn new_progressbar() -> ProgressBar {
ProgressBar::hidden().with_style( ProgressBar::no_length().with_style(
ProgressStyle::with_template(&format!( ProgressStyle::with_template(&format!(
concat!( concat!(
"{{bar:50.cyan/blue}} {{msg:.magenta}}: ", "{{bar:50.cyan/blue}} {{msg:.magenta}}: ",