From 9b52a06a8b471c8f9a37b4edc5a7c45a4c971625 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Tue, 24 Aug 2021 19:54:26 +0200 Subject: [PATCH] feat(core): wire up configurable search bar hint --- .../worker/engine/process/middleware/match_select.rs | 10 ++++++++-- espanso/src/gui/mod.rs | 2 +- espanso/src/gui/modulo/search.rs | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/espanso/src/cli/worker/engine/process/middleware/match_select.rs b/espanso/src/cli/worker/engine/process/middleware/match_select.rs index f364b7e..96c2507 100644 --- a/espanso/src/cli/worker/engine/process/middleware/match_select.rs +++ b/espanso/src/cli/worker/engine/process/middleware/match_select.rs @@ -50,7 +50,7 @@ impl<'a> MatchSelectorAdapter<'a> { } impl<'a> MatchSelector for MatchSelectorAdapter<'a> { - fn select(&self, matches_ids: &[i32]) -> Option { + fn select(&self, matches_ids: &[i32], is_search: bool) -> Option { let matches = self.match_provider.get_matches(&matches_ids); let search_items: Vec = matches .into_iter() @@ -65,8 +65,14 @@ impl<'a> MatchSelector for MatchSelectorAdapter<'a> { } }) .collect(); + + let hint = if is_search { + Some("Search matches by content or trigger (or type > to see commands)") + } else { + None + }; - match self.search_ui.show(&search_items) { + match self.search_ui.show(&search_items, hint) { Ok(Some(selected_id)) => match selected_id.parse::() { Ok(id) => Some(id), Err(err) => { diff --git a/espanso/src/gui/mod.rs b/espanso/src/gui/mod.rs index e6a434e..3920c35 100644 --- a/espanso/src/gui/mod.rs +++ b/espanso/src/gui/mod.rs @@ -24,7 +24,7 @@ use anyhow::Result; pub mod modulo; pub trait SearchUI { - fn show(&self, items: &[SearchItem]) -> Result>; + fn show(&self, items: &[SearchItem], hint: Option<&str>) -> Result>; } #[derive(Debug)] diff --git a/espanso/src/gui/modulo/search.rs b/espanso/src/gui/modulo/search.rs index 45c789f..053089d 100644 --- a/espanso/src/gui/modulo/search.rs +++ b/espanso/src/gui/modulo/search.rs @@ -38,9 +38,10 @@ impl<'a> ModuloSearchUI<'a> { } impl<'a> SearchUI for ModuloSearchUI<'a> { - fn show(&self, items: &[SearchItem]) -> anyhow::Result> { + fn show(&self, items: &[SearchItem], hint: Option<&str>) -> anyhow::Result> { let modulo_config = ModuloSearchConfig { title: "espanso", + hint, items: convert_items(&items), }; @@ -67,6 +68,7 @@ impl<'a> SearchUI for ModuloSearchUI<'a> { #[derive(Debug, Serialize)] struct ModuloSearchConfig<'a> { title: &'a str, + hint: Option<&'a str>, items: Vec>, }