diff --git a/client/src/modes/common/command_mode.rs b/client/src/modes/common/command_mode.rs index c7195fa..1de7d81 100644 --- a/client/src/modes/common/command_mode.rs +++ b/client/src/modes/common/command_mode.rs @@ -4,6 +4,8 @@ use crossterm::event::{KeyEvent, KeyCode, KeyModifiers}; use crate::tui::terminal::grpc_client::GrpcClient; use crate::config::binds::config::Config; use crate::ui::handlers::form::FormState; +use crate::tui::controls::commands::CommandHandler; +use crate::tui::terminal::core::TerminalCore; use crate::modes::{ canvas::{common}, }; @@ -15,7 +17,8 @@ pub async fn handle_command_event( command_input: &mut String, command_message: &mut String, grpc_client: &mut GrpcClient, - is_saved: &mut bool, + command_handler: &mut CommandHandler, + terminal: &mut TerminalCore, current_position: &mut u64, total_count: u64, ) -> Result<(bool, String, bool), Box> { @@ -37,7 +40,8 @@ pub async fn handle_command_event( command_input, command_message, grpc_client, - is_saved, + command_handler, + terminal, current_position, total_count, ).await; @@ -68,7 +72,8 @@ async fn process_command( command_input: &mut String, command_message: &mut String, grpc_client: &mut GrpcClient, - is_saved: &mut bool, + command_handler: &mut CommandHandler, + terminal: &mut TerminalCore, current_position: &mut u64, total_count: u64, ) -> Result<(bool, String, bool), Box> { @@ -84,32 +89,24 @@ async fn process_command( .unwrap_or("unknown"); match action { + "force_quit" | "save_and_quit" | "quit" => { + let (should_exit, message) = command_handler + .handle_command(action, terminal) + .await?; + command_input.clear(); + Ok((should_exit, message, true)) + }, "save" => { let message = common::save( form_state, grpc_client, - is_saved, + &mut command_handler.is_saved, current_position, total_count, ).await?; command_input.clear(); return Ok((false, message, true)); }, - "force_quit" => { - let (should_exit, message) = common::force_quit(); - command_input.clear(); - return Ok((should_exit, message, true)); - }, - "save_and_quit" => { - let (should_exit, message) = common::save_and_quit( - form_state, - grpc_client, - current_position, - total_count, - ).await?; - command_input.clear(); - return Ok((should_exit, message, true)); - }, "revert" => { let message = common::revert( form_state, diff --git a/client/src/modes/handlers/event.rs b/client/src/modes/handlers/event.rs index 4a4a06e..63558b0 100644 --- a/client/src/modes/handlers/event.rs +++ b/client/src/modes/handlers/event.rs @@ -224,7 +224,8 @@ impl EventHandler { &mut self.command_input, &mut self.command_message, grpc_client, - &mut app_state.ui.is_saved, + command_handler, + terminal, current_position, total_count, ).await?; diff --git a/client/src/tui/controls/commands.rs b/client/src/tui/controls/commands.rs index 672e046..e12b145 100644 --- a/client/src/tui/controls/commands.rs +++ b/client/src/tui/controls/commands.rs @@ -2,7 +2,7 @@ use crate::tui::terminal::core::TerminalCore; pub struct CommandHandler { - is_saved: bool, + pub is_saved: bool, } impl CommandHandler {