From 56fbf61019971e2dd817f73a8cfe8131e2a6e4db Mon Sep 17 00:00:00 2001 From: solidiquis Date: Sat, 18 May 2024 20:16:06 -0700 Subject: [PATCH] print once for preparing output state --- src/progress.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/progress.rs b/src/progress.rs index be0059a..1c30cee 100644 --- a/src/progress.rs +++ b/src/progress.rs @@ -1,6 +1,8 @@ use crossterm::{ cursor, + execute, ExecutableCommand, + style::Print, terminal::{self, ClearType}, }; use std::{ @@ -14,7 +16,7 @@ use std::{ }; /// For progress indicator to throttle printin. -pub const RENDER_INTERVAL_MS: u64 = 33; +pub const RENDER_INTERVAL_MS: u64 = 16; /// To notify the progress indicator static NOTIFIER: OnceLock> = OnceLock::new(); @@ -37,13 +39,6 @@ enum IndicatorState { PreparingOutput, } -#[derive(Default)] -pub struct FileCounter { - num_file: usize, - num_dir: usize, - num_link: usize, -} - impl Indicator { pub fn init() -> Self { let (tx, rx) = mpsc::channel(); @@ -95,14 +90,12 @@ impl Indicator { if time_last_print.elapsed() < threshold { continue; } - let _ = stdout.execute(terminal::Clear(ClearType::CurrentLine)); let _ = write!(stdout, "{self}"); let _ = stdout.execute(cursor::RestorePosition); time_last_print = std::time::Instant::now(); } self.update_state(IndicatorState::PreparingOutput); - let _ = stdout.execute(terminal::Clear(ClearType::CurrentLine)); - let _ = write!(stdout, "{self}"); + let _ = execute!(stdout, terminal::Clear(ClearType::CurrentLine), Print(self)); }); let out = op();