feat(core): implement builtins to show active config and app

This commit is contained in:
Federico Terzi 2021-11-15 22:25:52 +01:00
parent 9081ca76e7
commit 334e99b343
2 changed files with 46 additions and 3 deletions

View File

@ -17,7 +17,7 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
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()
}
}

View File

@ -55,6 +55,8 @@ pub fn get_builtin_matches(config: &dyn Config) -> Vec<BuiltInMatch> {
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(),
];