feat(config): add regex option
This commit is contained in:
parent
bfe6b13ae7
commit
745c329580
|
@ -491,7 +491,7 @@ fn triggers_for_match(m: &Value) -> Vec<String> {
|
||||||
} else if let Some(trigger) = m.get("trigger").and_then(|v| v.as_str()) {
|
} else if let Some(trigger) = m.get("trigger").and_then(|v| v.as_str()) {
|
||||||
vec![trigger.to_string()]
|
vec![trigger.to_string()]
|
||||||
} else {
|
} else {
|
||||||
panic!("Match does not have any trigger defined: {:?}", m)
|
vec![]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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 anyhow::Result;
|
||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
use parse::YAMLMatchGroup;
|
use parse::YAMLMatchGroup;
|
||||||
|
@ -137,6 +137,10 @@ impl TryFrom<YAMLMatch> for Match {
|
||||||
.unwrap_or(TriggerCause::default().propagate_case),
|
.unwrap_or(TriggerCause::default().propagate_case),
|
||||||
uppercase_style,
|
uppercase_style,
|
||||||
})
|
})
|
||||||
|
} else if let Some(regex) = yaml_match.regex { // TODO: add test case
|
||||||
|
MatchCause::Regex(RegexCause {
|
||||||
|
regex,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
MatchCause::None
|
MatchCause::None
|
||||||
};
|
};
|
||||||
|
|
|
@ -64,6 +64,9 @@ pub struct YAMLMatch {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub triggers: Option<Vec<String>>,
|
pub triggers: Option<Vec<String>>,
|
||||||
|
|
||||||
|
#[serde(default)]
|
||||||
|
pub regex: Option<String>,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub replace: Option<String>,
|
pub replace: Option<String>,
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ impl Default for Match {
|
||||||
pub enum MatchCause {
|
pub enum MatchCause {
|
||||||
None,
|
None,
|
||||||
Trigger(TriggerCause),
|
Trigger(TriggerCause),
|
||||||
// TODO: regex
|
Regex(RegexCause),
|
||||||
// TODO: shortcut
|
// TODO: shortcut
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +88,19 @@ pub enum UpperCasingStyle {
|
||||||
CapitalizeWords,
|
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
|
// Effects
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, EnumAsInner)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, EnumAsInner)]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user