1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! InsertText action handler: variable substitution and terminal write.
use crate::app::window_state::WindowState;
use std::collections::HashMap;
impl WindowState {
/// Execute an InsertText custom action.
///
/// Substitutes variables in the text, then writes the result to the active terminal.
pub(crate) fn execute_insert_text_action(
&mut self,
text: String,
variables: HashMap<String, String>,
) -> bool {
// Substitute variables
let substituted_text =
match crate::snippets::VariableSubstitutor::new().substitute(&text, &variables) {
Ok(content) => content,
Err(e) => {
log::error!("Failed to substitute variables in action: {}", e);
self.show_persistent_toast(format!("Action Error: {}", e));
return false;
}
};
// Write to the active terminal
if let Some(tab) = self.tab_manager.active_tab() {
// A mux tab's `tab.terminal` is a hidden login shell — route
// daemon panes first; only a local target falls through.
if self.route_mux_tab_write(tab, substituted_text.as_bytes()) {
log::info!("Executed insert text action");
return true;
}
// try_lock: intentional -- execute_custom_action runs from keybinding
// handler in sync event loop. On miss: the action text is not written.
// Logged as an error so the user is aware; they can retry the keybinding.
if let Ok(terminal) = tab.terminal.try_read() {
if let Err(e) = terminal.write(substituted_text.as_bytes()) {
log::error!("Failed to write action text to terminal: {}", e);
return false;
}
log::info!("Executed insert text action");
return true;
} else {
log::error!("Failed to lock terminal for action execution");
return false;
}
}
false
}
}