Skip to content

Commit 3232a4d

Browse files
committed
Auto merge of #228 - WofWca:clear-screen, r=fmoko
improvement(watch): clear screen before each `verify()` Closes #146 It seems to me that #227 wasn't really fixing the issue.
2 parents c8babba + 3aff590 commit 3232a4d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/main.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ fn main() {
8080
}
8181

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

@@ -93,23 +90,30 @@ fn main() {
9390
}
9491

9592
fn watch(exercises: &[Exercise]) -> notify::Result<()> {
93+
/* Clears the terminal with an ANSI escape code.
94+
Works in UNIX and newer Windows terminals. */
95+
fn clear_screen() {
96+
println!("\x1Bc");
97+
}
98+
9699
let (tx, rx) = channel();
97100

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

104+
clear_screen();
101105
let _ignored = verify(exercises.iter());
102106

103107
loop {
104108
match rx.recv() {
105109
Ok(event) => match event {
106110
DebouncedEvent::Create(b) | DebouncedEvent::Chmod(b) | DebouncedEvent::Write(b) => {
107111
if b.extension() == Some(OsStr::new("rs")) && b.exists() {
108-
println!("----------**********----------\n");
109112
let filepath = b.as_path().canonicalize().unwrap();
110113
let exercise = exercises
111114
.iter()
112115
.skip_while(|e| !filepath.ends_with(&e.path));
116+
clear_screen();
113117
let _ignored = verify(exercise);
114118
}
115119
}

0 commit comments

Comments
 (0)