espanso/src/matcher/mod.rs

26 lines
556 B
Rust
Raw Normal View History

2019-08-30 19:24:03 +00:00
use std::sync::mpsc::Receiver;
pub(crate) mod scrolling;
2019-08-30 19:24:03 +00:00
pub struct Match {
pub trigger: String,
pub result: String
}
pub trait MatchReceiver {
2019-08-31 15:00:23 +00:00
fn on_match(&self, m: &Match);
2019-08-30 19:24:03 +00:00
}
pub trait Matcher {
2019-08-31 15:00:23 +00:00
fn handle_char(&mut self, c: char);
fn watch(&mut self, receiver: &Receiver<char>) {
2019-08-30 19:24:03 +00:00
loop {
match receiver.recv() {
2019-08-30 19:24:03 +00:00
Ok(c) => {
self.handle_char(c);
2019-08-30 19:24:03 +00:00
},
Err(_) => panic!("Keyboard interceptor broke receiver stream."),
2019-08-30 19:24:03 +00:00
}
}
}
}