terminal.rs huge changes
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
// src/modes/handlers/command_mode.rs
|
||||
|
||||
use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
|
||||
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 super::common;
|
||||
@@ -12,7 +16,7 @@ pub async fn handle_command_event(
|
||||
form_state: &mut FormState,
|
||||
command_input: &mut String,
|
||||
command_message: &mut String,
|
||||
app_terminal: &mut AppTerminal,
|
||||
grpc_client: &mut GrpcClient,
|
||||
is_saved: &mut bool,
|
||||
current_position: &mut u64,
|
||||
total_count: u64,
|
||||
@@ -65,7 +69,7 @@ async fn process_command(
|
||||
form_state: &mut FormState,
|
||||
command_input: &mut String,
|
||||
command_message: &mut String,
|
||||
app_terminal: &mut AppTerminal,
|
||||
grpc_client: &mut GrpcClient,
|
||||
is_saved: &mut bool,
|
||||
current_position: &mut u64,
|
||||
total_count: u64,
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
// src/modes/handlers/common.rs
|
||||
|
||||
use crate::tui::terminal::AppTerminal;
|
||||
use crate::tui::terminal::{
|
||||
core::TerminalCore,
|
||||
grpc_client::GrpcClient,
|
||||
commands::CommandHandler,
|
||||
};
|
||||
use crate::ui::handlers::form::FormState;
|
||||
use common::proto::multieko2::adresar::{PostAdresarRequest, PutAdresarRequest};
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
// src/modes/handlers/edit.rs
|
||||
|
||||
use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
|
||||
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 super::common;
|
||||
@@ -13,7 +17,7 @@ pub async fn handle_edit_event_internal(
|
||||
form_state: &mut FormState,
|
||||
ideal_cursor_column: &mut usize,
|
||||
command_message: &mut String,
|
||||
app_terminal: &mut AppTerminal, // Add these parameters
|
||||
terminal: &mut TerminalCore,
|
||||
is_saved: &mut bool,
|
||||
current_position: &mut u64,
|
||||
total_count: u64,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -4,7 +4,11 @@ use crossterm::event::{KeyEvent};
|
||||
use crate::config::config::Config;
|
||||
use crate::ui::handlers::form::FormState;
|
||||
use crate::config::key_sequences::KeySequenceTracker;
|
||||
use crate::tui::terminal::AppTerminal;
|
||||
use crate::tui::terminal::{
|
||||
core::TerminalCore,
|
||||
grpc_client::GrpcClient,
|
||||
commands::CommandHandler,
|
||||
};
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum CharType {
|
||||
|
||||
Reference in New Issue
Block a user