diff --git a/src/extension/clipboard.rs b/src/extension/clipboard.rs new file mode 100644 index 0000000..778bbfe --- /dev/null +++ b/src/extension/clipboard.rs @@ -0,0 +1,43 @@ +/* + * This file is part of espanso. + * + * Copyright (C) 2020 Federico Terzi + * + * espanso is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * espanso is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with espanso. If not, see . + */ + +use serde_yaml::{Mapping, Value}; +use crate::clipboard::ClipboardManager; + +pub struct ClipboardExtension { + clipboard_manager: Box, +} + +impl ClipboardExtension { + pub fn new(clipboard_manager: Box) -> ClipboardExtension { + ClipboardExtension{ + clipboard_manager + } + } +} + +impl super::Extension for ClipboardExtension { + fn name(&self) -> String { + String::from("clipboard") + } + + fn calculate(&self, params: &Mapping, _: &Vec) -> Option { + self.clipboard_manager.get_clipboard() + } +} \ No newline at end of file diff --git a/src/extension/mod.rs b/src/extension/mod.rs index 047060d..9db489a 100644 --- a/src/extension/mod.rs +++ b/src/extension/mod.rs @@ -18,24 +18,27 @@ */ use serde_yaml::Mapping; +use crate::clipboard::ClipboardManager; mod date; mod shell; mod script; mod random; -mod dummy; +mod clipboard; +pub mod dummy; pub trait Extension { fn name(&self) -> String; fn calculate(&self, params: &Mapping, args: &Vec) -> Option; } -pub fn get_extensions() -> Vec> { +pub fn get_extensions(clipboard_manager: Box) -> Vec>{ vec![ Box::new(date::DateExtension::new()), Box::new(shell::ShellExtension::new()), Box::new(script::ScriptExtension::new()), Box::new(random::RandomExtension::new()), Box::new(dummy::DummyExtension::new()), + Box::new(clipboard::ClipboardExtension::new(clipboard_manager)), ] } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index bca0ebd..78e8d0d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -344,7 +344,7 @@ fn daemon_background(receive_channel: Receiver, config_set: ConfigSet) { let keyboard_manager = keyboard::get_manager(); - let extensions = extension::get_extensions(); + let extensions = extension::get_extensions(Box::new(clipboard::get_manager())); let renderer = render::default::DefaultRenderer::new(extensions, config_manager.default_config().clone()); diff --git a/src/matcher/mod.rs b/src/matcher/mod.rs index 3e9c294..e322355 100644 --- a/src/matcher/mod.rs +++ b/src/matcher/mod.rs @@ -218,9 +218,12 @@ pub struct MatchVariable { #[serde(rename = "type")] pub var_type: String, + #[serde(default = "default_params")] pub params: Mapping, } +fn default_params() -> Mapping {Mapping::new()} + #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] pub enum TriggerEntry { Char(char), diff --git a/src/render/default.rs b/src/render/default.rs index adfed8e..dca2c70 100644 --- a/src/render/default.rs +++ b/src/render/default.rs @@ -271,7 +271,7 @@ mod tests { use super::*; fn get_renderer(config: Configs) -> DefaultRenderer { - DefaultRenderer::new(crate::extension::get_extensions(), config) + DefaultRenderer::new(vec![Box::new(crate::extension::dummy::DummyExtension::new())], config) } fn get_config_for(s: &str) -> Configs {