feat(config): add methods to generate match descriptions

This commit is contained in:
Federico Terzi 2021-05-08 10:55:44 +02:00
parent 6d5507cc5f
commit e361bdb9c2

View File

@ -48,6 +48,32 @@ impl Default for Match {
}
}
impl Match {
// TODO: test
pub fn description<'a>(&'a self) -> &'a str {
if let Some(label) = &self.label {
&label
} else if let MatchEffect::Text(text_effect) = &self.effect {
&text_effect.replace
} else if let MatchEffect::Image(_) = &self.effect {
"Image content"
} else {
"No description available for this match"
}
}
// TODO: test
pub fn cause_description<'a>(&'a self) -> Option<&'a str> {
if let MatchCause::Trigger(trigger_cause) = &self.cause {
trigger_cause.triggers.first().map(|s| s.as_str())
} else {
None
}
// TODO: insert rendering for hotkey/shortcut
// TODO: insert rendering for regex? I'm worried it might be too long
}
}
// Causes
#[derive(Debug, Clone, Eq, Hash, PartialEq, EnumAsInner)]