summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs68
1 files changed, 38 insertions, 30 deletions
diff --git a/src/main.rs b/src/main.rs
index bbff712..f17d9d9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,8 +4,8 @@ use crate::run::{reset, run};
use crate::verify::verify;
use clap::{Parser, Subcommand};
use console::Emoji;
-use notify::DebouncedEvent;
-use notify::{RecommendedWatcher, RecursiveMode, Watcher};
+use notify_debouncer_mini::notify::{self, RecursiveMode};
+use notify_debouncer_mini::{new_debouncer, DebouncedEventKind};
use std::ffi::OsStr;
use std::fs;
use std::io::{self, prelude::*};
@@ -331,8 +331,10 @@ fn watch(
let (tx, rx) = channel();
let should_quit = Arc::new(AtomicBool::new(false));
- let mut watcher: RecommendedWatcher = Watcher::new(tx, Duration::from_secs(1))?;
- watcher.watch(Path::new("./exercises"), RecursiveMode::Recursive)?;
+ let mut debouncer = new_debouncer(Duration::from_secs(1), tx)?;
+ debouncer
+ .watcher()
+ .watch(Path::new("./exercises"), RecursiveMode::Recursive)?;
clear_screen();
@@ -350,38 +352,44 @@ fn watch(
loop {
match rx.recv_timeout(Duration::from_secs(1)) {
Ok(event) => match event {
- DebouncedEvent::Create(b) | DebouncedEvent::Chmod(b) | DebouncedEvent::Write(b) => {
- if b.extension() == Some(OsStr::new("rs")) && b.exists() {
- let filepath = b.as_path().canonicalize().unwrap();
- let pending_exercises = exercises
- .iter()
- .find(|e| filepath.ends_with(&e.path))
- .into_iter()
- .chain(
+ Ok(events) => {
+ for event in events {
+ let event_path = event.path;
+ if event.kind == DebouncedEventKind::Any
+ && event_path.extension() == Some(OsStr::new("rs"))
+ && event_path.exists()
+ {
+ let filepath = event_path.as_path().canonicalize().unwrap();
+ let pending_exercises =
exercises
.iter()
- .filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)),
- );
- let num_done = exercises
- .iter()
- .filter(|e| e.looks_done() && !filepath.ends_with(&e.path))
- .count();
- clear_screen();
- match verify(
- pending_exercises,
- (num_done, exercises.len()),
- verbose,
- success_hints,
- ) {
- Ok(_) => return Ok(WatchStatus::Finished),
- Err(exercise) => {
- let mut failed_exercise_hint = failed_exercise_hint.lock().unwrap();
- *failed_exercise_hint = Some(to_owned_hint(exercise));
+ .find(|e| filepath.ends_with(&e.path))
+ .into_iter()
+ .chain(exercises.iter().filter(|e| {
+ !e.looks_done() && !filepath.ends_with(&e.path)
+ }));
+ let num_done = exercises
+ .iter()
+ .filter(|e| e.looks_done() && !filepath.ends_with(&e.path))
+ .count();
+ clear_screen();
+ match verify(
+ pending_exercises,
+ (num_done, exercises.len()),
+ verbose,
+ success_hints,
+ ) {
+ Ok(_) => return Ok(WatchStatus::Finished),
+ Err(exercise) => {
+ let mut failed_exercise_hint =
+ failed_exercise_hint.lock().unwrap();
+ *failed_exercise_hint = Some(to_owned_hint(exercise));
+ }
}
}
}
}
- _ => {}
+ Err(e) => println!("watch error: {e:?}"),
},
Err(RecvTimeoutError::Timeout) => {
// the timeout expired, just check the `should_quit` variable below then loop again