From 5ae7493431d7a1a127309e3f9acb0f7dab04983b Mon Sep 17 00:00:00 2001 From: Tim Oram Date: Mon, 12 Feb 2024 10:33:24 -0330 Subject: Remove the concept of custom events Due to the input module previously being a separate crate, it needed to support dynamic application level event bindings. This created a lot of complexity in the event handling, with no value. This removes that custom functionality, and instead includes all the app level events under the standard events. --- src/application.rs | 19 ++-- src/components/choice.rs | 3 +- src/components/confirm.rs | 19 ++-- src/components/confirm/tests.rs | 15 ++- src/components/edit.rs | 3 +- src/components/help.rs | 3 +- src/components/search_bar.rs | 3 +- src/components/shared/editable_line.rs | 3 +- src/events.rs | 8 -- src/events/app_key_bindings.rs | 116 ---------------------- src/events/meta_event.rs | 83 ---------------- src/input.rs | 6 +- src/input/custom_event.rs | 2 - src/input/custom_key_binding.rs | 5 - src/input/event.rs | 19 ++-- src/input/event_handler.rs | 44 +++------ src/input/key_bindings.rs | 149 ++++++++++++++++++++++------- src/input/standard_event.rs | 70 ++++++++++++++ src/input/testutil.rs | 102 ++++++++------------ src/input/thread.rs | 39 +++----- src/input/thread/state.rs | 16 ++-- src/main.rs | 1 - src/module.rs | 3 +- src/module/module_handler.rs | 13 +-- src/module/tests.rs | 3 +- src/modules/confirm_abort.rs | 14 ++- src/modules/confirm_rebase.rs | 14 ++- src/modules/error.rs | 3 +- src/modules/external_editor.rs | 7 +- src/modules/external_editor/tests.rs | 22 +++-- src/modules/insert.rs | 3 +- src/modules/insert/tests.rs | 3 +- src/modules/list.rs | 140 +++++++++++++-------------- src/modules/list/tests/abort_and_rebase.rs | 42 ++++---- src/modules/list/tests/change_action.rs | 72 +++++++------- src/modules/list/tests/edit_mode.rs | 66 +++++++------ src/modules/list/tests/external_editor.rs | 12 +-- src/modules/list/tests/insert_line.rs | 4 +- src/modules/list/tests/movement.rs | 72 +++++++------- src/modules/list/tests/normal_mode.rs | 6 +- src/modules/list/tests/read_event.rs | 70 +++++++------- src/modules/list/tests/remove_lines.rs | 60 ++++++------ src/modules/list/tests/render.rs | 2 +- src/modules/list/tests/search.rs | 26 ++--- src/modules/list/tests/show_commit.rs | 12 +-- src/modules/list/tests/swap_lines.rs | 112 +++++++++++----------- src/modules/list/tests/toggle_break.rs | 8 +- src/modules/list/tests/toggle_option.rs | 6 +- src/modules/list/tests/undo_redo.rs | 44 ++++----- src/modules/list/tests/visual_mode.rs | 66 ++++++------- src/modules/show_commit.rs | 8 +- src/modules/show_commit/tests.rs | 6 +- src/modules/window_size_error.rs | 3 +- src/process.rs | 14 ++- src/process/artifact.rs | 2 +- src/process/results.rs | 2 +- src/process/tests.rs | 9 +- src/process/thread.rs | 3 +- src/testutil.rs | 6 -- src/testutil/create_event_reader.rs | 13 --- src/testutil/create_test_keybindings.rs | 44 --------- src/testutil/module_test.rs | 5 +- src/testutil/process_test.rs | 6 +- src/testutil/read_event_test.rs | 2 +- src/testutil/test_module_provider.rs | 3 +- src/testutil/with_event_handler.rs | 11 --- src/util.rs | 2 +- 67 files changed, 778 insertions(+), 994 deletions(-) delete mode 100644 src/events.rs delete mode 100644 src/events/app_key_bindings.rs delete mode 100644 src/events/meta_event.rs delete mode 100644 src/input/custom_event.rs delete mode 100644 src/input/custom_key_binding.rs delete mode 100644 src/testutil/create_event_reader.rs delete mode 100644 src/testutil/create_test_keybindings.rs delete mode 100644 src/testutil/with_event_handler.rs diff --git a/src/application.rs b/src/application.rs index 1b8bbb2..97a983b 100644 --- a/src/application.rs +++ b/src/application.rs @@ -6,11 +6,9 @@ use parking_lot::Mutex; use crate::{ config::Config, display::Display, - events, - events::{KeyBindings, MetaEvent}, git::Repository, help::build_help, - input::{Event, EventHandler, EventReaderFn}, + input::{Event, EventHandler, EventReaderFn, KeyBindings, StandardEvent}, module::{self, ExitStatus, ModuleHandler}, process::{self, Process}, runtime::{Runtime, ThreadStatuses, Threadable}, @@ -65,7 +63,7 @@ where ModuleProvider: module::ModuleProvider + Send + 'static let thread_statuses = ThreadStatuses::new(); let mut threads: Vec> = vec![]; - let input_threads = events::Thread::new(event_provider); + let input_threads = crate::input::Thread::new(event_provider); let input_state = input_threads.state(); threads.push(Box::new(input_threads)); @@ -182,8 +180,8 @@ where ModuleProvider: module::ModuleProvider + Send + 'static Ok(todo_file) } - fn create_search_update_handler(input_state: events::State) -> impl Fn() + Send + Sync { - move || input_state.push_event(Event::MetaEvent(MetaEvent::SearchUpdate)) + fn create_search_update_handler(input_state: crate::input::State) -> impl Fn() + Send + Sync { + move || input_state.push_event(Event::Standard(StandardEvent::SearchUpdate)) } } @@ -196,12 +194,11 @@ mod tests { use super::*; use crate::{ display::Size, - events::Event, - input::{KeyCode, KeyEvent, KeyModifiers}, + input::{testutil::create_event_reader, Event, KeyCode, KeyEvent, KeyModifiers}, module::Modules, runtime::{Installer, RuntimeError}, test_helpers::mocks::crossterm::CrossTerm, - testutil::{create_event_reader, set_git_directory, DefaultTestModule, TestModuleProvider}, + testutil::{set_git_directory, DefaultTestModule, TestModuleProvider}, }; fn args(args: &[&str]) -> Args { @@ -350,13 +347,13 @@ mod tests { #[serial_test::serial] fn search_update_handler_handles_update() { let event_provider = create_event_reader(|| Ok(None)); - let input_threads = events::Thread::new(event_provider); + let input_threads = crate::input::Thread::new(event_provider); let input_state = input_threads.state(); let update_handler = Application::>::create_search_update_handler(input_state.clone()); update_handler(); - assert_eq!(input_state.read_event(), Event::MetaEvent(MetaEvent::SearchUpdate)); + assert_eq!(input_state.read_event(), Event::Standard(StandardEvent::SearchUpdate)); } #[test] diff --git a/src/components/choice.rs b/src/components/choice.rs index a5498ff..73f7e77 100644 --- a/src/components/choice.rs +++ b/src/components/choice.rs @@ -7,8 +7,7 @@ use lazy_static::lazy_static; use crate::{ display::DisplayColor, - events::Event, - input::{InputOptions, KeyCode}, + input::{Event, InputOptions, KeyCode}, util::handle_view_data_scroll, view::{LineSegment, ViewData, ViewLine}, }; diff --git a/src/components/confirm.rs b/src/components/confirm.rs index 7401cd9..60464c2 100644 --- a/src/components/confirm.rs +++ b/src/components/confirm.rs @@ -7,8 +7,7 @@ use lazy_static::lazy_static; pub(crate) use self::confirmed::Confirmed; use crate::{ - events::{Event, KeyBindings, MetaEvent}, - input::{InputOptions, KeyCode, KeyEvent}, + input::{Event, InputOptions, KeyBindings, KeyCode, KeyEvent, StandardEvent}, view::{ViewData, ViewLine}, }; @@ -49,13 +48,13 @@ impl Confirm { )); let event_upper = Event::Key(KeyEvent::new(KeyCode::Char(c.to_ascii_uppercase()), key.modifiers)); - return if key_bindings.custom.confirm_yes.contains(&event_lower) - || key_bindings.custom.confirm_yes.contains(&event_upper) + return if key_bindings.confirm_yes.contains(&event_lower) + || key_bindings.confirm_yes.contains(&event_upper) { - Event::from(MetaEvent::Yes) + Event::from(StandardEvent::Yes) } else { - Event::from(MetaEvent::No) + Event::from(StandardEvent::No) }; } } @@ -64,10 +63,10 @@ impl Confirm { #[allow(clippy::unused_self)] pub(crate) const fn handle_event(&self, event: Event) -> Confirmed { - if let Event::MetaEvent(meta_event) = event { - match meta_event { - MetaEvent::Yes => Confirmed::Yes, - MetaEvent::No => Confirmed::No, + if let Event::Standard(standard_event) = event { + match standard_event { + StandardEvent::Yes => Confirmed::Yes, + StandardEvent::No => Confirmed::No, _ => Confirmed::Other, } } diff --git a/src/components/confirm/tests.rs b/src/components/confirm/tests.rs index d6b77d7..f53269c 100644 --- a/src/components/confirm/tests.rs +++ b/src/components/confirm/tests.rs @@ -3,8 +3,7 @@ use rstest::rstest; use super::*; use crate::{ assert_rendered_output, - input::StandardEvent, - testutil::create_test_keybindings, + input::{testutil::create_test_keybindings, StandardEvent}, view::testutil::AssertRenderOptions, }; @@ -25,7 +24,7 @@ fn render() { fn read_event_yes_uppercase() { assert_eq!( Confirm::read_event(Event::from('Y'), &create_test_keybindings()), - Event::from(MetaEvent::Yes) + Event::from(StandardEvent::Yes) ); } @@ -33,7 +32,7 @@ fn read_event_yes_uppercase() { fn read_event_yes_lowercase() { assert_eq!( Confirm::read_event(Event::from('y'), &create_test_keybindings()), - Event::from(MetaEvent::Yes) + Event::from(StandardEvent::Yes) ); } @@ -41,7 +40,7 @@ fn read_event_yes_lowercase() { fn read_event_no_lowercase() { assert_eq!( Confirm::read_event(Event::from('n'), &create_test_keybindings()), - Event::from(MetaEvent::No) + Event::from(StandardEvent::No) ); } @@ -49,7 +48,7 @@ fn read_event_no_lowercase() { fn read_event_no_uppercase() { assert_eq!( Confirm::read_event(Event::from('N'), &create_test_keybindings()), - Event::from(MetaEvent::No) + Event::from(StandardEvent::No) ); } @@ -72,14 +71,14 @@ fn read_event_not_char_event() { #[test] fn handle_event_yes() { let module = Confirm::new("Prompt message", &[], &[]); - let confirmed = module.handle_event(Event::from(MetaEvent::Yes)); + let confirmed = module.handle_event(Event::from(StandardEvent::Yes)); assert_eq!(confirmed, Confirmed::Yes); } #[test] fn handle_event_no() { let module = Confirm::new("Prompt message", &[], &[]); - let confirmed = module.handle_event(Event::from(MetaEvent::No)); + let confirmed = module.handle_event(Event::from(StandardEvent::No)); assert_eq!(confirmed, Confirmed::No); } diff --git a/src/components/edit.rs b/src/components/edit.rs index 9c04491..ed86f10 100644 --- a/src/components/edit.rs +++ b/src/components/edit.rs @@ -6,8 +6,7 @@ use lazy_static::lazy_static; use crate::{ components::shared::EditableLine, display::DisplayColor, - events::Event, - input::{InputOptions, KeyCode, KeyEvent, KeyModifiers}, + input::{Event, InputOptions, KeyCode, KeyEvent, KeyModifiers}, view::{LineSegment, ViewData, ViewDataUpdater, ViewLine}, }; diff --git a/src/components/help.rs b/src/components/help.rs index f9caa85..e68fa72 100644 --- a/src/components/help.rs +++ b/src/components/help.rs @@ -5,9 +5,8 @@ use unicode_segmentation::UnicodeSegmentation; use crate::{ display::DisplayColor, - events::Event, first, - input::{InputOptions, StandardEvent}, + input::{Event, InputOptions, StandardEvent}, util::handle_view_data_scroll, view::{LineSegment, ViewData, ViewLine}, }; diff --git a/src/components/search_bar.rs b/src/components/search_bar.rs index 6cbe3d9..7b9991d 100644 --- a/src/components/search_bar.rs +++ b/src/components/search_bar.rs @@ -9,8 +9,7 @@ use crate::{ search_bar::state::State, shared::{EditAction, EditableLine}, }, - events::Event, - input::{InputOptions, KeyCode, KeyEvent, KeyModifiers, StandardEvent}, + input::{Event, InputOptions, KeyCode, KeyEvent, KeyModifiers, StandardEvent}, view::{LineSegment, ViewLine}, }; diff --git a/src/components/shared/editable_line.rs b/src/components/shared/editable_line.rs index e65aa0e..0001879 100644 --- a/src/components/shared/editable_line.rs +++ b/src/components/shared/editable_line.rs @@ -2,8 +2,7 @@ use unicode_segmentation::UnicodeSegmentation; use crate::{ display::DisplayColor, - events::Event, - input::{KeyCode, KeyEvent, KeyModifiers}, + input::{Event, KeyCode, KeyEvent, KeyModifiers}, view::LineSegment, }; diff --git a/src/events.rs b/src/events.rs deleted file mode 100644 index 77d30d7..0000000 --- a/src/events.rs +++ /dev/null @@ -1,8 +0,0 @@ -mod app_key_bindings; -mod meta_event; - -pub(crate) use self::{app_key_bindings::AppKeyBindings, meta_event::MetaEvent}; -pub(crate) type KeyBindings = crate::input::KeyBindings; -pub(crate) type Event = crate::input::Event; -pub(crate) type State = crate::input::State; -pub(crate) type Thread = crate::input::Thread; diff --git a/src/events/app_key_bindings.rs b/src/events/app_key_bindings.rs deleted file mode 100644 index 68e85ba..0000000 --- a/src/events/app_key_bindings.rs +++ /dev/null @@ -1,116 +0,0 @@ -use crate::{ - config::KeyBindings, - events::{Event, MetaEvent}, - input::CustomKeybinding, -}; - -pub(crate) fn map_keybindings(bindings: &[String]) -> Vec { - crate::input::map_keybindings::(bindings) -} - -/// Represents a mapping between an input event and an action. -#[derive(Debug)] -#[non_exhaustive] -pub(crate) struct AppKeyBindings { - /// Key bindings for aborting. - pub(crate) abort: Vec, - /// Key bindings for the break action. - pub(crate) action_break: Vec, - /// Key bindings for the drop action. - pub(crate) action_drop: Vec, - /// Key bindings for the edit action. - pub(crate) action_edit: Vec, - /// Key bindings for the fixup action. - pub(crate) action_fixup: Vec, - /// Key bindings for the pick action. - pub(crate) action_pick: Vec, - /// Key bindings for the reword action. - pub(crate) action_reword: Vec, - /// Key bindings for the squash action. - pub(crate) action_squash: Vec, - /// Key bindings for positive confirmation. - pub(crate) confirm_yes: Vec, - /// Key bindings for editing. - pub(crate) edit: Vec, - /// Key bindings for forcing an abort. - pub(crate) force_abort: Vec, - /// Key bindings for forcing a rebase. - pub(crate) force_rebase: Vec, - /// Key bindings for inserting a line. - pub(crate) insert_line: Vec, - /// Key bindings for moving down. - pub(crate) move_down: Vec, - /// Key bindings for moving down a step. - pub(crate) move_down_step: Vec, - /// Key bindings for moving to the end. - pub(crate) move_end: Vec, - /// Key bindings for moving to the start. - pub(crate) move_home: Vec, - /// Key bindings for moving to the left. - pub(crate) move_left: Vec, - /// Key bindings for moving to the right. - pub(crate) move_right: Vec, - /// Key bindings for moving the selection down. - pub(crate) move_selection_down: Vec, - /// Key bindings for moving the selection up. - pub(crate) move_selection_up: Vec, - /// Key bindings for moving up. - pub(crate) move_up: Vec, - /// Key bindings for moving up a step. - pub(crate) move_up_step: Vec, - /// Key bindings for opening the external editor. - pub(crate) open_in_external_editor: Vec, - /// Key bindings for rebasing. - pub(crate) rebase: Vec, - /// Key bindings for removing a line. - pub(crate) remove_line: Vec, - /// Key bindings for showing a commit. - pub(crate) show_commit: Vec, - /// Key bindings for showing a diff. - pub(crate) show_diff: Vec, - /// Key bindings for toggling visual mode. - pub(crate) toggle_visual_mode: Vec, - /// Key bindings for the fixup specific action to toggle the c option. - pub(crate) fixup_keep_message: Vec, - /// Key biding for the fixup specific action to toggle the C option. - pub(crate) fixup_keep_message_with_editor: Vec, -} - -impl CustomKeybinding for AppKeyBindings { - /// Create a new instance from the configuration keybindings. - fn new(key_bindings: &KeyBindings) -> Self { - Self { - abort: map_keybindings(&key_bindings.abort), - action_break: map_keybindings(&key_bindings.action_break), - action_drop: map_keybindings(&key_bindings.action_drop), - action_edit: map_keybindings(&key_bindings.action_edit), - action_fixup: map_keybindings(&key_bindings.action_fixup), - action_pick: map_keybindings(&key_bindings.action_pick), - action_reword: map_keybindings(&key_bindings.action_reword), - action_squash: map_keybindings(&key_bindings.action_squash), - edit: map_keybindings(&key_bindings.edit), - force_abort: map_keybindings(&key_bindings.force_abort), - force_rebase: map_keybindings(&key_bindings.force_rebase), - insert_line: map_keybindings(&key_bindings.insert_line), - move_down: map_keybindings(&key_bindings.move_down), - move_down_step: map_keybindings(&key_bindings.move_down_step), - move_end: map_keybindings(&key_bindings.move_end), - move_home: map_keybindings(&key_bindings.move_home), - move_left: map_keybindings(&key_bindings.move_left), - move_right: map_keybindings(&key_bindings.move_right), - move_selection_down: map_keybindings(&key_bindings.move_selection_down), - move_selection_up: map_keybindings(&key_bindings.move_selection_up), - move_up: map_keybindings(&key_bindings.move_up), - move_up_step: map_keybindings(&key_bindings.move_up_step), - open_in_external_editor: map_keybindings(&key_bindings.open_in_external_editor), - rebase: map_keybindings(&key_bindings.rebase), - remove_line: map_keybindings(&key_bindings.remove_line), - show_commit: map_keybindings(&key_bindings.show_commit), - show_diff: map_keybindings(&key_bindings.show_diff), - toggle_visual_mode: map_keybindings(&key_bindings.toggle_visual_mode), - confirm_yes: map_keybindings(&key_bindings.confirm_yes), - fixup_keep_message: map_keybindings(&key_bindings.fixup_keep_message), - fixup_keep_message_with_editor: map_keybindings(&key_bindings.fixup_keep_message_with_editor), - } - } -} diff --git a/src/events/meta_event.rs b/src/events/meta_event.rs deleted file mode 100644 index dddd57a..0000000 --- a/src/events/meta_event.rs +++ /dev/null @@ -1,83 +0,0 @@ -use crate::events::Event; - -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd)] -pub(crate) enum MetaEvent { - /// The abort meta event. - Abort, - /// The force abort meta event. - ForceAbort, - /// The rebase meta event. - Rebase, - /// The force rebase meta event. - ForceRebase, - /// The break action meta event. - ActionBreak, - /// The drop action meta event. - ActionDrop, - /// The edit action meta event. - ActionEdit, - /// The fixup action meta event. - ActionFixup, - /// The pick action meta event. - ActionPick, - /// The reword action meta event. - ActionReword, - /// The squash action meta event. - ActionSquash, - /// The move cursor down meta event. - MoveCursorDown, - /// The move cursor to end meta event. - MoveCursorEnd, - /// The move cursor to home meta event. - MoveCursorHome, - /// The move cursor left meta event. - MoveCursorLeft, - /// The move cursor page down meta event. - MoveCursorPageDown, - /// The move cursor page up meta event. - MoveCursorPageUp, - /// The move cursor right meta event. - MoveCursorRight, - /// The move cursor up meta event. - MoveCursorUp, - /// The delete meta event. - Delete, - /// The edit meta event. - Edit, - /// The open in editor meta event. - OpenInEditor, - /// The show commit meta event. - ShowCommit, - /// The show diff meta event. - ShowDiff, - /// The swap selection down meta event. - SwapSelectedDown, - /// The swap selection up meta event. - SwapSelectedUp, - /// The toggle visual mode meta event. - ToggleVisualMode, - /// The insert line meta event. - InsertLine, - /// Fixup specific action to toggle the c option. - FixupKeepMessage, - /// Fixup specific action to toggle the C option. - FixupKeepMessageWithEditor, - /// The no meta event. - No, - /// The yes meta event. - Yes, - /// The external command was successful meta event. - ExternalCommandSuccess, - /// The external command was an error meta event. - ExternalCommandError, - /// Search was updated - SearchUpdate, -} - -impl crate::input::CustomEvent for MetaEvent {} - -impl From for Event { - fn from(event: MetaEvent) -> Self { - Self::MetaEvent(event) - } -} diff --git a/src/input.rs b/src/input.rs index f74f182..a330813 100644 --- a/src/input.rs +++ b/src/input.rs @@ -8,8 +8,6 @@ //! these utilities are not tested, and often are optimized for developer experience than //! performance should only be used in test code. -mod custom_event; -mod custom_key_binding; mod event; mod event_handler; mod event_provider; @@ -17,15 +15,13 @@ mod input_options; mod key_bindings; mod key_event; mod standard_event; -#[cfg(not(tarpaulin_include))] +#[cfg(test)] pub(crate) mod testutil; mod thread; pub(crate) use crossterm::event::{KeyCode, KeyModifiers, MouseEvent, MouseEventKind}; pub(crate) use self::{ - custom_event::CustomEvent, - custom_key_binding::CustomKeybinding, event::Event, event_handler::EventHandler, event_provider::{read_event, EventReaderFn}, diff --git a/src/input/custom_event.rs b/src/input/custom_event.rs deleted file mode 100644 index 5f7ba97..0000000 --- a/src/input/custom_event.rs +++ /dev/null @@ -1,2 +0,0 @@ -/// A custom event compatible enum. -pub(crate) trait CustomEvent: PartialOrd + PartialEq + Eq + Clone + Copy {} diff --git a/src/input/custom_key_binding.rs b/src/input/custom_key_binding.rs deleted file mode 100644 index 7fdb656..0000000 --- a/src/input/custom_key_binding.rs +++ /dev/null @@ -1,5 +0,0 @@ -/// A custom keybindings compatible struct. -pub(crate) trait CustomKeybinding { - /// Create a new instance from the configuration keybindings. - fn new(key_bindings: &crate::config::KeyBindings) -> Self; -} diff --git a/src/input/event.rs b/src/input/event.rs index 1085ec9..f96f817 100644 --- a/src/input/event.rs +++ b/src/input/event.rs @@ -4,8 +4,8 @@ use crate::input::{KeyEvent, StandardEvent}; /// An event, either from an input device, system change or action event. #[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy)] -#[allow(clippy::exhaustive_enums, clippy::enum_variant_names)] -pub(crate) enum Event { +#[allow(clippy::exhaustive_enums)] +pub(crate) enum Event { /// A keyboard event. Key(KeyEvent), /// An action event. @@ -16,11 +16,9 @@ pub(crate) enum Event { None, /// A terminal resize event. Resize(u16, u16), - /// Custom application defined events - MetaEvent(CustomEvent), } -impl From for Event { +impl From for Event { fn from(event: crossterm::event::Event) -> Self { match event { crossterm::event::Event::Key(evt) => Self::Key(KeyEvent::from(evt)), @@ -34,31 +32,31 @@ impl From for E } } -impl From for Event { +impl From for Event { fn from(key_event: KeyEvent) -> Self { Self::Key(key_event) } } -impl From for Event { +impl From for Event { fn from(mouse_event: MouseEvent) -> Self { Self::Mouse(mouse_event) } } -impl From for Event { +impl From for Event { fn from(event: StandardEvent) -> Self { Self::Standard(event) } } -impl From for Event { +impl From for Event { fn from(code: KeyCode) -> Self { Self::Key(KeyEvent::from(code)) } } -impl From for Event { +impl From for Event { fn from(c: char) -> Self { Self::Key(KeyEvent::from(KeyCode::Char(c))) } @@ -72,7 +70,6 @@ mod tests { }; use super::*; - use crate::input::testutil::local::Event; #[test] fn from_crossterm_key_event() { diff --git a/src/input/event_handler.rs b/src/input/event_handler.rs index 11b280f..a26c22e 100644 --- a/src/input/event_handler.rs +++ b/src/input/event_handler.rs @@ -2,31 +2,21 @@ use crate::input::{Event, InputOptions, KeyBindings, KeyCode, KeyEvent, KeyModif /// A handler for reading and processing events. #[derive(Debug)] -pub(crate) struct EventHandler -{ - key_bindings: KeyBindings, +pub(crate) struct EventHandler { + key_bindings: KeyBindings, } -impl - EventHandler -{ +impl EventHandler { /// Create a new instance of the `EventHandler`. #[must_use] - pub(crate) const fn new(key_bindings: KeyBindings) -> Self { + pub(crate) const fn new(key_bindings: KeyBindings) -> Self { Self { key_bindings } } /// Read and handle an event. #[allow(clippy::trivially_copy_pass_by_ref)] - pub(crate) fn read_event( - &self, - event: Event, - input_options: &InputOptions, - callback: F, - ) -> Event - where - F: FnOnce(Event, &KeyBindings) -> Event, - { + pub(crate) fn read_event(&self, event: Event, input_options: &InputOptions, callback: F) -> Event + where F: FnOnce(Event, &KeyBindings) -> Event { if event == Event::None { return event; } @@ -67,7 +57,7 @@ impl) -> Option> { + fn handle_standard_inputs(event: Event) -> Option { match event { Event::Key(KeyEvent { code: KeyCode::Char('c'), @@ -78,10 +68,7 @@ impl, - event: Event, - ) -> Option> { + fn handle_movement_inputs(key_bindings: &KeyBindings, event: Event) -> Option { Some(match event { e if key_bindings.scroll_down.contains(&e) => Event::from(StandardEvent::ScrollDown), e if key_bindings.scroll_end.contains(&e) => Event::from(StandardEvent::ScrollBottom), @@ -128,10 +115,7 @@ impl, - event: Event, - ) -> Option> { + fn handle_search(key_bindings: &KeyBindings, event: Event) -> Option { match event { e if key_bindings.search_next.contains(&e) => Some(Event::from(StandardEvent::SearchNext)), e if key_bindings.search_previous.contains(&e) => Some(Event::from(StandardEvent::SearchPrevious)), @@ -140,10 +124,7 @@ impl, - event: Event, - ) -> Option> { + fn handle_undo_redo(key_bindings: &KeyBindings, event: Event) -> Option { if key_bindings.undo.contains(&event) { Some(Event::from(StandardEvent::Undo)) } @@ -161,10 +142,7 @@ mod tests { use rstest::rstest; use super::*; - use crate::input::{ - map_keybindings, - testutil::local::{create_test_keybindings, Event, EventHandler}, - }; + use crate::input::{map_keybindings, testutil::create_test_keybindings}; #[rstest] #[case::standard(Event::Key(KeyEvent { diff --git a/src/input/key_bindings.rs b/src/input/key_bindings.rs index e176416..66cb122 100644 --- a/src/input/key_bindings.rs +++ b/src/input/key_bindings.rs @@ -3,48 +3,107 @@ use crate::input::{Event, KeyCode, KeyEvent, KeyModifiers}; /// Represents a mapping between an input event and an action. #[derive(Debug)] #[non_exhaustive] -pub(crate) struct KeyBindings -{ +pub(crate) struct KeyBindings { /// Key bindings for redoing a change. - pub(crate) redo: Vec>, + pub(crate) redo: Vec, /// Key bindings for undoing a change. - pub(crate) undo: Vec>, + pub(crate) undo: Vec, /// Key bindings for scrolling down. - pub(crate) scroll_down: Vec>, + pub(crate) scroll_down: Vec, /// Key bindings for scrolling to the end. - pub(crate) scroll_end: Vec>, + pub(crate) scroll_end: Vec, /// Key bindings for scrolling to the start. - pub(crate) scroll_home: Vec>, + pub(crate) scroll_home: Vec, /// Key bindings for scrolling to the left. - pub(crate) scroll_left: Vec>, + pub(crate) scroll_left: Vec, /// Key bindings for scrolling to the right. - pub(crate) scroll_right: Vec>, + pub(crate) scroll_right: Vec, /// Key bindings for scrolling up. - pub(crate) scroll_up: Vec>, + pub(crate) scroll_up: Vec, /// Key bindings for scrolling down a step. - pub(crate) scroll_step_down: Vec>, + pub(crate) scroll_step_down: Vec, /// Key bindings for scrolling up a step. - pub(crate) scroll_step_up: Vec>, + pub(crate) scroll_step_up: Vec, /// Key bindings for help. - pub(crate) help: Vec>, + pub(crate) help: Vec, /// Key bindings for starting search. - pub(crate) search_start: Vec>, + pub(crate) search_start: Vec, /// Key bindings for next search match. - pub(crate) search_next: Vec>, + pub(crate) search_next: Vec, /// Key bindings for previous search match. - pub(crate) search_previous: Vec>, + pub(crate) search_previous: Vec, - /// Custom keybindings - pub(crate) custom: CustomKeybinding, + /// Key bindings for aborting. + pub(crate) abort: Vec, + /// Key bindings for the break action. + pub(crate) action_break: Vec, + /// Key bindings for the drop action. + pub(crate) action_drop: Vec, + /// Key bindings for the edit action. + pub(crate) action_edit: Vec, + /// Key bindings for the fixup action. + pub(crate) action_fixup: Vec, + /// Key bindings for the pick action. + pub(crate) action_pick: Vec, + /// Key bindings for the reword action. + pub(crate) action_reword: Vec, + /// Key bindings for the squash action. + pub(crate) action_squash: Vec, + /// Key bindings for positive confirmation. + pub(crate) confirm_yes: Vec, + /// Key bindings for editing. + pub(crate) edit: Vec, + /// Key bindings for forcing an abort. + pub(crate) force_abort: Vec, + /// Key bindings for forcing a rebase. + pub(crate) force_rebase: Vec, + /// Key bindings for inserting a line. + pub(crate) insert_line: Vec, + /// Key bindings for moving down. + pub(crate) move_down: Vec, + /// Key bindings for moving down a step. + pub(crate) move_down_step: Vec, + /// Key bindings for moving to the end. + pub(crate) move_end: Vec, + /// Key bindings for moving to the start. + pub(crate) move_home: Vec, + /// Key bindings for moving to the left. + pub(crate) move_left: Vec, + /// Key bindings for moving to the right. + pub(crate) move_right: Vec, + /// Key bindings for moving the selection down. + pub(crate) move_selection_down: Vec, + /// Key bindings for moving the selection up. + pub(crate) move_selection_up: Vec, + /// Key bindings for moving up. + pub(crate) move_up: Vec, + /// Key bindings for moving up a step. + pub(crate) move_up_step: Vec, + /// Key bindings for opening the external editor. + pub(crate) open_in_external_editor: Vec, + /// Key bindings for rebasing. + pub(crate) rebase: Vec, + /// Key bindings for removing a line. + pub(crate) remove_line: Vec, + /// Key bindings for showing a commit. + pub(crate) show_commit: Vec, + /// Key bindings for showing a diff. + pub(crate) show_diff: Vec, + /// Key bindings for toggling visual mode. + pub(crate) toggle_visual_mode: Vec, + /// Key bindings for the fixup specific action to toggle the c option. + pub(crate) fixup_keep_message: Vec, + /// Key biding for the fixup specific action to toggle the C option. + pub(crate) fixup_keep_message_with_editor: Vec, } /// Map a keybinding to a list of events. #[must_use] #[allow(clippy::string_slice, clippy::missing_panics_doc)] -pub(crate) fn map_keybindings(bindings: &[String]) -> Vec> { +pub(crate) fn map_keybindings(bindings: &[String]) -> Vec { bindings .iter() .map(|b| { @@ -91,9 +150,7 @@ pub(crate) fn map_keybindings(bindings: .collect() } -impl - KeyBindings -{ +impl KeyBindings { /// Create a new instance from the configuration keybindings. #[must_use] pub(crate) fn new(key_bindings: &crate::config::KeyBindings) -> Self { @@ -112,7 +169,37 @@ impl::new(&crate::config::KeyBindings::new()); + let _key_bindings = KeyBindings::new(&crate::config::KeyBindings::new()); } #[test] fn map_keybindings_with_modifiers() { - assert_eq!( - map_keybindings::(&[String::from("ControlAltShiftUp")]), - vec![Event::Key(KeyEvent::new( + assert_eq!(map_keybindings(&[String::from("ControlAltShiftUp")]), vec![Event::Key( + KeyEvent::new( KeyCode::Up, KeyModifiers::CONTROL | KeyModifiers::ALT | KeyModifiers::SHIFT - ))] - ); + ) + )]); } #[rstest] @@ -160,8 +245,6 @@ mod tests { #[case::function_out_of_range("F10000", KeyCode::F(1))] #[case::char("a", KeyCode::Char('a'))] fn map_keybindings_key_code(#[case] binding: &str, #[case] key_code: KeyCode) { - assert_eq!(map_keybindings::(&[String::from(binding)]), vec![ - Event::from(key_code) - ]); + assert_eq!(map_keybindings(&[String::from(binding)]), vec![Event::from(key_code)]); } } diff --git a/src/input/standard_event.rs b/src/input/standard_event.rs index 0534bca..ddbec51 100644 --- a/src/input/standard_event.rs +++ b/src/input/standard_event.rs @@ -36,4 +36,74 @@ pub(crate) enum StandardEvent { SearchPrevious, /// Finish search mode meta event. SearchFinish, + /// The abort meta event. + Abort, + /// The force abort meta event. + ForceAbort, + /// The rebase meta event. + Rebase, + /// The force rebase meta event. + ForceRebase, + /// The break action meta event. + ActionBreak, + /// The drop action meta event. + ActionDrop, + /// The edit action meta event. + ActionEdit, + /// The fixup action meta event. + ActionFixup, + /// The pick action meta event. + ActionPick, + /// The reword action meta event. + ActionReword, + /// The squash action meta event. + ActionSquash, + /// The move cursor down meta event. + MoveCursorDown, + /// The move cursor to end meta event. + MoveCursorEnd, + /// The move cursor to home meta event. + MoveCursorHome, + /// The move cursor left meta event. + MoveCursorLeft, + /// The move cursor page down meta event. + MoveCursorPageDown, + /// The move cursor page up meta event. + MoveCursorPageUp, + /// The move cursor right meta event. + MoveCursorRight, + /// The move cursor up meta event. + MoveCursorUp, + /// The delete meta event. + Delete, + /// The edit meta event. + Edit, + /// The open in editor meta event. + OpenInEditor, + /// The show commit meta event. + ShowCommit, + /// The show diff meta event. + ShowDiff, + /// The swap selection down meta event. + SwapSelectedDown, + /// The swap selection up meta event. + SwapSelectedUp, + /// The toggle visual mode meta event. + ToggleVisualMode, + /// The insert line meta event. + InsertLine, + /// Fixup specific action to toggle the c option. + FixupKeepMessage, + /// Fixup specific action to toggle the C option. + FixupKeepMessageWithEditor, + /// The no meta event. + No, + /// The yes meta event. + Yes, + /// The external command was successful meta event. + ExternalCommandSuccess, + /// The external command was an error meta event. + ExternalCommandError, + /// Search was updated + SearchUpdate, } diff --git a/src/input/testutil.rs b/src/input/testutil.rs index bd19319..ae6e96a 100644 --- a/src/input/testutil.rs +++ b/src/input/testutil.rs @@ -15,47 +15,9 @@ use crate::input::{ State, }; -#[cfg(test)] -pub(crate) mod local { - use anyhow::Result; - - use crate::input::{CustomEvent, CustomKeybinding, EventReaderFn}; - - #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd)] - pub(crate) enum TestEvent {} - impl CustomEvent for TestEvent {} - - pub(crate) struct TestKeybinding; - impl CustomKeybinding for TestKeybinding { - fn new(_: &crate::config::KeyBindings) -> Self { - Self {} - } - } - - pub(crate) type Event = crate::input::Event; - pub(crate) type EventHandler = crate::input::EventHandler; - pub(crate) type KeyBindings = crate::input::KeyBindings; - - pub(crate) fn create_test_keybindings() -> KeyBindings { - super::create_test_keybindings::(TestKeybinding {}) - } - - pub(crate) fn create_event_reader( - event_generator: EventGeneratorFunction, - ) -> impl EventReaderFn - where EventGeneratorFunction: Fn() -> Result> + Sync + Send + 'static { - super::create_event_reader(event_generator) - } -} - /// Create a mocked version of `KeyBindings`. #[must_use] -pub(crate) fn create_test_keybindings< - TestKeybinding: crate::input::CustomKeybinding, - CustomEvent: crate::input::CustomEvent, ->( - custom_key_bindings: TestKeybinding, -) -> KeyBindings { +pub(crate) fn create_test_keybindings() -> KeyBindings { KeyBindings { redo: vec![Event::from(KeyEvent::new(KeyCode::Char('y'), KeyModifiers::CONTROL))], undo: vec![Event::from(KeyEvent::new(KeyCode::Char('z'), KeyModifiers::CONTROL))], @@ -71,36 +33,57 @@ pub(crate) fn create_test_keybindings< search_start: map_keybindings(&[String::from("/")]), search_next: map_keybindings(&[String::from("n")]), search_previous: map_keybindings(&[String::from("N")]), - custom: custom_key_bindings, + abort: map_keybindings(&[String::from("q")]), + action_break: map_keybindings(&[String::from("b")]), + action_drop: map_keybindings(&[String::from("d")]), + action_edit: map_keybindings(&[String::from("e")]), + action_fixup: map_keybindings(&[String::from("f")]), + action_pick: map_keybindings(&[String::from("p")]), + action_reword: map_keybindings(&[String::from("r")]), + action_squash: map_keybindings(&[String::from("s")]), + confirm_yes: map_keybindings(&[String::from("y")]), + edit: map_keybindings(&[String::from("E")]), + force_abort: map_keybindings(&[String::from("Q")]), + force_rebase: map_keybindings(&[String::from("W")]), + insert_line: map_keybindings(&[String::from("I")]), + move_down: map_keybindings(&[String::from("Down")]), + move_down_step: map_keybindings(&[String::from("PageDown")]), + move_end: map_keybindings(&[String::from("End")]), + move_home: map_keybindings(&[String::from("Home")]), + move_left: map_keybindings(&[String::from("Left")]), + move_right: map_keybindings(&[String::from("Right")]), + move_selection_down: map_keybindings(&[String::from("j")]), + move_selection_up: map_keybindings(&[String::from("k")]), + move_up: map_keybindings(&[String::from("Up")]), + move_up_step: map_keybindings(&[String::from("PageUp")]), + open_in_external_editor: map_keybindings(&[String::from('!')]), + rebase: map_keybindings(&[String::from('w')]), + remove_line: map_keybindings(&[String::from("Delete")]), + show_commit: map_keybindings(&[String::from("c")]), + show_diff: map_keybindings(&[String::from("d")]), + toggle_visual_mode: map_keybindings(&[String::from("v")]), + fixup_keep_message: map_keybindings(&[String::from("u")]), + fixup_keep_message_with_editor: map_keybindings(&[String::from("U")]), } } /// Context for a `EventHandler` based test. #[derive(Debug)] #[non_exhaustive] -pub(crate) struct TestContext { +pub(crate) struct TestContext { /// The `EventHandler` instance. - pub(crate) event_handler: EventHandler, + pub(crate) event_handler: EventHandler, /// The sender instance. - pub(crate) state: State, + pub(crate) state: State, /// The number of known available events. pub(crate) number_events: usize, } /// Provide an `EventHandler` instance for use within a test. #[allow(clippy::missing_panics_doc)] -pub(crate) fn with_event_handler< - C, - TestKeybinding: crate::input::CustomKeybinding, - CustomEvent: crate::input::CustomEvent, ->( - custom_key_bindings: TestKeybinding, - events: &[Event], - callback: C, -) where - C: FnOnce(TestContext), -{ - let event_handler = EventHandler::new(create_test_keybindings(custom_key_bindings)); +pub(crate) fn with_event_handler(events: &[Event], callback: C) +where C: FnOnce(TestContext) { + let event_handler = EventHandler::new(create_test_keybindings()); let state = State::new(); for event in events { @@ -125,13 +108,10 @@ pub(crate) fn with_event_handler< /// # Panics /// If provided an event generator that returns a `Event::MetaEvent` or `Event::StandardEvent` event type. #[allow(clippy::panic)] -pub(crate) fn create_event_reader( +pub(crate) fn create_event_reader( event_generator: EventGeneratorFunction, ) -> impl EventReaderFn -where - EventGeneratorFunction: Fn() -> Result>> + Sync + Send + 'static, - CustomEvent: crate::input::CustomEvent, -{ +where EventGeneratorFunction: Fn() -> Result> + Sync + Send + 'static { move || { match event_generator()? { None => Ok(None), @@ -146,7 +126,7 @@ where Event::Mouse(mouse_event) => Ok(Some(c_event::Event::Mouse(mouse_event))), Event::None => Ok(None), Event::Resize(width, height) => Ok(Some(c_event::Event::Resize(width, height))), - Event::MetaEvent(_) | Event::Standard(_) => { + Event::Standard(_) => { panic!("MetaEvent and Standard are not supported, please use other event types") }, } diff --git a/src/input/thread.rs b/src/input/thread.rs index 9339278..d22ff7c 100644 --- a/src/input/thread.rs +++ b/src/input/thread.rs @@ -20,19 +20,15 @@ const MINIMUM_PAUSE_RATE: Duration = Duration::from_millis(250); /// A thread for reading and handling input events. #[derive(Debug)] -pub(crate) struct Thread -where - EventProvider: EventReaderFn, - CustomEvent: crate::input::CustomEvent + 'static, +pub(crate) struct Thread +where EventProvider: EventReaderFn { event_provider: Arc, - state: State, + state: State, } -impl Threadable for Thread -where - EventProvider: EventReaderFn, - CustomEvent: crate::input::CustomEvent + Send + Sync + 'static, +impl Threadable for Thread +where EventProvider: EventReaderFn { fn install(&self, installer: &Installer) { let state = self.state(); @@ -74,10 +70,8 @@ where } } -impl Thread -where - EventProvider: EventReaderFn, - CustomEvent: crate::input::CustomEvent + 'static, +impl Thread +where EventProvider: EventReaderFn { /// Create a new instance of a thread. pub(crate) fn new(event_provider: EventProvider) -> Self { @@ -89,7 +83,7 @@ where /// Get a cloned copy of the state of the thread. #[must_use] - pub(crate) fn state(&self) -> State { + pub(crate) fn state(&self) -> State { self.state.clone() } } @@ -101,17 +95,14 @@ mod tests { use super::*; use crate::{ - input::{ - testutil::local::{create_event_reader, TestEvent}, - KeyEvent, - }, + input::{testutil::create_event_reader, KeyEvent}, runtime::{testutils::ThreadableTester, Status}, }; #[test] fn set_pause_resume() { let event_provider = create_event_reader(|| Ok(None)); - let thread: Thread<_, TestEvent> = Thread::new(event_provider); + let thread: Thread<_> = Thread::new(event_provider); let state = thread.state(); thread.pause(); assert!(state.is_paused()); @@ -122,7 +113,7 @@ mod tests { #[test] fn set_end() { let event_provider = create_event_reader(|| Ok(None)); - let thread: Thread<_, TestEvent> = Thread::new(event_provider); + let thread: Thread<_> = Thread::new(event_provider); let state = thread.state(); thread.end(); assert!(state.is_ended()); @@ -136,7 +127,7 @@ mod tests { KeyModifiers::empty(), )))) }); - let thread: Thread<_, TestEvent> = Thread::new(event_provider); + let thread: Thread<_> = Thread::new(event_provider); let state = thread.state(); let tester = ThreadableTester::new(); @@ -158,7 +149,7 @@ mod tests { #[test] fn read_none_event() { let event_provider = create_event_reader(|| Ok(None)); - let thread: Thread<_, TestEvent> = Thread::new(event_provider); + let thread: Thread<_> = Thread::new(event_provider); let state = thread.state(); let tester = ThreadableTester::new(); @@ -173,7 +164,7 @@ mod tests { #[test] fn read_error() { let event_provider = create_event_reader(|| Err(anyhow!("Err"))); - let thread: Thread<_, TestEvent> = Thread::new(event_provider); + let thread: Thread<_> = Thread::new(event_provider); let state = thread.state(); let tester = ThreadableTester::new(); @@ -188,7 +179,7 @@ mod tests { #[test] fn pause_resume() { let event_provider = create_event_reader(|| Ok(None)); - let thread: Thread<_, TestEvent> = Thread::new(event_provider); + let thread: Thread<_> = Thread::new(event_provider); let state = thread.state(); let tester = ThreadableTester::new(); diff --git a/src/input/thread/state.rs b/src/input/thread/state.rs index c3983c2..43fb478 100644 --- a/src/input/thread/state.rs +++ b/src/input/thread/state.rs @@ -17,15 +17,15 @@ const EVENT_POLL_TIMEOUT: Duration = Duration::from_secs(1); /// Input thread state. #[derive(Clone, Debug)] -pub(crate) struct State { +pub(crate) struct State { ended: Arc, - event_queue: Arc>>>, + event_queue: Arc>>, paused: Arc, update_receiver: crossbeam_channel::Receiver<()>, update_sender: crossbeam_channel::Sender<()>, } -impl State { +impl State { pub(crate) fn new() -> Self { let (update_sender, update_receiver) = crossbeam_channel::unbounded(); Self { @@ -65,7 +65,7 @@ impl State { } /// Add an event after existing events. - pub(crate) fn enqueue_event(&self, event: Event) { + pub(crate) fn enqueue_event(&self, event: Event) { let mut events = self.event_queue.lock(); let last_resize_event_maybe = matches!(event, Event::Resize(..)) .then(|| events.back_mut().filter(|e| matches!(*e, &mut Event::Resize(..)))) @@ -81,7 +81,7 @@ impl State { } /// Add an event before existing events. - pub(crate) fn push_event(&self, event: Event) { + pub(crate) fn push_event(&self, event: Event) { let mut events = self.event_queue.lock(); if events.len() >= MAXIMUM_EVENTS { _ = events.pop_back(); @@ -93,7 +93,7 @@ impl State { /// Read an event from the queue. This function will block for a while until an event is /// available. And if no event is available, it will return `Event::None`. #[must_use] - pub(crate) fn read_event(&self) -> Event { + pub(crate) fn read_event(&self) -> Event { // clear existing message since last read while self.update_receiver.try_recv().is_ok() {} loop { @@ -122,9 +122,9 @@ mod tests { }; use super::*; - use crate::input::testutil::local::{Event, TestEvent}; + use crate::input::Event; - fn create_state() -> State { + fn create_state() -> State { State::new() } diff --git a/src/main.rs b/src/main.rs index f65bb57..94cf89f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -127,7 +127,6 @@ mod components; mod config; mod display; mod editor; -mod events; mod exit; mod git; mod help; diff --git a/src/module.rs b/src/module.rs index f0a3d99..c235749 100644 --- a/src/module.rs +++ b/src/module.rs @@ -17,8 +17,7 @@ pub(crate) use self::{ state::State, }; use crate::{ - events::{Event, KeyBindings}, - input::InputOptions, + input::{Event, InputOptions, KeyBindings}, process::Results, view::{RenderContext, ViewData}, }; diff --git a/src/module/module_handler.rs b/src/module/module_handler.rs index 2143fd8..773fc9e 100644 --- a/src/module/module_handler.rs +++ b/src/module/module_handler.rs @@ -1,22 +1,17 @@ use super::State; use crate::{ - events, - events::{AppKeyBindings, Event, MetaEvent}, - input::EventHandler, + input::{Event, EventHandler}, process::Results, view::{RenderContext, ViewData}, }; pub(crate) struct ModuleHandler { - event_handler: EventHandler, + event_handler: EventHandler, module_provider: ModuleProvider, } impl ModuleHandler { - pub(crate) const fn new( - event_handler: EventHandler, - module_provider: ModuleProvider, - ) -> Self { + pub(crate) const fn new(event_handler: EventHandler, module_provider: ModuleProvider) -> Self { Self { event_handler, module_provider, @@ -40,7 +35,7 @@ impl ModuleHandler Option { let module = self.module_provider.get_module(state); diff --git a/src/module/tests.rs b/src/module/tests.rs index dadc104..85aeb5a 100644 --- a/src/module/tests.rs +++ b/src/module/tests.rs @@ -1,8 +1,9 @@ use anyhow::anyhow; use crate::{ + input::testutil::create_test_keybindings, module::{Event, InputOptions, Module, State}, - testutil::{create_test_keybindings, module_test}, + testutil::module_test, }; struct TestModule; diff --git a/src/modules/confirm_abort.rs b/src/modules/confirm_abort.rs index 6e53427..32c1b40 100644 --- a/src/modules/confirm_abort.rs +++ b/src/modules/confirm_abort.rs @@ -4,8 +4,7 @@ use parking_lot::Mutex; use crate::{ components::confirm::{Confirm, Confirmed, INPUT_OPTIONS}, - events::{Event, KeyBindings}, - input::InputOptions, + input::{Event, InputOptions, KeyBindings}, module::{ExitStatus, Module, State}, process::Results, todo_file::TodoFile, @@ -62,8 +61,7 @@ mod tests { use crate::{ assert_rendered_output, assert_results, - events::MetaEvent, - input::KeyCode, + input::{KeyCode, StandardEvent}, process::Artifact, testutil::module_test, view::testutil::AssertRenderOptions, @@ -95,12 +93,12 @@ mod tests { fn handle_event_yes() { module_test( &["pick aaa comment"], - &[Event::from(MetaEvent::Yes)], + &[Event::from(StandardEvent::Yes)], |mut test_context| { let mut module = create_confirm_abort(test_context.take_todo_file()); assert_results!( test_context.handle_event(&mut module), - Artifact::Event(Event::from(MetaEvent::Yes)), + Artifact::Event(Event::from(StandardEvent::Yes)), Artifact::ExitStatus(ExitStatus::Good) ); assert!(module.todo_file.lock().is_empty()); @@ -112,12 +110,12 @@ mod tests { fn handle_event_no() { module_test( &["pick aaa comment"], - &[Event::from(MetaEvent::No)], + &[Event::from(StandardEvent::No)], |mut test_context| { let mut module = create_confirm_abort(test_context.take_todo_file()); assert_results!( test_context.handle_event(&mut module), - Artifact::Event(Event::from(MetaEvent::No)), + Artifact::Event(Event::from(StandardEvent::No)), Artifact::ChangeState(State::List) ); }, diff --git a/src/modules/confirm_rebase.rs b/src/modules/confirm_rebase.rs index efe080b..441c6a3 100644 --- a/src/modules/confirm_rebase.rs +++ b/src/modules/confirm_rebase.rs @@ -1,7 +1,6 @@ use crate::{ components::confirm::{Confirm, Confirmed, INPUT_OPTIONS}, - events::{Event, KeyBindings}, - input::InputOptions, + input::{Event, InputOptions, KeyBindings}, module::{ExitStatus, Module, State}, process::Results, view::{RenderContext, ViewData}, @@ -53,8 +52,7 @@ mod tests { use crate::{ assert_rendered_output, assert_results, - events::MetaEvent, - input::KeyCode, + input::{KeyCode, StandardEvent}, process::Artifact, testutil::module_test, }; @@ -82,12 +80,12 @@ mod tests { fn handle_event_yes() { module_test( &["pick aaa comment"], - &[Event::from(MetaEvent::Yes)], + &[Event::from(StandardEvent::Yes)], |mut test_context| { let mut module = create_confirm_rebase(); assert_results!( test_context.handle_event(&mut module), - Artifact::Event(Event::from(MetaEvent::Yes)), + Artifact::Event(Event::from(StandardEvent::Yes)), Artifact::ExitStatus(ExitStatus::Good) ); }, @@ -98,12 +96,12 @@ mod tests { fn handle_event_no() { module_test( &["pick aaa comment"], - &[Event::from(MetaEvent::No)], + &[Event::from(StandardEvent::No)], |mut test_context| { let mut module = create_confirm_rebase(); assert_results!( test_context.handle_event(&mut module), - Artifact::Event(Event::from(MetaEvent::No)), + Artifact::Event(Event::from(StandardEvent::No)), Artifact::ChangeState(State::List) ); }, diff --git a/src/modules/error.rs b/src/modules/error.rs index 9e990b6..400e5ef 100644 --- a/src/modules/error.rs +++ b/src/modules/error.rs @@ -3,8 +3,7 @@ use lazy_static::lazy_static; use crate::{ display::DisplayColor, - events::Event, - input::InputOptions, + input::{Event, InputOptions}, module::{Module, State}, process::Results, util::handle_view_data_scroll, diff --git a/src/modules/external_editor.rs b/src/modules/external_editor.rs index a2aab2f..f708f34 100644 --- a/src/modules/external_editor.rs +++ b/src/modules/external_editor.rs @@ -14,8 +14,7 @@ use parking_lot::Mutex; use self::{action::Action, argument_tokenizer::tokenize, external_editor_state::ExternalEditorState}; use crate::{ components::choice::{Choice, INPUT_OPTIONS as CHOICE_INPUT_OPTIONS}, - events::{Event, MetaEvent}, - input::InputOptions, + input::{Event, InputOptions, StandardEvent}, module::{ExitStatus, Module, State}, process::Results, todo_file::{Line, TodoFile}, @@ -98,7 +97,7 @@ impl Module for ExternalEditor { match self.state { ExternalEditorState::Active => { match event { - Event::MetaEvent(MetaEvent::ExternalCommandSuccess) => { + Event::Standard(StandardEvent::ExternalCommandSuccess) => { let mut todo_file = self.todo_file.lock(); let result = todo_file.load_file(); let state = match result { @@ -120,7 +119,7 @@ impl Module for ExternalEditor { self.set_state(&mut results, new_state); } }, - Event::MetaEvent(MetaEvent::ExternalCommandError) => { + Event::Standard(StandardEvent::ExternalCommandError) => { self.set_state( &mut results, ExternalEditorState::Error(anyhow!("Editor returned a non-zero exit status")), diff --git a/src/modules/external_editor/tests.rs b/src/modules/external_editor/tests.rs index 0313cee..f6eb52c 100644 --- a/src/modules/external_editor/tests.rs +++ b/src/modules/external_editor/tests.rs @@ -4,8 +4,7 @@ use super::*; use crate::{ assert_rendered_output, assert_results, - events::Event, - input::KeyCode, + input::{Event, KeyCode}, module::ExitStatus, process::Artifact, testutil::module_test, @@ -125,7 +124,7 @@ fn deactivate() { fn edit_success() { module_test( &["pick aaa comment"], - &[Event::from(MetaEvent::ExternalCommandSuccess)], + &[Event::from(StandardEvent::ExternalCommandSuccess)], |mut test_context| { let mut module = create_external_editor("editor", test_context.take_todo_file()); _ = test_context.activate(&mut module, State::List); @@ -133,7 +132,7 @@ fn edit_success() { assert_rendered_output!(view_data, "{TITLE}", "{LEADING}", "Editing..."); assert_results!( test_context.handle_event(&mut module), - Artifact::Event(Event::from(MetaEvent::ExternalCommandSuccess)), + Artifact::Event(Event::from(StandardEvent::ExternalCommandSuccess)), Artifact::ChangeState(State::List) ); assert_external_editor_state_eq!(module.state, ExternalEditorState::Active); @@ -145,7 +144,7 @@ fn edit_success() { fn empty_edit_error() { module_test( &["pick aaa comment"], - &[Event::from('1'), Event::from(MetaEvent::ExternalCommandSuccess)], + &[Event::from('1'), Event::from(StandardEvent::ExternalCommandSuccess)], |mut test_context| { let mut module = create_external_editor("editor", test_context.take_todo_file()); _ = test_context.activate(&mut module, State::List); @@ -156,7 +155,7 @@ fn empty_edit_error() { _ = test_context.handle_event(&mut module); assert_results!( test_context.handle_event(&mut module), - Artifact::Event(Event::from(MetaEvent::ExternalCommandSuccess)) + Artifact::Event(Event::from(StandardEvent::ExternalCommandSuccess)) ); assert_external_editor_state_eq!(module.state, ExternalEditorState::Empty); let view_data = test_context.build_view_data(&mut module); @@ -277,13 +276,13 @@ fn no_editor_set() { fn editor_non_zero_exit() { module_test( &["pick aaa comment"], - &[Event::from(MetaEvent::ExternalCommandError)], + &[Event::from(StandardEvent::ExternalCommandError)], |mut test_context| { let mut module = create_external_editor("editor", test_context.take_todo_file()); _ = test_context.activate(&mut module, State::List); assert_results!( test_context.handle_event(&mut module), - Artifact::Event(Event::from(MetaEvent::ExternalCommandError)) + Artifact::Event(Event::from(StandardEvent::ExternalCommandError)) ); assert_external_editor_state_eq!( module.state, @@ -312,7 +311,10 @@ fn editor_non_zero_exit() { fn editor_reload_error() { module_test( &["pick aaa comment"], - &[Event::from(KeyCode::Up), Event::from(MetaEvent::ExternalCommandSuccess)], + &[ + Event::from(KeyCode::Up), + Event::from(StandardEvent::ExternalCommandSuccess), + ], |mut test_context| { let todo_file = test_context.take_todo_file(); let path = todo_file.get_filepath().to_path_buf(); @@ -323,7 +325,7 @@ fn editor_reload_error() { _ = test_context.handle_event(&mut module); assert_results!( test_context.handle_event(&mut module), - Artifact::Event(Event::from(MetaEvent::ExternalCommandSuccess)) + Artifact::Event(Event::from(StandardEvent::ExternalCommandSuccess)) ); assert_external_editor_state_eq!( module.state, diff --git a/src/modules/insert.rs b/src/modules/insert.rs index e6b5121..f4bab79 100644 --- a/src/modules/insert.rs +++ b/src/modules/insert.rs @@ -15,8 +15,7 @@ use crate::{ edit::{Edit, INPUT_OPTIONS as EDIT_INPUT_OPTIONS}, }, display::DisplayColor, - events::Event, - input::InputOptions, + input::{Event, InputOptions}, module::{Module, State}, process::Results, todo_file::{Line, TodoFile}, diff --git a/src/modules/insert/tests.rs b/src/modules/insert/tests.rs index 05808e4..e8f6161 100644 --- a/src/modules/insert/tests.rs +++ b/src/modules/insert/tests.rs @@ -2,8 +2,7 @@ use super::*; use crate::{ assert_rendered_output, assert_results, - events::Event, - input::KeyCode, + input::{Event, KeyCode}, process::Artifact, testutil::module_test, }; diff --git a/src/modules/list.rs b/src/modules/list.rs index ed8e9e3..ea397ad 100644 --- a/src/modules/list.rs +++ b/src/modules/list.rs @@ -22,8 +22,7 @@ use crate::{ }, config::Config, display::DisplayColor, - events::{Event, KeyBindings, MetaEvent}, - input::{InputOptions, MouseEventKind, StandardEvent}, + input::{Event, InputOptions, KeyBindings, MouseEventKind, StandardEvent}, module::{ExitStatus, Module, State}, modules::list::utils::get_line_action_maximum_width, process::Results, @@ -503,11 +502,11 @@ impl List { if let Some(action) = self.selected_line_action { if action == Action::Fixup { match event { - e if key_bindings.custom.fixup_keep_message.contains(&e) => { - return Event::from(MetaEven