BREAKING CHANGES updating gRPC based on the enum now
This commit is contained in:
@@ -17,6 +17,15 @@ use crate::modes::{
|
||||
};
|
||||
use crate::config::binds::key_sequences::KeySequenceTracker;
|
||||
use crate::modes::handlers::mode_manager::{ModeManager, AppMode};
|
||||
use crate::tui::functions::common::form::SaveOutcome;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EventOutcome {
|
||||
Ok(String), // Normal operation, display message
|
||||
Exit(String), // Signal app exit, display message
|
||||
DataSaved(SaveOutcome, String), // Data save attempted, include outcome and message
|
||||
// Add other outcomes like QuitRequested, SaveAndQuitRequested later if needed
|
||||
}
|
||||
|
||||
pub struct EventHandler {
|
||||
pub command_mode: bool,
|
||||
@@ -55,7 +64,7 @@ impl EventHandler {
|
||||
app_state: &mut crate::state::state::AppState,
|
||||
total_count: u64,
|
||||
current_position: &mut u64,
|
||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||
) -> Result<EventOutcome, Box<dyn std::error::Error>> {
|
||||
let current_mode = ModeManager::derive_mode(app_state, self);
|
||||
app_state.update_mode(current_mode);
|
||||
|
||||
@@ -64,9 +73,10 @@ impl EventHandler {
|
||||
let modifiers = key.modifiers;
|
||||
|
||||
if UiStateHandler::toggle_sidebar(&mut app_state.ui, config, key_code, modifiers) {
|
||||
return Ok((false, format!("Sidebar {}",
|
||||
let message = format!("Sidebar {}",
|
||||
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
|
||||
)));
|
||||
);
|
||||
return Ok(EventOutcome::Ok(message));
|
||||
}
|
||||
|
||||
match current_mode {
|
||||
@@ -90,7 +100,7 @@ impl EventHandler {
|
||||
self.edit_mode_cooldown = true;
|
||||
self.command_message = "Edit mode".to_string();
|
||||
terminal.set_cursor_style(SetCursorStyle::BlinkingBar)?;
|
||||
return Ok((false, self.command_message.clone()));
|
||||
return Ok(EventOutcome::Ok(self.command_message.clone()));
|
||||
}
|
||||
|
||||
if config.is_enter_edit_mode_after(key_code, modifiers) &&
|
||||
@@ -119,7 +129,7 @@ impl EventHandler {
|
||||
self.edit_mode_cooldown = true;
|
||||
self.command_message = "Edit mode (after cursor)".to_string();
|
||||
terminal.set_cursor_style(SetCursorStyle::BlinkingBar)?;
|
||||
return Ok((false, self.command_message.clone()));
|
||||
return Ok(EventOutcome::Ok(self.command_message.clone()));
|
||||
}
|
||||
|
||||
if let Some(action) = config.get_read_only_action_for_key(key_code, modifiers) {
|
||||
@@ -127,7 +137,7 @@ impl EventHandler {
|
||||
self.command_mode = true;
|
||||
self.command_input.clear();
|
||||
self.command_message.clear();
|
||||
return Ok((false, String::new()));
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +164,7 @@ impl EventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
return read_only::handle_read_only_event(
|
||||
let message = read_only::handle_read_only_event(
|
||||
app_state,
|
||||
key,
|
||||
config,
|
||||
@@ -167,26 +177,27 @@ impl EventHandler {
|
||||
&mut self.command_message,
|
||||
&mut self.edit_mode_cooldown,
|
||||
&mut self.ideal_cursor_column,
|
||||
).await;
|
||||
).await?;
|
||||
return Ok(EventOutcome::Ok(message));
|
||||
},
|
||||
|
||||
AppMode::Edit => {
|
||||
if config.is_exit_edit_mode(key_code, modifiers) {
|
||||
self.is_edit_mode = false;
|
||||
self.edit_mode_cooldown = true;
|
||||
|
||||
|
||||
let has_changes = if app_state.ui.show_login {
|
||||
auth_state.has_unsaved_changes()
|
||||
} else {
|
||||
form_state.has_unsaved_changes()
|
||||
};
|
||||
|
||||
|
||||
self.command_message = if has_changes {
|
||||
"Exited edit mode (unsaved changes remain)".to_string()
|
||||
} else {
|
||||
"Read-only mode".to_string()
|
||||
};
|
||||
|
||||
|
||||
terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?;
|
||||
|
||||
let current_input = if app_state.ui.show_login {
|
||||
@@ -210,7 +221,7 @@ impl EventHandler {
|
||||
self.ideal_cursor_column = form_state.current_cursor_pos();
|
||||
}
|
||||
}
|
||||
return Ok((false, self.command_message.clone()));
|
||||
return Ok(EventOutcome::Ok(self.command_message.clone()));
|
||||
}
|
||||
|
||||
if let Some(action) = config.get_action_for_key_in_mode(
|
||||
@@ -220,23 +231,23 @@ impl EventHandler {
|
||||
) {
|
||||
match action {
|
||||
"save" | "force_quit" | "save_and_quit" | "revert" => {
|
||||
return common_mode::handle_core_action(
|
||||
action,
|
||||
form_state,
|
||||
auth_state,
|
||||
grpc_client,
|
||||
&mut self.auth_client,
|
||||
terminal,
|
||||
app_state,
|
||||
current_position,
|
||||
total_count,
|
||||
).await;
|
||||
},
|
||||
return common_mode::handle_core_action(
|
||||
action,
|
||||
form_state,
|
||||
auth_state,
|
||||
grpc_client,
|
||||
&mut self.auth_client,
|
||||
terminal,
|
||||
app_state,
|
||||
current_position,
|
||||
total_count,
|
||||
).await;
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
let result = edit::handle_edit_event(
|
||||
let message = edit::handle_edit_event(
|
||||
app_state.ui.show_login,
|
||||
key,
|
||||
config,
|
||||
@@ -244,18 +255,17 @@ impl EventHandler {
|
||||
auth_state,
|
||||
&mut self.ideal_cursor_column,
|
||||
&mut self.command_message,
|
||||
&mut app_state.ui.is_saved,
|
||||
current_position,
|
||||
total_count,
|
||||
grpc_client,
|
||||
).await?;
|
||||
|
||||
self.key_sequence_tracker.reset();
|
||||
return Ok((false, result));
|
||||
return Ok(EventOutcome::Ok(message));
|
||||
},
|
||||
|
||||
AppMode::Command => {
|
||||
let (should_exit, message, exit_command_mode) = command_mode::handle_command_event(
|
||||
let outcome = command_mode::handle_command_event(
|
||||
key,
|
||||
config,
|
||||
form_state,
|
||||
@@ -267,17 +277,18 @@ impl EventHandler {
|
||||
current_position,
|
||||
total_count,
|
||||
).await?;
|
||||
|
||||
if exit_command_mode {
|
||||
self.command_mode = false;
|
||||
|
||||
if let EventOutcome::Ok(msg) = &outcome {
|
||||
if msg == "Exited command mode" {
|
||||
self.command_mode = false;
|
||||
}
|
||||
}
|
||||
|
||||
return Ok((should_exit, message));
|
||||
return Ok(outcome);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.edit_mode_cooldown = false;
|
||||
Ok((false, self.command_message.clone()))
|
||||
Ok(EventOutcome::Ok(self.command_message.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user