working finally
This commit is contained in:
@@ -4,6 +4,8 @@ use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
|
|||||||
use crate::tui::terminal::grpc_client::GrpcClient;
|
use crate::tui::terminal::grpc_client::GrpcClient;
|
||||||
use crate::config::binds::config::Config;
|
use crate::config::binds::config::Config;
|
||||||
use crate::ui::handlers::form::FormState;
|
use crate::ui::handlers::form::FormState;
|
||||||
|
use crate::tui::controls::commands::CommandHandler;
|
||||||
|
use crate::tui::terminal::core::TerminalCore;
|
||||||
use crate::modes::{
|
use crate::modes::{
|
||||||
canvas::{common},
|
canvas::{common},
|
||||||
};
|
};
|
||||||
@@ -15,7 +17,8 @@ pub async fn handle_command_event(
|
|||||||
command_input: &mut String,
|
command_input: &mut String,
|
||||||
command_message: &mut String,
|
command_message: &mut String,
|
||||||
grpc_client: &mut GrpcClient,
|
grpc_client: &mut GrpcClient,
|
||||||
is_saved: &mut bool,
|
command_handler: &mut CommandHandler,
|
||||||
|
terminal: &mut TerminalCore,
|
||||||
current_position: &mut u64,
|
current_position: &mut u64,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
) -> Result<(bool, String, bool), Box<dyn std::error::Error>> {
|
) -> Result<(bool, String, bool), Box<dyn std::error::Error>> {
|
||||||
@@ -37,7 +40,8 @@ pub async fn handle_command_event(
|
|||||||
command_input,
|
command_input,
|
||||||
command_message,
|
command_message,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
is_saved,
|
command_handler,
|
||||||
|
terminal,
|
||||||
current_position,
|
current_position,
|
||||||
total_count,
|
total_count,
|
||||||
).await;
|
).await;
|
||||||
@@ -68,7 +72,8 @@ async fn process_command(
|
|||||||
command_input: &mut String,
|
command_input: &mut String,
|
||||||
command_message: &mut String,
|
command_message: &mut String,
|
||||||
grpc_client: &mut GrpcClient,
|
grpc_client: &mut GrpcClient,
|
||||||
is_saved: &mut bool,
|
command_handler: &mut CommandHandler,
|
||||||
|
terminal: &mut TerminalCore,
|
||||||
current_position: &mut u64,
|
current_position: &mut u64,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
) -> Result<(bool, String, bool), Box<dyn std::error::Error>> {
|
) -> Result<(bool, String, bool), Box<dyn std::error::Error>> {
|
||||||
@@ -84,32 +89,24 @@ async fn process_command(
|
|||||||
.unwrap_or("unknown");
|
.unwrap_or("unknown");
|
||||||
|
|
||||||
match action {
|
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" => {
|
"save" => {
|
||||||
let message = common::save(
|
let message = common::save(
|
||||||
form_state,
|
form_state,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
is_saved,
|
&mut command_handler.is_saved,
|
||||||
current_position,
|
current_position,
|
||||||
total_count,
|
total_count,
|
||||||
).await?;
|
).await?;
|
||||||
command_input.clear();
|
command_input.clear();
|
||||||
return Ok((false, message, true));
|
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" => {
|
"revert" => {
|
||||||
let message = common::revert(
|
let message = common::revert(
|
||||||
form_state,
|
form_state,
|
||||||
|
|||||||
@@ -224,7 +224,8 @@ impl EventHandler {
|
|||||||
&mut self.command_input,
|
&mut self.command_input,
|
||||||
&mut self.command_message,
|
&mut self.command_message,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
&mut app_state.ui.is_saved,
|
command_handler,
|
||||||
|
terminal,
|
||||||
current_position,
|
current_position,
|
||||||
total_count,
|
total_count,
|
||||||
).await?;
|
).await?;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
use crate::tui::terminal::core::TerminalCore;
|
use crate::tui::terminal::core::TerminalCore;
|
||||||
|
|
||||||
pub struct CommandHandler {
|
pub struct CommandHandler {
|
||||||
is_saved: bool,
|
pub is_saved: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CommandHandler {
|
impl CommandHandler {
|
||||||
|
|||||||
Reference in New Issue
Block a user