diff --git a/src/config.rs b/src/config.rs index d0f6344..4a33e32 100644 --- a/src/config.rs +++ b/src/config.rs @@ -32,9 +32,23 @@ pub struct Configs { #[serde(default = "default_backspace_limit")] pub backspace_limit: i32, + #[serde(default)] + pub backend: BackendType, + pub matches: Vec } +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub enum BackendType { + Inject, + Clipboard +} +impl Default for BackendType { + fn default() -> Self { + BackendType::Inject + } +} + impl Configs { pub fn load(path: &Path) -> Configs { let file_res = File::open(path); diff --git a/src/engine.rs b/src/engine.rs index bdd62ed..55afc3b 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1,6 +1,7 @@ use crate::matcher::{Match, MatchReceiver}; use crate::keyboard::KeyboardSender; use crate::config::Configs; +use crate::config::BackendType; use crate::clipboard::ClipboardManager; use std::sync::Arc; @@ -20,24 +21,30 @@ impl MatchReceiver for Engine where S: KeyboardSender, C: Clipboard fn on_match(&self, m: &Match) { self.sender.delete_string(m.trigger.len() as i32); - // Send the expected string. On linux, newlines are managed automatically - // while on windows and macos, we need to emulate a Enter key press. + match self.configs.backend { + BackendType::Inject => { + // Send the expected string. On linux, newlines are managed automatically + // while on windows and macos, we need to emulate a Enter key press. - if cfg!(target_os = "linux") { - self.clipboard_manager.set_clipboard(m.replace.as_str()); - self.sender.trigger_paste(); - //self.sender.send_string(m.replace.as_str()); - }else{ - // To handle newlines, substitute each "\n" char with an Enter key press. - let splits = m.replace.lines(); + if cfg!(target_os = "linux") { + self.sender.send_string(m.replace.as_str()); + }else{ + // To handle newlines, substitute each "\n" char with an Enter key press. + let splits = m.replace.lines(); - for (i, split) in splits.enumerate() { - if i > 0 { - self.sender.send_enter(); + for (i, split) in splits.enumerate() { + if i > 0 { + self.sender.send_enter(); + } + + self.sender.send_string(split); + } } - - self.sender.send_string(split); - } + }, + BackendType::Clipboard => { + self.clipboard_manager.set_clipboard(m.replace.as_str()); + self.sender.trigger_paste(); + }, } } } \ No newline at end of file