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