Repository: espanso/espanso (language: rust)

Issue:
Show regex triggers in search bar
As described [here](https://github.com/federico-terzi/espanso/issues/762#issuecomment-939360857), it would be nice to have regex triggers displayed on the search bar

![image](https://user-images.githubusercontent.com/20475953/136689563-e5b25650-5e8f-47ff-b1fa-95845a979283.png)



Discussion / hints:
I tried this and it's still missing on v2.2.1

Fix patch:
diff --git a/espanso-config/src/matches/mod.rs b/espanso-config/src/matches/mod.rs
index ea31c398..3b806a7e 100644
--- a/espanso-config/src/matches/mod.rs
+++ b/espanso-config/src/matches/mod.rs
@@ -90,26 +90,22 @@ pub enum MatchCause {
 }
 
 impl MatchCause {
-  // TODO: test
   pub fn description(&self) -> Option<&str> {
-    if let MatchCause::Trigger(trigger_cause) = &self {
-      trigger_cause.triggers.first().map(String::as_str)
-    } else {
-      None
+    match &self {
+      MatchCause::Trigger(trigger_cause) => trigger_cause.triggers.first().map(String::as_str),
+      MatchCause::Regex(trigger_cause) => Some(trigger_cause.regex.as_str()),
+      MatchCause::None => None,
     }
     // TODO: insert rendering for hotkey/shortcut
-    // TODO: insert rendering for regex? I'm worried it might be too long
   }
 
-  // TODO: test
   pub fn long_description(&self) -> String {
-    if let MatchCause::Trigger(trigger_cause) = &self {
-      format!("triggers: {:?}", trigger_cause.triggers)
-    } else {
-      "No description available".to_owned()
+    match &self {
+      MatchCause::Trigger(trigger_cause) => format!("triggers: {:?}", trigger_cause.triggers),
+      MatchCause::Regex(trigger_cause) => format!("regex: {:?}", trigger_cause.regex),
+      MatchCause::None => "No description available".to_owned(),
     }
     // TODO: insert rendering for hotkey/shortcut
-    // TODO: insert rendering for regex? I'm worried it might be too long
   }
 
   pub fn search_terms(&self) -> Vec<&str> {
@@ -242,3 +238,54 @@ pub enum Number {
   Integer(i64),
   Float(OrderedFloat<f64>),
 }
+
+#[cfg(test)]
+mod tests {
+  use super::*;
+
+  fn trigger_cause() -> TriggerCause {
+    TriggerCause {
+      triggers: vec![":greet".to_string()],
+      ..TriggerCause::default()
+    }
+  }
+
+  fn regex_cause() -> RegexCause {
+    RegexCause {
+      regex: ":greet\\d".to_string(),
+    }
+  }
+
+  #[test]
+  fn match_cause_trigger_description() {
+    let trigger = trigger_cause();
+
+    assert_eq!(MatchCause::Trigger(trigger).description(), Some(":greet"));
+  }
+
+  #[test]
+  fn match_cause_regex_description() {
+    let regex = regex_cause();
+    assert_eq!(MatchCause::Regex(regex).description(), Some(":greet\\d"));
+  }
+
+  #[test]
+  fn match_cause_trigger_long_description() {
+    let trigger = trigger_cause();
+
+    assert_eq!(
+      MatchCause::Trigger(trigger).long_description(),
+      r#"triggers: [":greet"]"#
+    );
+  }
+
+  #[test]
+  fn match_cause_regex_long_description() {
+    let regex = regex_cause();
+
+    assert_eq!(
+      MatchCause::Regex(regex).long_description(),
+      r#"regex: ":greet\\d""#
+    );
+  }
+}


Test patch: