diff --git a/espanso-config/src/legacy/config.rs b/espanso-config/src/legacy/config.rs index ee957fc..312d148 100644 --- a/espanso-config/src/legacy/config.rs +++ b/espanso-config/src/legacy/config.rs @@ -491,7 +491,7 @@ fn triggers_for_match(m: &Value) -> Vec { } else if let Some(trigger) = m.get("trigger").and_then(|v| v.as_str()) { vec![trigger.to_string()] } else { - panic!("Match does not have any trigger defined: {:?}", m) + vec![] } } diff --git a/espanso-config/src/matches/group/loader/yaml/mod.rs b/espanso-config/src/matches/group/loader/yaml/mod.rs index 37b63ed..0280aa5 100644 --- a/espanso-config/src/matches/group/loader/yaml/mod.rs +++ b/espanso-config/src/matches/group/loader/yaml/mod.rs @@ -17,7 +17,7 @@ * along with espanso. If not, see . */ -use crate::{counter::next_id, matches::{ImageEffect, Match, Params, TextFormat, UpperCasingStyle, Value, Variable, group::{path::resolve_imports, MatchGroup}}}; +use crate::{counter::next_id, matches::{ImageEffect, Match, Params, RegexCause, TextFormat, UpperCasingStyle, Value, Variable, group::{path::resolve_imports, MatchGroup}}}; use anyhow::Result; use log::{error, warn}; use parse::YAMLMatchGroup; @@ -137,6 +137,10 @@ impl TryFrom for Match { .unwrap_or(TriggerCause::default().propagate_case), uppercase_style, }) + } else if let Some(regex) = yaml_match.regex { // TODO: add test case + MatchCause::Regex(RegexCause { + regex, + }) } else { MatchCause::None }; diff --git a/espanso-config/src/matches/group/loader/yaml/parse.rs b/espanso-config/src/matches/group/loader/yaml/parse.rs index 44545d0..c9d7a8f 100644 --- a/espanso-config/src/matches/group/loader/yaml/parse.rs +++ b/espanso-config/src/matches/group/loader/yaml/parse.rs @@ -64,6 +64,9 @@ pub struct YAMLMatch { #[serde(default)] pub triggers: Option>, + #[serde(default)] + pub regex: Option, + #[serde(default)] pub replace: Option, diff --git a/espanso-config/src/matches/mod.rs b/espanso-config/src/matches/mod.rs index 402a686..fc24406 100644 --- a/espanso-config/src/matches/mod.rs +++ b/espanso-config/src/matches/mod.rs @@ -54,7 +54,7 @@ impl Default for Match { pub enum MatchCause { None, Trigger(TriggerCause), - // TODO: regex + Regex(RegexCause), // TODO: shortcut } @@ -88,6 +88,19 @@ pub enum UpperCasingStyle { CapitalizeWords, } +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct RegexCause { + pub regex: String, +} + +impl Default for RegexCause { + fn default() -> Self { + Self { + regex: String::new(), + } + } +} + // Effects #[derive(Debug, Clone, PartialEq, Eq, Hash, EnumAsInner)]