summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Oram <dev@mitmaro.ca>2024-02-12 10:33:24 -0330
committerTim Oram <dev@mitmaro.ca>2024-02-15 20:27:06 -0330
commit5ae7493431d7a1a127309e3f9acb0f7dab04983b (patch)
tree0f55fdfb4cd4db7e82d163ac06c698b1fb08af41
parentad0ff4dd1f08de53e6c182908e9f1d40f4869783 (diff)
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.
-rw-r--r--src/application.rs19
-rw-r--r--src/components/choice.rs3
-rw-r--r--src/components/confirm.rs19
-rw-r--r--src/components/confirm/tests.rs15
-rw-r--r--src/components/edit.rs3
-rw-r--r--src/components/help.rs3
-rw-r--r--src/components/search_bar.rs3
-rw-r--r--src/components/shared/editable_line.rs3
-rw-r--r--src/events.rs8
-rw-r--r--src/events/app_key_bindings.rs116
-rw-r--r--src/events/meta_event.rs83
-rw-r--r--src/input.rs6
-rw-r--r--src/input/custom_event.rs2
-rw-r--r--src/input/custom_key_binding.rs5
-rw-r--r--src/input/event.rs19
-rw-r--r--src/input/event_handler.rs44
-rw-r--r--src/input/key_bindings.rs149
-rw-r--r--src/input/standard_event.rs70
-rw-r--r--src/input/testutil.rs102
-rw-r--r--src/input/thread.rs39
-rw-r--r--src/input/thread/state.rs16
-rw-r--r--src/main.rs1
-rw-r--r--src/module.rs3
-rw-r--r--src/module/module_handler.rs13
-rw-r--r--src/module/tests.rs3
-rw-r--r--src/modules/confirm_abort.rs14
-rw-r--r--src/modules/confirm_rebase.rs14
-rw-r--r--src/modules/error.rs3
-rw-r--r--src/modules/external_editor.rs7
-rw-r--r--src/modules/external_editor/tests.rs22
-rw-r--r--src/modules/insert.rs3
-rw-r--r--src/modules/insert/tests.rs3
-rw-r--r--src/modules/list.rs140
-rw-r--r--src/modules/list/tests/abort_and_rebase.rs42
-rw-r--r--src/modules/list/tests/change_action.rs72
-rw-r--r--src/modules/list/tests/edit_mode.rs66
-rw-r--r--src/modules/list/tests/external_editor.rs12
-rw-r--r--src/modules/list/tests/insert_line.rs4
-rw-r--r--src/modules/list/tests/movement.rs72
-rw-r--r--src/modules/list/tests/normal_mode.rs6
-rw-r--r--src/modules/list/tests/read_event.rs70
-rw-r--r--src/modules/list/tests/remove_lines.rs60
-rw-r--r--src/modules/list/tests/render.rs2
-rw-r--r--src/modules/list/tests/search.rs26
-rw-r--r--src/modules/list/tests/show_commit.rs12
-rw-r--r--src/modules/list/tests/swap_lines.rs112
-rw-r--r--src/modules/list/tests/toggle_break.rs8
-rw-r--r--src/modules/list/tests/toggle_option.rs6
-rw-r--r--src/modules/list/tests/undo_redo.rs44
-rw-r--r--src/modules/list/tests/visual_mode.rs66
-rw-r--r--src/modules/show_commit.rs8
-rw-r--r--src/modules/show_commit/tests.rs6
-rw-r--r--src/modules/window_size_error.rs3
-rw-r--r--src/process.rs14
-rw-r--r--src/process/artifact.rs2
-rw-r--r--src/process/results.rs2
-rw-r--r--src/process/tests.rs9
-rw-r--r--src/process/thread.rs3
-rw-r--r--src/testutil.rs6
-rw-r--r--src/testutil/create_event_reader.rs13
-rw-r--r--src/testutil/create_test_keybindings.rs44
-rw-r--r--src/testutil/module_test.rs5
-rw-r--r--src/testutil/process_test.rs6
-rw-r--r--src/testutil/read_event_test.rs2
-rw-r--r--src/testutil/test_module_provider.rs3
-rw-r--r--src/testutil/with_event_handler.rs11
-rw-r--r--src/util.rs2
67 files changed, 778 insertions, 994 deletions
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<Box<dyn Threadable>> = 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::<TestModuleProvider<DefaultTestModule>>::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<AppKeyBindings, MetaEvent>;
-pub(crate) type Event = crate::input::Event<MetaEvent>;
-pub(crate) type State = crate::input::State<MetaEvent>;
-pub(crate) type Thread<EventProvider> = crate::input::Thread<EventProvider, MetaEvent>;
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<Event> {
- crate::input::map_keybindings::<MetaEvent>(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<Event>,
- /// Key bindings for the break action.
- pub(crate) action_break: Vec<Event>,
- /// Key bindings for the drop action.
- pub(crate) action_drop: Vec<Event>,
- /// Key bindings for the edit action.
- pub(crate) action_edit: Vec<Event>,
- /// Key bindings for the fixup action.
- pub(crate) action_fixup: Vec<Event>,
- /// Key bindings for the pick action.
- pub(crate) action_pick: Vec<Event>,
- /// Key bindings for the reword action.
- pub(crate) action_reword: Vec<Event>,
- /// Key bindings for the squash action.
- pub(crate) action_squash: Vec<Event>,
- /// Key bindings for positive confirmation.
- pub(crate) confirm_yes: Vec<Event>,
- /// Key bindings for editing.
- pub(crate) edit: Vec<Event>,
- /// Key bindings for forcing an abort.
- pub(crate) force_abort: Vec<Event>,
- /// Key bindings for forcing a rebase.
- pub(crate) force_rebase: Vec<Event>,
- /// Key bindings for inserting a line.
- pub(crate) insert_line: Vec<Event>,
- /// Key bindings for moving down.
- pub(crate) move_down: Vec<Event>,
- /// Key bindings for moving down a step.
- pub(crate) move_down_step: Vec<Event>,
- /// Key bindings for moving to the end.
- pub(crate) move_end: Vec<Event>,
- /// Key bindings for moving to the start.
- pub(crate) move_home: Vec<Event>,
- /// Key bindings for moving to the left.
- pub(crate) move_left: Vec<Event>,
- /// Key bindings for moving to the right.
- pub(crate) move_right: Vec<Event>,
- /// Key bindings for moving the selection down.
- pub(crate) move_selection_down: Vec<Event>,
- /// Key bindings for moving the selection up.
- pub(crate) move_selection_up: Vec<Event>,
- /// Key bindings for moving up.
- pub(crate) move_up: Vec<Event>,
- /// Key bindings for moving up a step.
- pub(crate) move_up_step: Vec<Event>,
- /// Key bindings for opening the external editor.
- pub(crate) open_in_external_editor: Vec<Event>,
- /// Key bindings for rebasing.
- pub(crate) rebase: Vec<Event>,
- /// Key bindings for removing a line.
- pub(crate) remove_line: Vec<Event>,
- /// Key bindings for showing a commit.
- pub(crate) show_commit: Vec<Event>,
- /// Key bindings for showing a diff.
- pub(crate) show_diff: Vec<Event>,
- /// Key bindings for toggling visual mode.
- pub(crate) toggle_visual_mode: Vec<Event>,
- /// Key bindings for the fixup specific action to toggle the c option.
- pub(crate) fixup_keep_message: Vec<Event>,
- /// Key biding for the fixup specific action to toggle the C option.
- pub(crate) fixup_keep_message_with_editor: Vec<Event>,
-}
-
-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<MetaEvent> 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_even