mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-26 00:00:03 +03:00
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.
This commit is contained in:
commit
3232a4d60d
12
src/main.rs
12
src/main.rs
|
@ -80,9 +80,6 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.subcommand_matches("watch").is_some() {
|
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();
|
watch(&exercises).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,11 +90,18 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn watch(exercises: &[Exercise]) -> notify::Result<()> {
|
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 (tx, rx) = channel();
|
||||||
|
|
||||||
let mut watcher: RecommendedWatcher = Watcher::new(tx, Duration::from_secs(2))?;
|
let mut watcher: RecommendedWatcher = Watcher::new(tx, Duration::from_secs(2))?;
|
||||||
watcher.watch(Path::new("./exercises"), RecursiveMode::Recursive)?;
|
watcher.watch(Path::new("./exercises"), RecursiveMode::Recursive)?;
|
||||||
|
|
||||||
|
clear_screen();
|
||||||
let _ignored = verify(exercises.iter());
|
let _ignored = verify(exercises.iter());
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -105,11 +109,11 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> {
|
||||||
Ok(event) => match event {
|
Ok(event) => match event {
|
||||||
DebouncedEvent::Create(b) | DebouncedEvent::Chmod(b) | DebouncedEvent::Write(b) => {
|
DebouncedEvent::Create(b) | DebouncedEvent::Chmod(b) | DebouncedEvent::Write(b) => {
|
||||||
if b.extension() == Some(OsStr::new("rs")) && b.exists() {
|
if b.extension() == Some(OsStr::new("rs")) && b.exists() {
|
||||||
println!("----------**********----------\n");
|
|
||||||
let filepath = b.as_path().canonicalize().unwrap();
|
let filepath = b.as_path().canonicalize().unwrap();
|
||||||
let exercise = exercises
|
let exercise = exercises
|
||||||
.iter()
|
.iter()
|
||||||
.skip_while(|e| !filepath.ends_with(&e.path));
|
.skip_while(|e| !filepath.ends_with(&e.path));
|
||||||
|
clear_screen();
|
||||||
let _ignored = verify(exercise);
|
let _ignored = verify(exercise);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue