Skip to content

Commit

Permalink
print once for preparing output state
Browse files Browse the repository at this point in the history
  • Loading branch information
solidiquis committed May 19, 2024
1 parent 8757ec9 commit 56fbf61
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/progress.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crossterm::{
cursor,
execute,
ExecutableCommand,
style::Print,
terminal::{self, ClearType},
};
use std::{
Expand All @@ -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<Sender<Message>> = OnceLock::new();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 56fbf61

Please sign in to comment.