Skip to content

Commit

Permalink
improvement(watch): clear screen before each verify()
Browse files Browse the repository at this point in the history
Closes #146
  • Loading branch information
WofWca committed Nov 9, 2019
1 parent c8babba commit 3aff590
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ fn main() {
}

if matches.subcommand_matches("watch").is_some() {
/* Clears the terminal with an ANSI escape code.
Works in UNIX and newer Windows terminals. */
println!("\x1Bc");
watch(&exercises).unwrap();
}

Expand All @@ -93,23 +90,30 @@ fn main() {
}

fn watch(exercises: &[Exercise]) -> notify::Result<()> {
/* Clears the terminal with an ANSI escape code.
Works in UNIX and newer Windows terminals. */
fn clear_screen() {
println!("\x1Bc");
}

let (tx, rx) = channel();

let mut watcher: RecommendedWatcher = Watcher::new(tx, Duration::from_secs(2))?;
watcher.watch(Path::new("./exercises"), RecursiveMode::Recursive)?;

clear_screen();
let _ignored = verify(exercises.iter());

loop {
match rx.recv() {
Ok(event) => match event {
DebouncedEvent::Create(b) | DebouncedEvent::Chmod(b) | DebouncedEvent::Write(b) => {
if b.extension() == Some(OsStr::new("rs")) && b.exists() {
println!("----------**********----------\n");
let filepath = b.as_path().canonicalize().unwrap();
let exercise = exercises
.iter()
.skip_while(|e| !filepath.ends_with(&e.path));
clear_screen();
let _ignored = verify(exercise);
}
}
Expand Down

0 comments on commit 3aff590

Please sign in to comment.