terminal.rs huge changes

This commit is contained in:
filipriec
2025-03-21 12:05:18 +01:00
parent d3f6296d67
commit 5edc286854
12 changed files with 247 additions and 207 deletions

View File

@@ -2,7 +2,11 @@
use crossterm::event::Event;
use crossterm::cursor::SetCursorStyle;
use crate::tui::terminal::AppTerminal;
use crate::tui::terminal::{
core::TerminalCore,
grpc_client::GrpcClient,
commands::CommandHandler,
};
use crate::config::config::Config;
use crate::ui::handlers::form::FormState;
use crate::modes::handlers::{edit, command_mode, read_only};
@@ -36,7 +40,9 @@ impl EventHandler {
&mut self,
event: Event,
config: &Config,
app_terminal: &mut AppTerminal,
terminal: &mut TerminalCore,
grpc_client: &mut GrpcClient,
command_handler: &mut CommandHandler,
form_state: &mut FormState,
is_saved: &mut bool,
total_count: u64,
@@ -52,7 +58,7 @@ impl EventHandler {
"save" => {
let message = common::save(
form_state,
app_terminal,
grpc_client,
is_saved,
current_position,
total_count,
@@ -60,22 +66,17 @@ impl EventHandler {
return Ok((false, message));
},
"force_quit" => {
let (should_exit, message) = common::force_quit();
let (should_exit, message) = command_handler.handle_command("force_quit", terminal).await?;
return Ok((should_exit, message));
},
"save_and_quit" => {
let (should_exit, message) = common::save_and_quit(
form_state,
app_terminal,
current_position,
total_count,
).await?;
let (should_exit, message) = command_handler.handle_command("save_and_quit", terminal).await?;
return Ok((should_exit, message));
},
"revert" => {
let message = common::revert(
form_state,
app_terminal,
grpc_client,
current_position,
total_count,
).await?;
@@ -93,7 +94,7 @@ impl EventHandler {
form_state,
&mut self.command_input,
&mut self.command_message,
app_terminal,
grpc_client,
is_saved,
current_position,
total_count,
@@ -124,7 +125,7 @@ impl EventHandler {
self.is_edit_mode = false;
self.edit_mode_cooldown = true;
self.command_message = "Read-only mode".to_string();
app_terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?;
terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?;
let current_input = form_state.get_current_input();
if !current_input.is_empty() && form_state.current_cursor_pos >= current_input.len() {
@@ -141,7 +142,8 @@ impl EventHandler {
form_state,
&mut self.ideal_cursor_column,
&mut self.command_message,
app_terminal,
terminal,
grpc_client,
is_saved,
current_position,
total_count,
@@ -152,7 +154,6 @@ impl EventHandler {
} else {
// In READ-ONLY mode, we DO want to check for entering command mode
// Check for entering command mode (only in read-only mode)
// Use get_read_only_action_for_key instead of is_enter_command_mode
if let Some(action) = config.get_read_only_action_for_key(key.code, key.modifiers) {
if action == "enter_command_mode" {
self.command_mode = true;
@@ -167,10 +168,10 @@ impl EventHandler {
self.is_edit_mode = true;
self.edit_mode_cooldown = true;
self.command_message = "Edit mode".to_string();
app_terminal.set_cursor_style(SetCursorStyle::BlinkingBar)?;
terminal.set_cursor_style(SetCursorStyle::BlinkingBar)?;
return Ok((false, self.command_message.clone()));
}
if config.is_enter_edit_mode_after(key.code, key.modifiers) {
let current_input = form_state.get_current_input();
if !current_input.is_empty() && form_state.current_cursor_pos < current_input.len() {
@@ -180,7 +181,7 @@ impl EventHandler {
self.is_edit_mode = true;
self.edit_mode_cooldown = true;
self.command_message = "Edit mode (after cursor)".to_string();
app_terminal.set_cursor_style(SetCursorStyle::BlinkingBar)?;
terminal.set_cursor_style(SetCursorStyle::BlinkingBar)?;
return Ok((false, self.command_message.clone()));
}
@@ -192,7 +193,8 @@ impl EventHandler {
&mut self.key_sequence_tracker,
current_position,
total_count,
app_terminal,
terminal,
grpc_client,
&mut self.command_message,
&mut self.edit_mode_cooldown,
&mut self.ideal_cursor_column,