2019-08-30 17:45:27 +00:00
|
|
|
use std::sync::mpsc;
|
2019-08-30 19:24:03 +00:00
|
|
|
use crate::keyboard::KeyboardInterceptor;
|
|
|
|
use crate::matcher::Matcher;
|
2019-08-31 14:07:45 +00:00
|
|
|
use crate::matcher::scrolling::ScrollingMatcher;
|
|
|
|
use crate::engine::Engine;
|
2019-09-01 20:00:31 +00:00
|
|
|
use crate::config::Configs;
|
2019-09-06 20:30:20 +00:00
|
|
|
use crate::ui::UIManager;
|
2019-09-05 15:20:52 +00:00
|
|
|
use std::thread;
|
2019-09-05 21:06:43 +00:00
|
|
|
use clap::{App, Arg};
|
|
|
|
use std::path::Path;
|
2019-08-30 16:32:10 +00:00
|
|
|
|
2019-08-30 17:45:27 +00:00
|
|
|
mod keyboard;
|
2019-08-30 19:24:03 +00:00
|
|
|
mod matcher;
|
2019-08-31 14:07:45 +00:00
|
|
|
mod engine;
|
2019-09-01 20:00:31 +00:00
|
|
|
mod config;
|
2019-09-06 14:06:41 +00:00
|
|
|
mod ui;
|
2019-08-30 12:33:40 +00:00
|
|
|
|
2019-09-05 21:06:43 +00:00
|
|
|
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
|
|
|
|
2019-08-30 12:33:40 +00:00
|
|
|
fn main() {
|
2019-09-05 21:06:43 +00:00
|
|
|
let matches = App::new("espanso")
|
|
|
|
.version(VERSION)
|
|
|
|
.author("Federico Terzi")
|
|
|
|
.about("Cross-platform Text Expander written in Rust")
|
|
|
|
.arg(Arg::with_name("config")
|
|
|
|
.short("c")
|
|
|
|
.long("config")
|
|
|
|
.value_name("FILE")
|
|
|
|
.help("Sets a custom config file. If not specified, reads the default $HOME/.espanso file, creating it if not present.")
|
|
|
|
.takes_value(true))
|
|
|
|
.arg(Arg::with_name("dump")
|
|
|
|
.long("dump")
|
|
|
|
.help("Prints all current configuration options."))
|
|
|
|
.arg(Arg::with_name("v")
|
|
|
|
.short("v")
|
|
|
|
.multiple(true)
|
|
|
|
.help("Sets the level of verbosity"))
|
|
|
|
.get_matches();
|
|
|
|
|
|
|
|
let configs = match matches.value_of("config") {
|
|
|
|
None => {Configs::load_default()},
|
|
|
|
Some(path) => {Configs::load(Path::new(path))},
|
|
|
|
};
|
|
|
|
|
|
|
|
if matches.is_present("dump") {
|
|
|
|
println!("{:#?}", configs);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
espanso_main(configs);
|
|
|
|
}
|
2019-08-30 12:33:40 +00:00
|
|
|
|
2019-09-05 21:06:43 +00:00
|
|
|
fn espanso_main(configs: Configs) {
|
2019-09-06 20:30:20 +00:00
|
|
|
let ui_manager = ui::get_uimanager();
|
|
|
|
ui_manager.notify("Hello guys");
|
2019-09-06 14:06:41 +00:00
|
|
|
|
2019-08-31 14:07:45 +00:00
|
|
|
let (txc, rxc) = mpsc::channel();
|
2019-08-30 16:32:10 +00:00
|
|
|
|
2019-08-31 14:07:45 +00:00
|
|
|
let sender = keyboard::get_sender();
|
|
|
|
|
2019-09-05 18:54:19 +00:00
|
|
|
let engine = Engine::new(sender, configs.clone());
|
2019-08-31 14:07:45 +00:00
|
|
|
|
2019-09-05 15:20:52 +00:00
|
|
|
thread::spawn(move || {
|
2019-09-05 18:54:19 +00:00
|
|
|
let matcher = ScrollingMatcher::new(configs.clone(), engine);
|
2019-09-05 15:20:52 +00:00
|
|
|
matcher.watch(rxc);
|
|
|
|
});
|
2019-08-31 15:00:23 +00:00
|
|
|
|
2019-09-05 15:20:52 +00:00
|
|
|
let interceptor = keyboard::get_interceptor(txc);
|
|
|
|
interceptor.initialize();
|
|
|
|
interceptor.start();
|
2019-08-30 12:33:40 +00:00
|
|
|
}
|