// src/tui/controls/commands.rs use crate::tui::terminal::core::TerminalCore; pub struct CommandHandler { is_saved: bool, } impl CommandHandler { pub fn new() -> Self { Self { is_saved: false } } pub async fn handle_command( &mut self, action: &str, terminal: &mut TerminalCore, ) -> Result<(bool, String), Box> { match action { "quit" => self.handle_quit(terminal).await, "force_quit" => self.handle_force_quit(terminal).await, "save_and_quit" => self.handle_save_quit(terminal).await, _ => Ok((false, format!("Unknown command: {}", action))), } } async fn handle_quit( &self, terminal: &mut TerminalCore, ) -> Result<(bool, String), Box> { if self.is_saved { terminal.cleanup()?; Ok((true, "Exiting.".into())) } else { Ok((false, "No changes saved. Use :q! to force quit.".into())) } } async fn handle_force_quit( &self, terminal: &mut TerminalCore, ) -> Result<(bool, String), Box> { terminal.cleanup()?; Ok((true, "Force exiting without saving.".into())) } async fn handle_save_quit( &mut self, terminal: &mut TerminalCore, ) -> Result<(bool, String), Box> { self.is_saved = true; terminal.cleanup()?; Ok((true, "State saved. Exiting.".into())) } }