From 334e99b3438de59e50a422bcecd0425b8e41dd85 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Mon, 15 Nov 2021 22:25:52 +0100 Subject: [PATCH] feat(core): implement builtins to show active config and app --- espanso/src/cli/worker/builtin/debug.rs | 47 +++++++++++++++++++++++-- espanso/src/cli/worker/builtin/mod.rs | 2 ++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/espanso/src/cli/worker/builtin/debug.rs b/espanso/src/cli/worker/builtin/debug.rs index 6ab41df..c548090 100644 --- a/espanso/src/cli/worker/builtin/debug.rs +++ b/espanso/src/cli/worker/builtin/debug.rs @@ -17,7 +17,7 @@ * along with espanso. If not, see . */ -use espanso_engine::event::{effect::TextInjectRequest, EventType}; +use espanso_engine::event::{effect::TextInjectRequest, ui::ShowTextEvent, EventType}; use crate::cli::worker::builtin::generate_next_builtin_id; @@ -29,7 +29,7 @@ pub fn create_match_paste_active_config_info() -> BuiltInMatch { BuiltInMatch { id: generate_next_builtin_id(), label: "Paste active config information", - triggers: vec!["#acfg#".to_string()], + triggers: vec!["#pacfg#".to_string()], action: |context| { let dump = context.get_active_config().pretty_dump(); @@ -46,7 +46,7 @@ pub fn create_match_paste_active_app_info() -> BuiltInMatch { BuiltInMatch { id: generate_next_builtin_id(), label: "Paste active application information (detect)", - triggers: vec!["#detect#".to_string()], + triggers: vec!["#pdetect#".to_string()], action: |context| { let info = context.get_active_app_info(); @@ -65,3 +65,44 @@ pub fn create_match_paste_active_app_info() -> BuiltInMatch { ..Default::default() } } + +pub fn create_match_show_active_config_info() -> BuiltInMatch { + BuiltInMatch { + id: generate_next_builtin_id(), + label: "Show active config information", + triggers: vec!["#acfg#".to_string()], + action: |context| { + let dump = context.get_active_config().pretty_dump(); + + EventType::ShowText(ShowTextEvent { + text: dump, + title: "Active configuration".to_string(), + }) + }, + ..Default::default() + } +} + +pub fn create_match_show_active_app_info() -> BuiltInMatch { + BuiltInMatch { + id: generate_next_builtin_id(), + label: "Show active application information (detect)", + triggers: vec!["#detect#".to_string()], + action: |context| { + let info = context.get_active_app_info(); + + let dump = format!( + "title: '{}'\nexec: '{}'\nclass: '{}'", + info.title.unwrap_or_default(), + info.exec.unwrap_or_default(), + info.class.unwrap_or_default() + ); + + EventType::ShowText(ShowTextEvent { + text: dump, + title: "Active application information (detect)".to_string(), + }) + }, + ..Default::default() + } +} diff --git a/espanso/src/cli/worker/builtin/mod.rs b/espanso/src/cli/worker/builtin/mod.rs index 1189f1b..b8e84d2 100644 --- a/espanso/src/cli/worker/builtin/mod.rs +++ b/espanso/src/cli/worker/builtin/mod.rs @@ -55,6 +55,8 @@ pub fn get_builtin_matches(config: &dyn Config) -> Vec { let mut matches = vec![ debug::create_match_paste_active_config_info(), debug::create_match_paste_active_app_info(), + debug::create_match_show_active_config_info(), + debug::create_match_show_active_app_info(), process::create_match_exit(), process::create_match_restart(), ];