mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-27 00:00:03 +03:00
Cache filters
This commit is contained in:
parent
9c6f56b836
commit
a325df55d1
39
src/main.rs
39
src/main.rs
|
@ -128,31 +128,45 @@ fn main() {
|
||||||
println!("{:<17}\t{:<46}\t{:<7}", "Name", "Path", "Status");
|
println!("{:<17}\t{:<46}\t{:<7}", "Name", "Path", "Status");
|
||||||
}
|
}
|
||||||
let mut exercises_done: u16 = 0;
|
let mut exercises_done: u16 = 0;
|
||||||
let filters = filter.clone().unwrap_or_default().to_lowercase();
|
let lowercase_filter = filter
|
||||||
exercises.iter().for_each(|e| {
|
.as_ref()
|
||||||
let fname = format!("{}", e.path.display());
|
.map(|s| s.to_lowercase())
|
||||||
|
.unwrap_or_default();
|
||||||
|
let filters = lowercase_filter
|
||||||
|
.split(',')
|
||||||
|
.filter_map(|f| {
|
||||||
|
let f = f.trim();
|
||||||
|
if f.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(f)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
for exercise in &exercises {
|
||||||
|
let fname = format!("{}", exercise.path.display());
|
||||||
let filter_cond = filters
|
let filter_cond = filters
|
||||||
.split(',')
|
.iter()
|
||||||
.filter(|f| !f.trim().is_empty())
|
.any(|f| exercise.name.contains(f) || fname.contains(f));
|
||||||
.any(|f| e.name.contains(f) || fname.contains(f));
|
let status = if exercise.looks_done() {
|
||||||
let status = if e.looks_done() {
|
|
||||||
exercises_done += 1;
|
exercises_done += 1;
|
||||||
"Done"
|
"Done"
|
||||||
} else {
|
} else {
|
||||||
"Pending"
|
"Pending"
|
||||||
};
|
};
|
||||||
let solve_cond = {
|
let solve_cond = {
|
||||||
(e.looks_done() && solved)
|
(exercise.looks_done() && solved)
|
||||||
|| (!e.looks_done() && unsolved)
|
|| (!exercise.looks_done() && unsolved)
|
||||||
|| (!solved && !unsolved)
|
|| (!solved && !unsolved)
|
||||||
};
|
};
|
||||||
if solve_cond && (filter_cond || filter.is_none()) {
|
if solve_cond && (filter_cond || filter.is_none()) {
|
||||||
let line = if paths {
|
let line = if paths {
|
||||||
format!("{fname}\n")
|
format!("{fname}\n")
|
||||||
} else if names {
|
} else if names {
|
||||||
format!("{}\n", e.name)
|
format!("{}\n", exercise.name)
|
||||||
} else {
|
} else {
|
||||||
format!("{:<17}\t{fname:<46}\t{status:<7}\n", e.name)
|
format!("{:<17}\t{fname:<46}\t{status:<7}\n", exercise.name)
|
||||||
};
|
};
|
||||||
// Somehow using println! leads to the binary panicking
|
// Somehow using println! leads to the binary panicking
|
||||||
// when its output is piped.
|
// when its output is piped.
|
||||||
|
@ -168,7 +182,8 @@ fn main() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
let percentage_progress = exercises_done as f32 / exercises.len() as f32 * 100.0;
|
let percentage_progress = exercises_done as f32 / exercises.len() as f32 * 100.0;
|
||||||
println!(
|
println!(
|
||||||
"Progress: You completed {} / {} exercises ({:.1} %).",
|
"Progress: You completed {} / {} exercises ({:.1} %).",
|
||||||
|
|
Loading…
Reference in a new issue