espanso/src/matcher/mod.rs

28 lines
635 B
Rust
Raw Normal View History

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
pub(crate) mod scrolling;
2019-09-01 20:00:31 +00:00
#[derive(Debug, Serialize, Deserialize)]
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
}
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
}
}
}
}