diff --git a/src/appstate.rs b/src/appstate.rs index 223f799..bff8d96 100644 --- a/src/appstate.rs +++ b/src/appstate.rs @@ -1,7 +1,7 @@ use std::{fmt, io, time::Duration}; use console::style; -use indicatif::{ProgressBar, ProgressStyle}; +use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle}; use log::{debug, warn}; use crate::{ @@ -59,7 +59,7 @@ impl AppState { fn with_progressbar(&mut self, f: impl FnOnce(&ProgressBar), drop_bar: bool) { let bar = &*self.progress.get_or_insert_with(|| { - ProgressBar::no_length().with_style( + ProgressBar::hidden().with_style( ProgressStyle::with_template(&format!( concat!( "{{bar:50.cyan/blue}} {{msg:.magenta}}: ", @@ -74,6 +74,7 @@ impl AppState { if let Some(upl) = self.inner.peek_uploading() { if bar.length().is_none() { + bar.set_draw_target(ProgressDrawTarget::stderr()); bar.set_length(upl.get_size()); bar.set_message(upl.get_name().to_owned()); bar.enable_steady_tick(Duration::from_millis(100)); @@ -119,19 +120,6 @@ impl AppState { Ok(Some(chunk)) } - fn is_done(&mut self) -> bool { - if let Some(path) = self.inner.check_eof() { - debug!("Finished {:?}!", path.display()); - self.drop_progressbar(ProgressBar::finish); - } else if self.inner.peek_uploading().is_some() { - self.touch_progressbar(); - - return false; - } - - self.inner.queue_empty() - } - pub fn upload_chunk(&mut self, buffer: &mut [u8]) -> sharry::Result { let Some(chunk) = self.next_chunk(buffer)? else { self.inner @@ -143,7 +131,14 @@ impl AppState { self.inner.file_patch(&self.http, &chunk)?; - Ok(self.is_done()) + self.touch_progressbar(); + + if let Some(path) = self.inner.check_eof() { + debug!("Finished {:?}!", path.display()); + self.drop_progressbar(ProgressBar::finish); + } + + Ok(self.inner.peek_uploading().is_none() && self.inner.queue_empty()) } pub fn rewind_chunk(mut self) -> Option {