diff --git a/src/client/config.rs b/src/client/config.rs index e737efe..0856825 100644 --- a/src/client/config.rs +++ b/src/client/config.rs @@ -37,11 +37,13 @@ impl Config { "shift" => expected_modifiers |= KeyModifiers::SHIFT, "alt" => expected_modifiers |= KeyModifiers::ALT, _ => { + // Handle single character keys and special cases expected_key = match part.to_lowercase().as_str() { - "s" => Some(KeyCode::Char('s')), - "q" => Some(KeyCode::Char('q')), - "w" => Some(KeyCode::Char('w')), ":" => Some(KeyCode::Char(':')), + part if part.len() == 1 => { + let c = part.chars().next().unwrap(); + Some(KeyCode::Char(c)) + } _ => None, }; } @@ -50,4 +52,15 @@ impl Config { modifiers == expected_modifiers && Some(key) == expected_key } + + pub fn get_action_for_command(&self, command: &str) -> Option<&str> { + for (action, bindings) in &self.keybindings { + for binding in bindings { + if binding.starts_with(':') && binding.trim_start_matches(':') == command { + return Some(action); + } + } + } + None + } } diff --git a/src/client/terminal.rs b/src/client/terminal.rs index d1a8bf5..e4c2b6f 100644 --- a/src/client/terminal.rs +++ b/src/client/terminal.rs @@ -50,7 +50,7 @@ impl AppTerminal { pub async fn handle_command( &mut self, - action: &str, + action: &str, // This should be the resolved action (e.g., "save") is_saved: &mut bool, form_data: &AdresarRequest, ) -> Result<(bool, String), Box> { diff --git a/src/client/ui.rs b/src/client/ui.rs index 0f8c362..fe21142 100644 --- a/src/client/ui.rs +++ b/src/client/ui.rs @@ -120,16 +120,29 @@ pub async fn run_ui() -> Result<(), Box> { fax: fax.clone(), }; - // Pass form data to handle_command (remove &config) + // Validate command format + let command = command_input.trim(); + if command.is_empty() { + command_message = "Empty command".to_string(); + continue; + } + + // Look up the action for the command string (e.g., "w") + let action = config.get_action_for_command(command) + .unwrap_or("unknown"); + + // Pass the resolved action to handle_command let (should_exit, message) = app_terminal - .handle_command(&command_input, &mut is_saved, &form_data) + .handle_command(action, &mut is_saved, &form_data) .await?; + command_message = message; + command_mode = false; + command_input.clear(); + if should_exit { return Ok(()); } - command_mode = false; - command_input.clear(); } KeyCode::Char(c) => command_input.push(c), KeyCode::Backspace => {