Display stdin more intuitively top-down instead of bottom-up (#50)

* fix: Don't include empty lines and whitespace when precessing stdin

* fix: Display stdin more intuitively top-down instead of bottom-up
This commit is contained in:
Fred Morcos 2024-11-20 13:40:16 +01:00 committed by GitHub
parent 30639c66b0
commit 44de19a01e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,11 +19,13 @@ impl Channel {
pub fn new() -> Self { pub fn new() -> Self {
let mut lines = Vec::new(); let mut lines = Vec::new();
for line in std::io::stdin().lock().lines().map_while(Result::ok) { for line in std::io::stdin().lock().lines().map_while(Result::ok) {
lines.push(preprocess_line(&line)); if !line.trim().is_empty() {
lines.push(preprocess_line(&line));
}
} }
let matcher = Matcher::new(Config::default().n_threads(NUM_THREADS)); let matcher = Matcher::new(Config::default().n_threads(NUM_THREADS));
let injector = matcher.injector(); let injector = matcher.injector();
for line in &lines { for line in lines.iter().rev() {
let () = injector.push(line.clone(), |e, cols| { let () = injector.push(line.clone(), |e, cols| {
cols[0] = e.clone().into(); cols[0] = e.clone().into();
}); });