2019-08-30 19:24:03 +00:00
|
|
|
use std::sync::mpsc::Receiver;
|
2019-09-01 20:00:31 +00:00
|
|
|
use serde::{Serialize, Deserialize};
|
2019-08-30 19:24:03 +00:00
|
|
|
|
2019-08-31 14:07:45 +00:00
|
|
|
pub(crate) mod scrolling;
|
|
|
|
|
2019-09-05 15:20:52 +00:00
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
2019-08-30 19:24:03 +00:00
|
|
|
pub struct Match {
|
|
|
|
pub trigger: String,
|
2019-09-01 20:00:31 +00:00
|
|
|
pub replace: String
|
2019-08-30 19:24:03 +00:00
|
|
|
}
|
|
|
|
|
2019-08-31 14:07:45 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-09-05 15:20:52 +00:00
|
|
|
pub trait Matcher<'a>: Send {
|
|
|
|
fn handle_char(&'a self, c: char);
|
|
|
|
fn watch(&'a 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|