From 0048d71b743ce299001150a3f6f0ac14c8e06386 Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Mon, 17 Mar 2025 22:02:15 -0600 Subject: [PATCH] feat: Support alternative keymappings for all keys, featuring hjkl movements --- src/app/key_binding.rs | 62 ++++++- src/app/key_binding_tests.rs | 2 +- src/handlers/mod.rs | 47 ++--- .../blocklist/blocklist_handler_tests.rs | 17 ++ src/handlers/radarr_handlers/blocklist/mod.rs | 15 +- .../collections/collection_details_handler.rs | 9 +- .../collection_details_handler_tests.rs | 17 ++ .../collections/collections_handler_tests.rs | 16 ++ .../collections/edit_collection_handler.rs | 9 +- .../edit_collection_handler_tests.rs | 21 ++- .../radarr_handlers/collections/mod.rs | 15 +- .../downloads/downloads_handler_tests.rs | 17 ++ src/handlers/radarr_handlers/downloads/mod.rs | 15 +- .../indexers/edit_indexer_handler.rs | 11 +- .../indexers/edit_indexer_handler_tests.rs | 37 ++-- .../indexers/edit_indexer_settings_handler.rs | 11 +- .../edit_indexer_settings_handler_tests.rs | 21 ++- .../indexers/indexers_handler_tests.rs | 16 ++ src/handlers/radarr_handlers/indexers/mod.rs | 17 +- .../indexers/test_all_indexers_handler.rs | 4 + .../test_all_indexers_handler_tests.rs | 17 ++ .../library/add_movie_handler.rs | 11 +- .../library/add_movie_handler_tests.rs | 24 ++- .../library/delete_movie_handler.rs | 8 +- .../library/delete_movie_handler_tests.rs | 17 ++ .../library/edit_movie_handler.rs | 9 +- .../library/edit_movie_handler_tests.rs | 25 ++- .../library/library_handler_tests.rs | 16 ++ src/handlers/radarr_handlers/library/mod.rs | 17 +- .../library/movie_details_handler.rs | 27 +-- .../library/movie_details_handler_tests.rs | 16 ++ src/handlers/radarr_handlers/mod.rs | 11 +- .../radarr_handlers/radarr_handler_tests.rs | 86 +++++++++ .../radarr_handlers/root_folders/mod.rs | 15 +- .../root_folders_handler_tests.rs | 21 ++- src/handlers/radarr_handlers/system/mod.rs | 16 +- .../system/system_details_handler.rs | 15 +- .../system/system_details_handler_tests.rs | 17 ++ .../system/system_handler_tests.rs | 16 ++ .../blocklist/blocklist_handler_tests.rs | 17 ++ src/handlers/sonarr_handlers/blocklist/mod.rs | 15 +- .../downloads/downloads_handler_tests.rs | 17 ++ src/handlers/sonarr_handlers/downloads/mod.rs | 15 +- .../history/history_handler_tests.rs | 17 ++ src/handlers/sonarr_handlers/history/mod.rs | 9 +- .../indexers/edit_indexer_handler.rs | 11 +- .../indexers/edit_indexer_handler_tests.rs | 37 ++-- .../indexers/edit_indexer_settings_handler.rs | 9 +- .../edit_indexer_settings_handler_tests.rs | 17 ++ .../indexers/indexers_handler_tests.rs | 16 ++ src/handlers/sonarr_handlers/indexers/mod.rs | 17 +- .../indexers/test_all_indexers_handler.rs | 4 + .../test_all_indexers_handler_tests.rs | 17 ++ .../library/add_series_handler.rs | 11 +- .../library/add_series_handler_tests.rs | 25 ++- .../library/delete_series_handler.rs | 9 +- .../library/delete_series_handler_tests.rs | 17 ++ .../library/edit_series_handler.rs | 9 +- .../library/edit_series_handler_tests.rs | 25 ++- .../library/episode_details_handler.rs | 23 ++- .../library/episode_details_handler_tests.rs | 16 ++ .../library/library_handler_tests.rs | 16 ++ src/handlers/sonarr_handlers/library/mod.rs | 16 +- .../library/season_details_handler.rs | 27 ++- .../library/season_details_handler_tests.rs | 16 ++ .../library/series_details_handler.rs | 31 ++-- .../library/series_details_handler_tests.rs | 16 ++ src/handlers/sonarr_handlers/mod.rs | 12 +- .../sonarr_handlers/root_folders/mod.rs | 15 +- .../root_folders_handler_tests.rs | 21 ++- .../sonarr_handlers/sonarr_handler_tests.rs | 167 ++++++++++++++---- src/handlers/sonarr_handlers/system/mod.rs | 16 +- .../system/system_details_handler.rs | 15 +- .../system/system_details_handler_tests.rs | 17 ++ .../system/system_handler_tests.rs | 16 ++ src/handlers/table_handler.rs | 22 +-- src/handlers/table_handler_tests.rs | 12 +- 77 files changed, 1247 insertions(+), 304 deletions(-) diff --git a/src/app/key_binding.rs b/src/app/key_binding.rs index f939a6d..f032b63 100644 --- a/src/app/key_binding.rs +++ b/src/app/key_binding.rs @@ -44,128 +44,188 @@ generate_keybindings! { #[derive(Clone, Copy, Eq, PartialEq, Debug)] pub struct KeyBinding { pub key: Key, + pub alt: Option, pub desc: &'static str, } pub const DEFAULT_KEYBINDINGS: KeyBindings = KeyBindings { add: KeyBinding { key: Key::Char('a'), + alt: None, desc: "add", }, up: KeyBinding { key: Key::Up, + alt: Some(Key::Char('k')), desc: "up", }, down: KeyBinding { key: Key::Down, + alt: Some(Key::Char('j')), desc: "down", }, left: KeyBinding { key: Key::Left, + alt: Some(Key::Char('h')), desc: "left", }, right: KeyBinding { key: Key::Right, + alt: Some(Key::Char('l')), desc: "right", }, backspace: KeyBinding { key: Key::Backspace, + alt: None, desc: "backspace", }, next_servarr: KeyBinding { key: Key::Tab, + alt: None, desc: "next servarr", }, previous_servarr: KeyBinding { key: Key::BackTab, + alt: None, desc: "previous servarr", }, clear: KeyBinding { key: Key::Char('c'), + alt: None, desc: "clear", }, auto_search: KeyBinding { key: Key::Char('S'), + alt: None, desc: "auto search", }, search: KeyBinding { key: Key::Char('s'), + alt: None, desc: "search", }, settings: KeyBinding { key: Key::Char('S'), + alt: None, desc: "settings", }, filter: KeyBinding { key: Key::Char('f'), + alt: None, desc: "filter", }, sort: KeyBinding { key: Key::Char('o'), + alt: None, desc: "sort", }, edit: KeyBinding { key: Key::Char('e'), + alt: None, desc: "edit", }, events: KeyBinding { key: Key::Char('e'), + alt: None, desc: "events", }, logs: KeyBinding { - key: Key::Char('l'), + key: Key::Char('L'), + alt: None, desc: "logs", }, tasks: KeyBinding { key: Key::Char('t'), + alt: None, desc: "tasks", }, test: KeyBinding { key: Key::Char('t'), + alt: None, desc: "test", }, test_all: KeyBinding { key: Key::Char('T'), + alt: None, desc: "test all", }, toggle_monitoring: KeyBinding { key: Key::Char('m'), + alt: None, desc: "toggle monitoring", }, refresh: KeyBinding { key: Key::Ctrl('r'), + alt: None, desc: "refresh", }, update: KeyBinding { key: Key::Char('u'), + alt: None, desc: "update", }, home: KeyBinding { key: Key::Home, + alt: None, desc: "home", }, end: KeyBinding { key: Key::End, + alt: None, desc: "end", }, delete: KeyBinding { key: Key::Delete, + alt: None, desc: "delete", }, submit: KeyBinding { key: Key::Enter, + alt: None, desc: "submit", }, confirm: KeyBinding { key: Key::Ctrl('s'), + alt: None, desc: "submit", }, quit: KeyBinding { key: Key::Char('q'), + alt: None, desc: "quit", }, esc: KeyBinding { key: Key::Esc, + alt: None, desc: "close", }, }; + +#[macro_export] +macro_rules! matches_key { + ($binding:ident, $key:expr) => { + $crate::app::key_binding::DEFAULT_KEYBINDINGS.$binding.key == $key + || ($crate::app::key_binding::DEFAULT_KEYBINDINGS + .$binding + .alt + .is_some() + && $crate::app::key_binding::DEFAULT_KEYBINDINGS + .$binding + .alt + .unwrap() + == $key) + }; + ($binding:ident, $key:expr, $ignore_alt_navigation:expr) => { + $crate::app::key_binding::DEFAULT_KEYBINDINGS.$binding.key == $key + || !$ignore_alt_navigation + && ($crate::app::key_binding::DEFAULT_KEYBINDINGS + .$binding + .alt + .is_some() + && $crate::app::key_binding::DEFAULT_KEYBINDINGS + .$binding + .alt + .unwrap() + == $key) + }; +} diff --git a/src/app/key_binding_tests.rs b/src/app/key_binding_tests.rs index c78c210..cc34a5c 100644 --- a/src/app/key_binding_tests.rs +++ b/src/app/key_binding_tests.rs @@ -23,7 +23,7 @@ mod test { #[case(DEFAULT_KEYBINDINGS.sort, Key::Char('o'), "sort")] #[case(DEFAULT_KEYBINDINGS.edit, Key::Char('e'), "edit")] #[case(DEFAULT_KEYBINDINGS.events, Key::Char('e'), "events")] - #[case(DEFAULT_KEYBINDINGS.logs, Key::Char('l'), "logs")] + #[case(DEFAULT_KEYBINDINGS.logs, Key::Char('L'), "logs")] #[case(DEFAULT_KEYBINDINGS.tasks, Key::Char('t'), "tasks")] #[case(DEFAULT_KEYBINDINGS.test, Key::Char('t'), "test")] #[case(DEFAULT_KEYBINDINGS.test_all, Key::Char('T'), "test all")] diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 518d01b..c359717 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -1,9 +1,9 @@ use radarr_handlers::RadarrHandler; use sonarr_handlers::SonarrHandler; -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; +use crate::matches_key; use crate::models::{HorizontallyScrollableText, Route}; mod radarr_handlers; @@ -22,40 +22,42 @@ pub trait KeyEventHandler<'a, 'b, T: Into + Copy> { fn handle_key_event(&mut self) { let key = self.get_key(); match key { - _ if key == DEFAULT_KEYBINDINGS.up.key => { + _ if matches_key!(up, key, self.ignore_alt_navigation()) => { if self.is_ready() { self.handle_scroll_up(); } } - _ if key == DEFAULT_KEYBINDINGS.down.key => { + _ if matches_key!(down, key, self.ignore_alt_navigation()) => { if self.is_ready() { self.handle_scroll_down(); } } - _ if key == DEFAULT_KEYBINDINGS.home.key => { + _ if matches_key!(home, key) => { if self.is_ready() { self.handle_home(); } } - _ if key == DEFAULT_KEYBINDINGS.end.key => { + _ if matches_key!(end, key) => { if self.is_ready() { self.handle_end(); } } - _ if key == DEFAULT_KEYBINDINGS.delete.key => { + _ if matches_key!(delete, key) => { if self.is_ready() { self.handle_delete(); } } - _ if key == DEFAULT_KEYBINDINGS.left.key || key == DEFAULT_KEYBINDINGS.right.key => { + _ if matches_key!(left, key, self.ignore_alt_navigation()) + || matches_key!(right, key, self.ignore_alt_navigation()) => + { self.handle_left_right_action() } - _ if key == DEFAULT_KEYBINDINGS.submit.key => { + _ if matches_key!(submit, key) => { if self.is_ready() { self.handle_submit(); } } - _ if key == DEFAULT_KEYBINDINGS.esc.key => self.handle_esc(), + _ if matches_key!(esc, key) => self.handle_esc(), _ => { if self.is_ready() { self.handle_char_key_event(); @@ -71,6 +73,7 @@ pub trait KeyEventHandler<'a, 'b, T: Into + Copy> { fn accepts(active_block: T) -> bool; fn new(key: Key, app: &'a mut App<'b>, active_block: T, context: Option) -> Self; fn get_key(&self) -> Key; + fn ignore_alt_navigation(&self) -> bool; fn is_ready(&self) -> bool; fn handle_scroll_up(&mut self); fn handle_scroll_down(&mut self); @@ -84,12 +87,12 @@ pub trait KeyEventHandler<'a, 'b, T: Into + Copy> { } pub fn handle_events(key: Key, app: &mut App<'_>) { - if key == DEFAULT_KEYBINDINGS.next_servarr.key { + if matches_key!(next_servarr, key) { app.reset(); app.server_tabs.next(); app.pop_and_push_navigation_stack(app.server_tabs.get_active_route()); app.cancellation_token.cancel(); - } else if key == DEFAULT_KEYBINDINGS.previous_servarr.key { + } else if matches_key!(previous_servarr, key) { app.reset(); app.server_tabs.previous(); app.pop_and_push_navigation_stack(app.server_tabs.get_active_route()); @@ -115,17 +118,15 @@ fn handle_clear_errors(app: &mut App<'_>) { fn handle_prompt_toggle(app: &mut App<'_>, key: Key) { match key { - _ if key == DEFAULT_KEYBINDINGS.left.key || key == DEFAULT_KEYBINDINGS.right.key => { - match app.get_current_route() { - Route::Radarr(_, _) => { - app.data.radarr_data.prompt_confirm = !app.data.radarr_data.prompt_confirm - } - Route::Sonarr(_, _) => { - app.data.sonarr_data.prompt_confirm = !app.data.sonarr_data.prompt_confirm - } - _ => (), + _ if matches_key!(left, key) || matches_key!(right, key) => match app.get_current_route() { + Route::Radarr(_, _) => { + app.data.radarr_data.prompt_confirm = !app.data.radarr_data.prompt_confirm } - } + Route::Sonarr(_, _) => { + app.data.sonarr_data.prompt_confirm = !app.data.sonarr_data.prompt_confirm + } + _ => (), + }, _ => (), } } @@ -149,7 +150,7 @@ macro_rules! handle_text_box_left_right_keys { macro_rules! handle_text_box_keys { ($self:expr, $key:expr, $input:expr) => { match $self.key { - _ if $key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.backspace.key => { + _ if $crate::matches_key!(backspace, $key) => { $input.pop(); } Key::Char(character) => { @@ -165,7 +166,7 @@ macro_rules! handle_prompt_left_right_keys { ($self:expr, $confirm_prompt:expr, $data:ident) => { if $self.app.data.$data.selected_block.get_active_block() == $confirm_prompt { handle_prompt_toggle($self.app, $self.key); - } else if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.left.key { + } else if $crate::matches_key!(left, $self.key) { $self.app.data.$data.selected_block.left(); } else { $self.app.data.$data.selected_block.right(); diff --git a/src/handlers/radarr_handlers/blocklist/blocklist_handler_tests.rs b/src/handlers/radarr_handlers/blocklist/blocklist_handler_tests.rs index d65f467..9389285 100644 --- a/src/handlers/radarr_handlers/blocklist/blocklist_handler_tests.rs +++ b/src/handlers/radarr_handlers/blocklist/blocklist_handler_tests.rs @@ -4,6 +4,7 @@ mod tests { use chrono::DateTime; use pretty_assertions::{assert_eq, assert_str_eq}; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -541,6 +542,22 @@ mod tests { }) } + #[rstest] + fn test_blocklist_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = BlocklistHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_extract_blocklist_item_id() { let mut app = App::test_default(); diff --git a/src/handlers/radarr_handlers/blocklist/mod.rs b/src/handlers/radarr_handlers/blocklist/mod.rs index 9dee67a..4202814 100644 --- a/src/handlers/radarr_handlers/blocklist/mod.rs +++ b/src/handlers/radarr_handlers/blocklist/mod.rs @@ -1,7 +1,5 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; -use crate::handle_table_events; use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys; use crate::handlers::table_handler::TableHandlingConfig; use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler}; @@ -9,6 +7,7 @@ use crate::models::radarr_models::BlocklistItem; use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, BLOCKLIST_BLOCKS}; use crate::models::stateful_table::SortOption; use crate::network::radarr_network::RadarrEvent; +use crate::{handle_table_events, matches_key}; #[cfg(test)] #[path = "blocklist_handler_tests.rs"] @@ -51,6 +50,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for BlocklistHandler<'a, BLOCKLIST_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -143,10 +146,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for BlocklistHandler<'a, let key = self.key; match self.active_radarr_block { ActiveRadarrBlock::Blocklist => match self.key { - _ if key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, key) => { self.app.should_refresh = true; } - _ if key == DEFAULT_KEYBINDINGS.clear.key => { + _ if matches_key!(clear, key) => { self .app .push_navigation_stack(ActiveRadarrBlock::BlocklistClearAllItemsPrompt.into()); @@ -154,7 +157,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for BlocklistHandler<'a, _ => (), }, ActiveRadarrBlock::DeleteBlocklistItemPrompt => { - if key == DEFAULT_KEYBINDINGS.confirm.key { + if matches_key!(confirm, key) { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::DeleteBlocklistItem( self.extract_blocklist_item_id(), @@ -164,7 +167,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for BlocklistHandler<'a, } } ActiveRadarrBlock::BlocklistClearAllItemsPrompt => { - if key == DEFAULT_KEYBINDINGS.confirm.key { + if matches_key!(confirm, key) { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::ClearBlocklist); diff --git a/src/handlers/radarr_handlers/collections/collection_details_handler.rs b/src/handlers/radarr_handlers/collections/collection_details_handler.rs index 4780ee6..bf2f8ae 100644 --- a/src/handlers/radarr_handlers/collections/collection_details_handler.rs +++ b/src/handlers/radarr_handlers/collections/collection_details_handler.rs @@ -1,7 +1,5 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; -use crate::handle_table_events; use crate::handlers::table_handler::TableHandlingConfig; use crate::handlers::KeyEventHandler; use crate::models::radarr_models::CollectionMovie; @@ -11,6 +9,7 @@ use crate::models::servarr_data::radarr::radarr_data::{ }; use crate::models::stateful_table::StatefulTable; use crate::models::BlockSelectionState; +use crate::{handle_table_events, matches_key}; #[cfg(test)] #[path = "collection_details_handler_tests.rs"] @@ -46,6 +45,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionDetailsHan COLLECTION_DETAILS_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -130,7 +133,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionDetailsHan fn handle_char_key_event(&mut self) { if self.active_radarr_block == ActiveRadarrBlock::CollectionDetails - && self.key == DEFAULT_KEYBINDINGS.edit.key + && matches_key!(edit, self.key) { self.app.push_navigation_stack( ( diff --git a/src/handlers/radarr_handlers/collections/collection_details_handler_tests.rs b/src/handlers/radarr_handlers/collections/collection_details_handler_tests.rs index 3d016da..745b3bb 100644 --- a/src/handlers/radarr_handlers/collections/collection_details_handler_tests.rs +++ b/src/handlers/radarr_handlers/collections/collection_details_handler_tests.rs @@ -1,6 +1,7 @@ #[cfg(test)] mod tests { use pretty_assertions::assert_str_eq; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -278,6 +279,22 @@ mod tests { }); } + #[rstest] + fn test_collection_details_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = CollectionDetailsHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_collection_details_handler_not_ready_when_loading() { let mut app = App::test_default(); diff --git a/src/handlers/radarr_handlers/collections/collections_handler_tests.rs b/src/handlers/radarr_handlers/collections/collections_handler_tests.rs index 7fd2179..9701226 100644 --- a/src/handlers/radarr_handlers/collections/collections_handler_tests.rs +++ b/src/handlers/radarr_handlers/collections/collections_handler_tests.rs @@ -589,6 +589,22 @@ mod tests { }); } + #[rstest] + fn test_collections_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = CollectionsHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_collections_handler_not_ready_when_loading() { let mut app = App::test_default(); diff --git a/src/handlers/radarr_handlers/collections/edit_collection_handler.rs b/src/handlers/radarr_handlers/collections/edit_collection_handler.rs index 04e3555..6936014 100644 --- a/src/handlers/radarr_handlers/collections/edit_collection_handler.rs +++ b/src/handlers/radarr_handlers/collections/edit_collection_handler.rs @@ -1,4 +1,3 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; use crate::handlers::{handle_prompt_toggle, KeyEventHandler}; @@ -7,7 +6,7 @@ use crate::models::servarr_data::radarr::modals::EditCollectionModal; use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, EDIT_COLLECTION_BLOCKS}; use crate::models::Scrollable; use crate::network::radarr_network::RadarrEvent; -use crate::{handle_text_box_keys, handle_text_box_left_right_keys}; +use crate::{handle_text_box_keys, handle_text_box_left_right_keys, matches_key}; #[cfg(test)] #[path = "edit_collection_handler_tests.rs"] @@ -69,6 +68,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for EditCollectionHandle EDIT_COLLECTION_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -354,7 +357,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for EditCollectionHandle ActiveRadarrBlock::EditCollectionPrompt => { if self.app.data.radarr_data.selected_block.get_active_block() == ActiveRadarrBlock::EditCollectionConfirmPrompt - && key == DEFAULT_KEYBINDINGS.confirm.key + && matches_key!(confirm, key) { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::EditCollection( diff --git a/src/handlers/radarr_handlers/collections/edit_collection_handler_tests.rs b/src/handlers/radarr_handlers/collections/edit_collection_handler_tests.rs index f76f831..5526ea8 100644 --- a/src/handlers/radarr_handlers/collections/edit_collection_handler_tests.rs +++ b/src/handlers/radarr_handlers/collections/edit_collection_handler_tests.rs @@ -2,6 +2,7 @@ mod tests { use bimap::BiMap; use pretty_assertions::assert_str_eq; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -926,7 +927,7 @@ mod tests { app.data.radarr_data.edit_collection_modal = Some(EditCollectionModal::default()); EditCollectionHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveRadarrBlock::EditCollectionRootFolderPathInput, None, @@ -942,7 +943,7 @@ mod tests { .unwrap() .path .text, - "h" + "a" ); } @@ -1019,6 +1020,22 @@ mod tests { }); } + #[rstest] + fn test_edit_collection_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = EditCollectionHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_build_edit_collection_params() { let mut app = App::test_default(); diff --git a/src/handlers/radarr_handlers/collections/mod.rs b/src/handlers/radarr_handlers/collections/mod.rs index 507a9f0..e8b79b8 100644 --- a/src/handlers/radarr_handlers/collections/mod.rs +++ b/src/handlers/radarr_handlers/collections/mod.rs @@ -1,7 +1,5 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; -use crate::handle_table_events; use crate::handlers::radarr_handlers::collections::collection_details_handler::CollectionDetailsHandler; use crate::handlers::radarr_handlers::collections::edit_collection_handler::EditCollectionHandler; use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys; @@ -14,6 +12,7 @@ use crate::models::servarr_data::radarr::radarr_data::{ use crate::models::stateful_table::SortOption; use crate::models::BlockSelectionState; use crate::network::radarr_network::RadarrEvent; +use crate::{handle_table_events, matches_key}; mod collection_details_handler; mod edit_collection_handler; @@ -73,6 +72,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<' || COLLECTIONS_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -145,7 +148,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<' let key = self.key; match self.active_radarr_block { ActiveRadarrBlock::Collections => match self.key { - _ if key == DEFAULT_KEYBINDINGS.edit.key => { + _ if matches_key!(edit, key) => { self .app .push_navigation_stack(ActiveRadarrBlock::EditCollectionPrompt.into()); @@ -154,18 +157,18 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<' self.app.data.radarr_data.selected_block = BlockSelectionState::new(EDIT_COLLECTION_SELECTION_BLOCKS); } - _ if key == DEFAULT_KEYBINDINGS.update.key => { + _ if matches_key!(update, key) => { self .app .push_navigation_stack(ActiveRadarrBlock::UpdateAllCollectionsPrompt.into()); } - _ if key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, key) => { self.app.should_refresh = true; } _ => (), }, ActiveRadarrBlock::UpdateAllCollectionsPrompt => { - if key == DEFAULT_KEYBINDINGS.confirm.key { + if matches_key!(confirm, key) { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::UpdateCollections); diff --git a/src/handlers/radarr_handlers/downloads/downloads_handler_tests.rs b/src/handlers/radarr_handlers/downloads/downloads_handler_tests.rs index 2efc8f2..6f447b1 100644 --- a/src/handlers/radarr_handlers/downloads/downloads_handler_tests.rs +++ b/src/handlers/radarr_handlers/downloads/downloads_handler_tests.rs @@ -1,6 +1,7 @@ #[cfg(test)] mod tests { use pretty_assertions::assert_eq; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -387,6 +388,22 @@ mod tests { }) } + #[rstest] + fn test_downloads_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = DownloadsHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_extract_download_id() { let mut app = App::test_default(); diff --git a/src/handlers/radarr_handlers/downloads/mod.rs b/src/handlers/radarr_handlers/downloads/mod.rs index b4094d8..bf2f23c 100644 --- a/src/handlers/radarr_handlers/downloads/mod.rs +++ b/src/handlers/radarr_handlers/downloads/mod.rs @@ -1,13 +1,12 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; -use crate::handle_table_events; use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys; use crate::handlers::table_handler::TableHandlingConfig; use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler}; use crate::models::radarr_models::DownloadRecord; use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, DOWNLOADS_BLOCKS}; use crate::network::radarr_network::RadarrEvent; +use crate::{handle_table_events, matches_key}; #[cfg(test)] #[path = "downloads_handler_tests.rs"] @@ -47,6 +46,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for DownloadsHandler<'a, DOWNLOADS_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -130,18 +133,18 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for DownloadsHandler<'a, let key = self.key; match self.active_radarr_block { ActiveRadarrBlock::Downloads => match self.key { - _ if key == DEFAULT_KEYBINDINGS.update.key => { + _ if matches_key!(update, key) => { self .app .push_navigation_stack(ActiveRadarrBlock::UpdateDownloadsPrompt.into()); } - _ if key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, key) => { self.app.should_refresh = true; } _ => (), }, ActiveRadarrBlock::DeleteDownloadPrompt => { - if key == DEFAULT_KEYBINDINGS.confirm.key { + if matches_key!(confirm, key) { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::DeleteDownload(self.extract_download_id())); @@ -150,7 +153,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for DownloadsHandler<'a, } } ActiveRadarrBlock::UpdateDownloadsPrompt => { - if key == DEFAULT_KEYBINDINGS.confirm.key { + if matches_key!(confirm, key) { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::UpdateDownloads); diff --git a/src/handlers/radarr_handlers/indexers/edit_indexer_handler.rs b/src/handlers/radarr_handlers/indexers/edit_indexer_handler.rs index 15350b1..5e5eed5 100644 --- a/src/handlers/radarr_handlers/indexers/edit_indexer_handler.rs +++ b/src/handlers/radarr_handlers/indexers/edit_indexer_handler.rs @@ -1,4 +1,3 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; use crate::handlers::{handle_prompt_toggle, KeyEventHandler}; @@ -6,7 +5,9 @@ use crate::models::servarr_data::modals::EditIndexerModal; use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, EDIT_INDEXER_BLOCKS}; use crate::models::servarr_models::EditIndexerParams; use crate::network::radarr_network::RadarrEvent; -use crate::{handle_prompt_left_right_keys, handle_text_box_keys, handle_text_box_left_right_keys}; +use crate::{ + handle_prompt_left_right_keys, handle_text_box_keys, handle_text_box_left_right_keys, matches_key, +}; #[cfg(test)] #[path = "edit_indexer_handler_tests.rs"] @@ -65,6 +66,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for EditIndexerHandler<' EDIT_INDEXER_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -504,7 +509,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for EditIndexerHandler<' ActiveRadarrBlock::EditIndexerPrompt => { if self.app.data.radarr_data.selected_block.get_active_block() == ActiveRadarrBlock::EditIndexerConfirmPrompt - && self.key == DEFAULT_KEYBINDINGS.confirm.key + && matches_key!(confirm, self.key) { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = diff --git a/src/handlers/radarr_handlers/indexers/edit_indexer_handler_tests.rs b/src/handlers/radarr_handlers/indexers/edit_indexer_handler_tests.rs index a8b0fce..265b091 100644 --- a/src/handlers/radarr_handlers/indexers/edit_indexer_handler_tests.rs +++ b/src/handlers/radarr_handlers/indexers/edit_indexer_handler_tests.rs @@ -10,6 +10,7 @@ mod tests { use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, EDIT_INDEXER_BLOCKS}; use crate::models::servarr_models::EditIndexerParams; use pretty_assertions::assert_eq; + use rstest::rstest; use strum::IntoEnumIterator; mod test_handle_scroll_up_and_down { @@ -1597,7 +1598,7 @@ mod tests { app.data.radarr_data.edit_indexer_modal = Some(EditIndexerModal::default()); EditIndexerHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveRadarrBlock::EditIndexerNameInput, None, @@ -1613,7 +1614,7 @@ mod tests { .unwrap() .name .text, - "h" + "a" ); } @@ -1624,7 +1625,7 @@ mod tests { app.data.radarr_data.edit_indexer_modal = Some(EditIndexerModal::default()); EditIndexerHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveRadarrBlock::EditIndexerUrlInput, None, @@ -1640,7 +1641,7 @@ mod tests { .unwrap() .url .text, - "h" + "a" ); } @@ -1651,7 +1652,7 @@ mod tests { app.data.radarr_data.edit_indexer_modal = Some(EditIndexerModal::default()); EditIndexerHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveRadarrBlock::EditIndexerApiKeyInput, None, @@ -1667,7 +1668,7 @@ mod tests { .unwrap() .api_key .text, - "h" + "a" ); } @@ -1678,7 +1679,7 @@ mod tests { app.data.radarr_data.edit_indexer_modal = Some(EditIndexerModal::default()); EditIndexerHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveRadarrBlock::EditIndexerSeedRatioInput, None, @@ -1694,7 +1695,7 @@ mod tests { .unwrap() .seed_ratio .text, - "h" + "a" ); } @@ -1705,7 +1706,7 @@ mod tests { app.data.radarr_data.edit_indexer_modal = Some(EditIndexerModal::default()); EditIndexerHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveRadarrBlock::EditIndexerTagsInput, None, @@ -1721,7 +1722,7 @@ mod tests { .unwrap() .tags .text, - "h" + "a" ); } @@ -1793,6 +1794,22 @@ mod tests { }) } + #[rstest] + fn test_edit_indexer_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = EditIndexerHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_build_edit_indexer_params() { let mut app = App::test_default(); diff --git a/src/handlers/radarr_handlers/indexers/edit_indexer_settings_handler.rs b/src/handlers/radarr_handlers/indexers/edit_indexer_settings_handler.rs index d304449..e583175 100644 --- a/src/handlers/radarr_handlers/indexers/edit_indexer_settings_handler.rs +++ b/src/handlers/radarr_handlers/indexers/edit_indexer_settings_handler.rs @@ -1,4 +1,3 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; use crate::handlers::{handle_prompt_toggle, KeyEventHandler}; @@ -7,7 +6,9 @@ use crate::models::servarr_data::radarr::radarr_data::{ ActiveRadarrBlock, INDEXER_SETTINGS_BLOCKS, }; use crate::network::radarr_network::RadarrEvent; -use crate::{handle_prompt_left_right_keys, handle_text_box_keys, handle_text_box_left_right_keys}; +use crate::{ + handle_prompt_left_right_keys, handle_text_box_keys, handle_text_box_left_right_keys, matches_key, +}; #[cfg(test)] #[path = "edit_indexer_settings_handler_tests.rs"] @@ -37,6 +38,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for IndexerSettingsHandl INDEXER_SETTINGS_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -269,7 +274,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for IndexerSettingsHandl ActiveRadarrBlock::AllIndexerSettingsPrompt => { if self.app.data.radarr_data.selected_block.get_active_block() == ActiveRadarrBlock::IndexerSettingsConfirmPrompt - && self.key == DEFAULT_KEYBINDINGS.confirm.key + && matches_key!(confirm, self.key) { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = Some( diff --git a/src/handlers/radarr_handlers/indexers/edit_indexer_settings_handler_tests.rs b/src/handlers/radarr_handlers/indexers/edit_indexer_settings_handler_tests.rs index 7dfb325..d790e56 100644 --- a/src/handlers/radarr_handlers/indexers/edit_indexer_settings_handler_tests.rs +++ b/src/handlers/radarr_handlers/indexers/edit_indexer_settings_handler_tests.rs @@ -1,6 +1,7 @@ #[cfg(test)] mod tests { use pretty_assertions::assert_eq; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -907,7 +908,7 @@ mod tests { app.data.radarr_data.indexer_settings = Some(IndexerSettings::default()); IndexerSettingsHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput, None, @@ -923,7 +924,7 @@ mod tests { .unwrap() .whitelisted_hardcoded_subs .text, - "h" + "a" ); } @@ -970,6 +971,22 @@ mod tests { }) } + #[rstest] + fn test_indexer_settings_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = IndexerSettingsHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_build_edit_indexer_settings_body() { let mut app = App::test_default(); diff --git a/src/handlers/radarr_handlers/indexers/indexers_handler_tests.rs b/src/handlers/radarr_handlers/indexers/indexers_handler_tests.rs index e1e562b..db5e657 100644 --- a/src/handlers/radarr_handlers/indexers/indexers_handler_tests.rs +++ b/src/handlers/radarr_handlers/indexers/indexers_handler_tests.rs @@ -633,6 +633,22 @@ mod tests { }) } + #[rstest] + fn test_indexers_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = IndexersHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_extract_indexer_id() { let mut app = App::test_default(); diff --git a/src/handlers/radarr_handlers/indexers/mod.rs b/src/handlers/radarr_handlers/indexers/mod.rs index 28371c9..12eeecd 100644 --- a/src/handlers/radarr_handlers/indexers/mod.rs +++ b/src/handlers/radarr_handlers/indexers/mod.rs @@ -1,7 +1,5 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; -use crate::handle_table_events; use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys; use crate::handlers::radarr_handlers::indexers::edit_indexer_handler::EditIndexerHandler; use crate::handlers::radarr_handlers::indexers::edit_indexer_settings_handler::IndexerSettingsHandler; @@ -15,6 +13,7 @@ use crate::models::servarr_data::radarr::radarr_data::{ use crate::models::servarr_models::Indexer; use crate::models::BlockSelectionState; use crate::network::radarr_network::RadarrEvent; +use crate::{handle_table_events, matches_key}; mod edit_indexer_handler; mod edit_indexer_settings_handler; @@ -70,6 +69,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for IndexersHandler<'a, || INDEXERS_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -169,20 +172,20 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for IndexersHandler<'a, let key = self.key; match self.active_radarr_block { ActiveRadarrBlock::Indexers => match self.key { - _ if key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, key) => { self.app.should_refresh = true; } - _ if key == DEFAULT_KEYBINDINGS.test.key => { + _ if matches_key!(test, key) => { self .app .push_navigation_stack(ActiveRadarrBlock::TestIndexer.into()); } - _ if key == DEFAULT_KEYBINDINGS.test_all.key => { + _ if matches_key!(test_all, key) => { self .app .push_navigation_stack(ActiveRadarrBlock::TestAllIndexers.into()); } - _ if key == DEFAULT_KEYBINDINGS.settings.key => { + _ if matches_key!(settings, key) => { self .app .push_navigation_stack(ActiveRadarrBlock::AllIndexerSettingsPrompt.into()); @@ -192,7 +195,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for IndexersHandler<'a, _ => (), }, ActiveRadarrBlock::DeleteIndexerPrompt => { - if key == DEFAULT_KEYBINDINGS.confirm.key { + if matches_key!(confirm, key) { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::DeleteIndexer(self.extract_indexer_id())); diff --git a/src/handlers/radarr_handlers/indexers/test_all_indexers_handler.rs b/src/handlers/radarr_handlers/indexers/test_all_indexers_handler.rs index 220fa3f..b1e4a83 100644 --- a/src/handlers/radarr_handlers/indexers/test_all_indexers_handler.rs +++ b/src/handlers/radarr_handlers/indexers/test_all_indexers_handler.rs @@ -48,6 +48,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for TestAllIndexersHandl active_block == ActiveRadarrBlock::TestAllIndexers } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, diff --git a/src/handlers/radarr_handlers/indexers/test_all_indexers_handler_tests.rs b/src/handlers/radarr_handlers/indexers/test_all_indexers_handler_tests.rs index bd84171..b497380 100644 --- a/src/handlers/radarr_handlers/indexers/test_all_indexers_handler_tests.rs +++ b/src/handlers/radarr_handlers/indexers/test_all_indexers_handler_tests.rs @@ -7,6 +7,7 @@ mod tests { use crate::models::servarr_data::modals::IndexerTestResultModalItem; use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock; use crate::models::stateful_table::StatefulTable; + use rstest::rstest; use strum::IntoEnumIterator; mod test_handle_esc { @@ -48,6 +49,22 @@ mod tests { }); } + #[rstest] + fn test_test_all_indexers_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = TestAllIndexersHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_test_all_indexers_handler_is_not_ready_when_loading() { let mut app = App::test_default(); diff --git a/src/handlers/radarr_handlers/library/add_movie_handler.rs b/src/handlers/radarr_handlers/library/add_movie_handler.rs index d0c90c0..9840e17 100644 --- a/src/handlers/radarr_handlers/library/add_movie_handler.rs +++ b/src/handlers/radarr_handlers/library/add_movie_handler.rs @@ -1,4 +1,3 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::handlers::table_handler::TableHandlingConfig; use crate::handlers::{handle_prompt_toggle, KeyEventHandler}; use crate::models::radarr_models::{ @@ -11,7 +10,9 @@ use crate::models::servarr_data::radarr::radarr_data::{ use crate::models::stateful_table::StatefulTable; use crate::models::{BlockSelectionState, Scrollable}; use crate::network::radarr_network::RadarrEvent; -use crate::{handle_table_events, handle_text_box_keys, handle_text_box_left_right_keys, App, Key}; +use crate::{ + handle_table_events, handle_text_box_keys, handle_text_box_left_right_keys, matches_key, App, Key, +}; #[cfg(test)] #[path = "add_movie_handler_tests.rs"] @@ -132,6 +133,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for AddMovieHandler<'a, ADD_MOVIE_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -542,7 +547,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for AddMovieHandler<'a, ActiveRadarrBlock::AddMoviePrompt => { if self.app.data.radarr_data.selected_block.get_active_block() == ActiveRadarrBlock::AddMovieConfirmPrompt - && key == DEFAULT_KEYBINDINGS.confirm.key + && matches_key!(confirm, key) { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = diff --git a/src/handlers/radarr_handlers/library/add_movie_handler_tests.rs b/src/handlers/radarr_handlers/library/add_movie_handler_tests.rs index 8be52b8..8966189 100644 --- a/src/handlers/radarr_handlers/library/add_movie_handler_tests.rs +++ b/src/handlers/radarr_handlers/library/add_movie_handler_tests.rs @@ -1395,7 +1395,7 @@ mod tests { app.data.radarr_data.add_movie_search = Some(HorizontallyScrollableText::default()); AddMovieHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveRadarrBlock::AddMovieSearchInput, None, @@ -1404,7 +1404,7 @@ mod tests { assert_str_eq!( app.data.radarr_data.add_movie_search.as_ref().unwrap().text, - "h" + "a" ); } @@ -1414,7 +1414,7 @@ mod tests { app.data.radarr_data.add_movie_modal = Some(AddMovieModal::default()); AddMovieHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveRadarrBlock::AddMovieTagsInput, None, @@ -1430,7 +1430,7 @@ mod tests { .unwrap() .tags .text, - "h" + "a" ); } @@ -1523,6 +1523,22 @@ mod tests { }); } + #[rstest] + fn test_add_movie_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = AddMovieHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_add_movie_search_no_panic_on_none_search_result() { let mut app = App::test_default(); diff --git a/src/handlers/radarr_handlers/library/delete_movie_handler.rs b/src/handlers/radarr_handlers/library/delete_movie_handler.rs index 4f8d320..860f895 100644 --- a/src/handlers/radarr_handlers/library/delete_movie_handler.rs +++ b/src/handlers/radarr_handlers/library/delete_movie_handler.rs @@ -1,7 +1,7 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; use crate::handlers::{handle_prompt_toggle, KeyEventHandler}; +use crate::matches_key; use crate::models::radarr_models::DeleteMovieParams; use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, DELETE_MOVIE_BLOCKS}; use crate::network::radarr_network::RadarrEvent; @@ -37,6 +37,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for DeleteMovieHandler<' DELETE_MOVIE_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -122,7 +126,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for DeleteMovieHandler<' if self.active_radarr_block == ActiveRadarrBlock::DeleteMoviePrompt && self.app.data.radarr_data.selected_block.get_active_block() == ActiveRadarrBlock::DeleteMovieConfirmPrompt - && self.key == DEFAULT_KEYBINDINGS.confirm.key + && matches_key!(confirm, self.key) { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = diff --git a/src/handlers/radarr_handlers/library/delete_movie_handler_tests.rs b/src/handlers/radarr_handlers/library/delete_movie_handler_tests.rs index 151c105..85e8275 100644 --- a/src/handlers/radarr_handlers/library/delete_movie_handler_tests.rs +++ b/src/handlers/radarr_handlers/library/delete_movie_handler_tests.rs @@ -1,6 +1,7 @@ #[cfg(test)] mod tests { use pretty_assertions::assert_eq; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -313,6 +314,22 @@ mod tests { }); } + #[rstest] + fn test_delete_movie_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = DeleteMovieHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_build_delete_movie_params() { let mut app = App::test_default(); diff --git a/src/handlers/radarr_handlers/library/edit_movie_handler.rs b/src/handlers/radarr_handlers/library/edit_movie_handler.rs index 9201091..0daf472 100644 --- a/src/handlers/radarr_handlers/library/edit_movie_handler.rs +++ b/src/handlers/radarr_handlers/library/edit_movie_handler.rs @@ -1,4 +1,3 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; use crate::handlers::{handle_prompt_toggle, KeyEventHandler}; @@ -7,7 +6,7 @@ use crate::models::servarr_data::radarr::modals::EditMovieModal; use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, EDIT_MOVIE_BLOCKS}; use crate::models::Scrollable; use crate::network::radarr_network::RadarrEvent; -use crate::{handle_text_box_keys, handle_text_box_left_right_keys}; +use crate::{handle_text_box_keys, handle_text_box_left_right_keys, matches_key}; #[cfg(test)] #[path = "edit_movie_handler_tests.rs"] @@ -68,6 +67,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for EditMovieHandler<'a, EDIT_MOVIE_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -376,7 +379,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for EditMovieHandler<'a, ActiveRadarrBlock::EditMoviePrompt => { if self.app.data.radarr_data.selected_block.get_active_block() == ActiveRadarrBlock::EditMovieConfirmPrompt - && key == DEFAULT_KEYBINDINGS.confirm.key + && matches_key!(confirm, key) { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = diff --git a/src/handlers/radarr_handlers/library/edit_movie_handler_tests.rs b/src/handlers/radarr_handlers/library/edit_movie_handler_tests.rs index eac5fe9..ce69fc6 100644 --- a/src/handlers/radarr_handlers/library/edit_movie_handler_tests.rs +++ b/src/handlers/radarr_handlers/library/edit_movie_handler_tests.rs @@ -2,6 +2,7 @@ mod tests { use bimap::BiMap; use pretty_assertions::assert_str_eq; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -1033,7 +1034,7 @@ mod tests { app.data.radarr_data.edit_movie_modal = Some(EditMovieModal::default()); EditMovieHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveRadarrBlock::EditMoviePathInput, None, @@ -1049,7 +1050,7 @@ mod tests { .unwrap() .path .text, - "h" + "a" ); } @@ -1059,7 +1060,7 @@ mod tests { app.data.radarr_data.edit_movie_modal = Some(EditMovieModal::default()); EditMovieHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveRadarrBlock::EditMovieTagsInput, None, @@ -1075,7 +1076,7 @@ mod tests { .unwrap() .tags .text, - "h" + "a" ); } @@ -1148,6 +1149,22 @@ mod tests { }); } + #[rstest] + fn test_edit_movie_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = EditMovieHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_build_edit_movie_params() { let mut app = App::test_default(); diff --git a/src/handlers/radarr_handlers/library/library_handler_tests.rs b/src/handlers/radarr_handlers/library/library_handler_tests.rs index 5117095..1ed6f5f 100644 --- a/src/handlers/radarr_handlers/library/library_handler_tests.rs +++ b/src/handlers/radarr_handlers/library/library_handler_tests.rs @@ -777,6 +777,22 @@ mod tests { }); } + #[rstest] + fn test_library_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = LibraryHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_library_handler_not_ready_when_loading() { let mut app = App::test_default(); diff --git a/src/handlers/radarr_handlers/library/mod.rs b/src/handlers/radarr_handlers/library/mod.rs index b7744a7..93b76cc 100644 --- a/src/handlers/radarr_handlers/library/mod.rs +++ b/src/handlers/radarr_handlers/library/mod.rs @@ -1,4 +1,3 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys; @@ -8,7 +7,6 @@ use crate::handlers::radarr_handlers::library::edit_movie_handler::EditMovieHand use crate::handlers::radarr_handlers::library::movie_details_handler::MovieDetailsHandler; use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler}; -use crate::handle_table_events; use crate::handlers::table_handler::TableHandlingConfig; use crate::models::radarr_models::Movie; use crate::models::servarr_data::radarr::radarr_data::{ @@ -17,6 +15,7 @@ use crate::models::servarr_data::radarr::radarr_data::{ use crate::models::stateful_table::SortOption; use crate::models::{BlockSelectionState, HorizontallyScrollableText}; use crate::network::radarr_network::RadarrEvent; +use crate::{handle_table_events, matches_key}; mod add_movie_handler; mod delete_movie_handler; @@ -81,6 +80,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for LibraryHandler<'a, ' || LIBRARY_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -161,7 +164,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for LibraryHandler<'a, ' let key = self.key; match self.active_radarr_block { ActiveRadarrBlock::Movies => match self.key { - _ if key == DEFAULT_KEYBINDINGS.edit.key => { + _ if matches_key!(edit, key) => { self.app.push_navigation_stack( ( ActiveRadarrBlock::EditMoviePrompt, @@ -173,25 +176,25 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for LibraryHandler<'a, ' self.app.data.radarr_data.selected_block = BlockSelectionState::new(EDIT_MOVIE_SELECTION_BLOCKS); } - _ if key == DEFAULT_KEYBINDINGS.add.key => { + _ if matches_key!(add, key) => { self .app .push_navigation_stack(ActiveRadarrBlock::AddMovieSearchInput.into()); self.app.data.radarr_data.add_movie_search = Some(HorizontallyScrollableText::default()); self.app.should_ignore_quit_key = true; } - _ if key == DEFAULT_KEYBINDINGS.update.key => { + _ if matches_key!(update, key) => { self .app .push_navigation_stack(ActiveRadarrBlock::UpdateAllMoviesPrompt.into()); } - _ if key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, key) => { self.app.should_refresh = true; } _ => (), }, ActiveRadarrBlock::UpdateAllMoviesPrompt => { - if key == DEFAULT_KEYBINDINGS.confirm.key { + if matches_key!(confirm, key) { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::UpdateAllMovies); diff --git a/src/handlers/radarr_handlers/library/movie_details_handler.rs b/src/handlers/radarr_handlers/library/movie_details_handler.rs index 2e41f47..f8a4805 100644 --- a/src/handlers/radarr_handlers/library/movie_details_handler.rs +++ b/src/handlers/radarr_handlers/library/movie_details_handler.rs @@ -1,9 +1,7 @@ use serde_json::Number; -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; -use crate::handle_table_events; use crate::handlers::table_handler::TableHandlingConfig; use crate::handlers::{handle_prompt_toggle, KeyEventHandler}; use crate::models::radarr_models::{ @@ -16,6 +14,7 @@ use crate::models::servarr_models::Language; use crate::models::stateful_table::SortOption; use crate::models::{BlockSelectionState, Scrollable}; use crate::network::radarr_network::RadarrEvent; +use crate::{handle_table_events, matches_key}; #[cfg(test)] #[path = "movie_details_handler_tests.rs"] @@ -136,6 +135,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for MovieDetailsHandler< MOVIE_DETAILS_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -245,13 +248,13 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for MovieDetailsHandler< | ActiveRadarrBlock::Cast | ActiveRadarrBlock::Crew | ActiveRadarrBlock::ManualSearch => match self.key { - _ if self.key == DEFAULT_KEYBINDINGS.left.key => { + _ if matches_key!(left, self.key) => { self.app.data.radarr_data.movie_info_tabs.previous(); self.app.pop_and_push_navigation_stack( self.app.data.radarr_data.movie_info_tabs.get_active_route(), ); } - _ if self.key == DEFAULT_KEYBINDINGS.right.key => { + _ if matches_key!(right, self.key) => { self.app.data.radarr_data.movie_info_tabs.next(); self.app.pop_and_push_navigation_stack( self.app.data.radarr_data.movie_info_tabs.get_active_route(), @@ -332,12 +335,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for MovieDetailsHandler< | ActiveRadarrBlock::Cast | ActiveRadarrBlock::Crew | ActiveRadarrBlock::ManualSearch => match self.key { - _ if key == DEFAULT_KEYBINDINGS.auto_search.key => { + _ if matches_key!(auto_search, key) => { self .app .push_navigation_stack(ActiveRadarrBlock::AutomaticallySearchMoviePrompt.into()); } - _ if key == DEFAULT_KEYBINDINGS.edit.key => { + _ if matches_key!(edit, key) => { self.app.push_navigation_stack( ( ActiveRadarrBlock::EditMoviePrompt, @@ -349,35 +352,33 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for MovieDetailsHandler< self.app.data.radarr_data.selected_block = BlockSelectionState::new(EDIT_MOVIE_SELECTION_BLOCKS); } - _ if key == DEFAULT_KEYBINDINGS.update.key => { + _ if matches_key!(update, key) => { self .app .push_navigation_stack(ActiveRadarrBlock::UpdateAndScanPrompt.into()); } - _ if key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, key) => { self .app .pop_and_push_navigation_stack(self.active_radarr_block.into()); } _ => (), }, - ActiveRadarrBlock::AutomaticallySearchMoviePrompt - if key == DEFAULT_KEYBINDINGS.confirm.key => - { + ActiveRadarrBlock::AutomaticallySearchMoviePrompt if matches_key!(confirm, key) => { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::TriggerAutomaticSearch(self.extract_movie_id())); self.app.pop_navigation_stack(); } - ActiveRadarrBlock::UpdateAndScanPrompt if key == DEFAULT_KEYBINDINGS.confirm.key => { + ActiveRadarrBlock::UpdateAndScanPrompt if matches_key!(confirm, key) => { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::UpdateAndScan(self.extract_movie_id())); self.app.pop_navigation_stack(); } - ActiveRadarrBlock::ManualSearchConfirmPrompt if key == DEFAULT_KEYBINDINGS.confirm.key => { + ActiveRadarrBlock::ManualSearchConfirmPrompt if matches_key!(confirm, key) => { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::DownloadRelease( self.build_radarr_release_download_body(), diff --git a/src/handlers/radarr_handlers/library/movie_details_handler_tests.rs b/src/handlers/radarr_handlers/library/movie_details_handler_tests.rs index c7332e6..bc3dbd0 100644 --- a/src/handlers/radarr_handlers/library/movie_details_handler_tests.rs +++ b/src/handlers/radarr_handlers/library/movie_details_handler_tests.rs @@ -1042,6 +1042,22 @@ mod tests { }); } + #[rstest] + fn test_movie_details_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = MovieDetailsHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[rstest] fn test_movie_details_handler_is_not_ready_when_loading( #[values( diff --git a/src/handlers/radarr_handlers/mod.rs b/src/handlers/radarr_handlers/mod.rs index 8ffbf29..f462704 100644 --- a/src/handlers/radarr_handlers/mod.rs +++ b/src/handlers/radarr_handlers/mod.rs @@ -1,4 +1,3 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::handlers::radarr_handlers::blocklist::BlocklistHandler; use crate::handlers::radarr_handlers::collections::CollectionsHandler; use crate::handlers::radarr_handlers::downloads::DownloadsHandler; @@ -8,7 +7,7 @@ use crate::handlers::radarr_handlers::root_folders::RootFoldersHandler; use crate::handlers::radarr_handlers::system::SystemHandler; use crate::handlers::KeyEventHandler; use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock; -use crate::{App, Key}; +use crate::{matches_key, App, Key}; mod blocklist; mod collections; @@ -65,6 +64,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for RadarrHandler<'a, 'b true } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -109,11 +112,11 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for RadarrHandler<'a, 'b pub fn handle_change_tab_left_right_keys(app: &mut App<'_>, key: Key) { let key_ref = key; match key_ref { - _ if key == DEFAULT_KEYBINDINGS.left.key => { + _ if matches_key!(left, key, app.should_ignore_quit_key) => { app.data.radarr_data.main_tabs.previous(); app.pop_and_push_navigation_stack(app.data.radarr_data.main_tabs.get_active_route()); } - _ if key == DEFAULT_KEYBINDINGS.right.key => { + _ if matches_key!(right, key, app.should_ignore_quit_key) => { app.data.radarr_data.main_tabs.next(); app.pop_and_push_navigation_stack(app.data.radarr_data.main_tabs.get_active_route()); } diff --git a/src/handlers/radarr_handlers/radarr_handler_tests.rs b/src/handlers/radarr_handlers/radarr_handler_tests.rs index cd0dc42..ff118fe 100644 --- a/src/handlers/radarr_handlers/radarr_handler_tests.rs +++ b/src/handlers/radarr_handlers/radarr_handler_tests.rs @@ -46,6 +46,76 @@ mod tests { assert_eq!(app.get_current_route(), right_block.into()); } + #[rstest] + #[case(0, ActiveRadarrBlock::System, ActiveRadarrBlock::Collections)] + #[case(1, ActiveRadarrBlock::Movies, ActiveRadarrBlock::Downloads)] + #[case(2, ActiveRadarrBlock::Collections, ActiveRadarrBlock::Blocklist)] + #[case(3, ActiveRadarrBlock::Downloads, ActiveRadarrBlock::RootFolders)] + #[case(4, ActiveRadarrBlock::Blocklist, ActiveRadarrBlock::Indexers)] + #[case(5, ActiveRadarrBlock::RootFolders, ActiveRadarrBlock::System)] + #[case(6, ActiveRadarrBlock::Indexers, ActiveRadarrBlock::Movies)] + fn test_radarr_handler_change_tab_left_right_keys_alt_navigation( + #[case] index: usize, + #[case] left_block: ActiveRadarrBlock, + #[case] right_block: ActiveRadarrBlock, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = false; + app.data.radarr_data.main_tabs.set_index(index); + + handle_change_tab_left_right_keys(&mut app, DEFAULT_KEYBINDINGS.left.alt.unwrap()); + + assert_eq!( + app.data.radarr_data.main_tabs.get_active_route(), + left_block.into() + ); + assert_eq!(app.get_current_route(), left_block.into()); + + app.data.radarr_data.main_tabs.set_index(index); + + handle_change_tab_left_right_keys(&mut app, DEFAULT_KEYBINDINGS.right.alt.unwrap()); + + assert_eq!( + app.data.radarr_data.main_tabs.get_active_route(), + right_block.into() + ); + assert_eq!(app.get_current_route(), right_block.into()); + } + + #[rstest] + #[case(0, ActiveRadarrBlock::Movies)] + #[case(1, ActiveRadarrBlock::Collections)] + #[case(2, ActiveRadarrBlock::Downloads)] + #[case(3, ActiveRadarrBlock::Blocklist)] + #[case(4, ActiveRadarrBlock::RootFolders)] + #[case(5, ActiveRadarrBlock::Indexers)] + #[case(6, ActiveRadarrBlock::System)] + fn test_radarr_handler_change_tab_left_right_keys_alt_navigation_no_op_when_ignoring_quit_key( + #[case] index: usize, + #[case] block: ActiveRadarrBlock, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = true; + app.push_navigation_stack(block.into()); + app.data.radarr_data.main_tabs.set_index(index); + + handle_change_tab_left_right_keys(&mut app, DEFAULT_KEYBINDINGS.left.alt.unwrap()); + + assert_eq!( + app.data.radarr_data.main_tabs.get_active_route(), + block.into() + ); + assert_eq!(app.get_current_route(), block.into()); + + handle_change_tab_left_right_keys(&mut app, DEFAULT_KEYBINDINGS.right.alt.unwrap()); + + assert_eq!( + app.data.radarr_data.main_tabs.get_active_route(), + block.into() + ); + assert_eq!(app.get_current_route(), block.into()); + } + #[rstest] fn test_delegates_system_blocks_to_system_handler( #[values( @@ -217,6 +287,22 @@ mod tests { }) } + #[rstest] + fn test_radarr_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = RadarrHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::Movies, + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_radarr_handler_is_ready() { let mut app = App::test_default(); diff --git a/src/handlers/radarr_handlers/root_folders/mod.rs b/src/handlers/radarr_handlers/root_folders/mod.rs index feb6879..e942163 100644 --- a/src/handlers/radarr_handlers/root_folders/mod.rs +++ b/src/handlers/radarr_handlers/root_folders/mod.rs @@ -1,4 +1,3 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys; @@ -8,7 +7,9 @@ use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, ROOT_F use crate::models::servarr_models::{AddRootFolderBody, RootFolder}; use crate::models::HorizontallyScrollableText; use crate::network::radarr_network::RadarrEvent; -use crate::{handle_table_events, handle_text_box_keys, handle_text_box_left_right_keys}; +use crate::{ + handle_table_events, handle_text_box_keys, handle_text_box_left_right_keys, matches_key, +}; #[cfg(test)] #[path = "root_folders_handler_tests.rs"] @@ -68,6 +69,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for RootFoldersHandler<' ROOT_FOLDERS_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -195,10 +200,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for RootFoldersHandler<' let key = self.key; match self.active_radarr_block { ActiveRadarrBlock::RootFolders => match self.key { - _ if key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, key) => { self.app.should_refresh = true; } - _ if key == DEFAULT_KEYBINDINGS.add.key => { + _ if matches_key!(add, key) => { self .app .push_navigation_stack(ActiveRadarrBlock::AddRootFolderPrompt.into()); @@ -215,7 +220,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for RootFoldersHandler<' ) } ActiveRadarrBlock::DeleteRootFolderPrompt => { - if key == DEFAULT_KEYBINDINGS.confirm.key { + if matches_key!(confirm, key) { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::DeleteRootFolder(self.extract_root_folder_id())); diff --git a/src/handlers/radarr_handlers/root_folders/root_folders_handler_tests.rs b/src/handlers/radarr_handlers/root_folders/root_folders_handler_tests.rs index 3cf7d98..036b7c8 100644 --- a/src/handlers/radarr_handlers/root_folders/root_folders_handler_tests.rs +++ b/src/handlers/radarr_handlers/root_folders/root_folders_handler_tests.rs @@ -1,6 +1,7 @@ #[cfg(test)] mod tests { use pretty_assertions::assert_eq; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -589,7 +590,7 @@ mod tests { app.data.radarr_data.edit_root_folder = Some(HorizontallyScrollableText::default()); RootFoldersHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveRadarrBlock::AddRootFolderPrompt, None, @@ -598,7 +599,7 @@ mod tests { assert_str_eq!( app.data.radarr_data.edit_root_folder.as_ref().unwrap().text, - "h" + "a" ); } @@ -644,6 +645,22 @@ mod tests { }) } + #[rstest] + fn test_root_folders_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = RootFoldersHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_build_add_root_folder_body() { let mut app = App::test_default(); diff --git a/src/handlers/radarr_handlers/system/mod.rs b/src/handlers/radarr_handlers/system/mod.rs index 7652b36..83be458 100644 --- a/src/handlers/radarr_handlers/system/mod.rs +++ b/src/handlers/radarr_handlers/system/mod.rs @@ -1,9 +1,9 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys; use crate::handlers::radarr_handlers::system::system_details_handler::SystemDetailsHandler; use crate::handlers::{handle_clear_errors, KeyEventHandler}; +use crate::matches_key; use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock; use crate::models::Scrollable; @@ -35,6 +35,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for SystemHandler<'a, 'b SystemDetailsHandler::accepts(active_block) || active_block == ActiveRadarrBlock::System } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -86,15 +90,15 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for SystemHandler<'a, 'b if self.active_radarr_block == ActiveRadarrBlock::System { let key = self.key; match self.key { - _ if key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, key) => { self.app.should_refresh = true; } - _ if key == DEFAULT_KEYBINDINGS.events.key => { + _ if matches_key!(events, key) => { self .app .push_navigation_stack(ActiveRadarrBlock::SystemQueuedEvents.into()); } - _ if key == DEFAULT_KEYBINDINGS.logs.key => { + _ if matches_key!(logs, key) => { self .app .push_navigation_stack(ActiveRadarrBlock::SystemLogs.into()); @@ -106,12 +110,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for SystemHandler<'a, 'b .set_items(self.app.data.radarr_data.logs.items.to_vec()); self.app.data.radarr_data.log_details.scroll_to_bottom(); } - _ if key == DEFAULT_KEYBINDINGS.tasks.key => { + _ if matches_key!(tasks, key) => { self .app .push_navigation_stack(ActiveRadarrBlock::SystemTasks.into()); } - _ if key == DEFAULT_KEYBINDINGS.update.key => { + _ if matches_key!(update, key) => { self .app .push_navigation_stack(ActiveRadarrBlock::SystemUpdates.into()); diff --git a/src/handlers/radarr_handlers/system/system_details_handler.rs b/src/handlers/radarr_handlers/system/system_details_handler.rs index eaadb68..e19c556 100644 --- a/src/handlers/radarr_handlers/system/system_details_handler.rs +++ b/src/handlers/radarr_handlers/system/system_details_handler.rs @@ -1,7 +1,7 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; use crate::handlers::{handle_prompt_toggle, KeyEventHandler}; +use crate::matches_key; use crate::models::radarr_models::RadarrTaskName; use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, SYSTEM_DETAILS_BLOCKS}; use crate::models::stateful_list::StatefulList; @@ -36,6 +36,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for SystemDetailsHandler SYSTEM_DETAILS_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -114,7 +118,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for SystemDetailsHandler match self.active_radarr_block { ActiveRadarrBlock::SystemLogs => match self.key { - _ if key == DEFAULT_KEYBINDINGS.left.key => { + _ if matches_key!(left, key) => { self .app .data @@ -124,7 +128,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for SystemDetailsHandler .iter() .for_each(|log| log.scroll_right()); } - _ if key == DEFAULT_KEYBINDINGS.right.key => { + _ if matches_key!(right, key) => { self .app .data @@ -178,14 +182,13 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for SystemDetailsHandler } fn handle_char_key_event(&mut self) { - if SYSTEM_DETAILS_BLOCKS.contains(&self.active_radarr_block) - && self.key == DEFAULT_KEYBINDINGS.refresh.key + if SYSTEM_DETAILS_BLOCKS.contains(&self.active_radarr_block) && matches_key!(refresh, self.key) { self.app.should_refresh = true; } if self.active_radarr_block == ActiveRadarrBlock::SystemTaskStartConfirmPrompt - && self.key == DEFAULT_KEYBINDINGS.confirm.key + && matches_key!(confirm, self.key) { self.app.data.radarr_data.prompt_confirm = true; self.app.data.radarr_data.prompt_confirm_action = diff --git a/src/handlers/radarr_handlers/system/system_details_handler_tests.rs b/src/handlers/radarr_handlers/system/system_details_handler_tests.rs index 7765670..a4caf72 100644 --- a/src/handlers/radarr_handlers/system/system_details_handler_tests.rs +++ b/src/handlers/radarr_handlers/system/system_details_handler_tests.rs @@ -1,6 +1,7 @@ #[cfg(test)] mod tests { use pretty_assertions::{assert_eq, assert_str_eq}; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -938,6 +939,22 @@ mod tests { }) } + #[rstest] + fn test_system_details_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = SystemDetailsHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_extract_task_name() { let mut app = App::test_default(); diff --git a/src/handlers/radarr_handlers/system/system_handler_tests.rs b/src/handlers/radarr_handlers/system/system_handler_tests.rs index 3a5be26..25f8622 100644 --- a/src/handlers/radarr_handlers/system/system_handler_tests.rs +++ b/src/handlers/radarr_handlers/system/system_handler_tests.rs @@ -450,6 +450,22 @@ mod tests { }) } + #[rstest] + fn test_system_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = SystemHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveRadarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_system_handler_is_not_ready_when_loading() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/blocklist/blocklist_handler_tests.rs b/src/handlers/sonarr_handlers/blocklist/blocklist_handler_tests.rs index da345db..74783ac 100644 --- a/src/handlers/sonarr_handlers/blocklist/blocklist_handler_tests.rs +++ b/src/handlers/sonarr_handlers/blocklist/blocklist_handler_tests.rs @@ -4,6 +4,7 @@ mod tests { use chrono::DateTime; use pretty_assertions::{assert_eq, assert_str_eq}; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -513,6 +514,22 @@ mod tests { }) } + #[rstest] + fn test_blocklist_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = BlocklistHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_extract_blocklist_item_id() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/blocklist/mod.rs b/src/handlers/sonarr_handlers/blocklist/mod.rs index ce4d07d..ca91fb3 100644 --- a/src/handlers/sonarr_handlers/blocklist/mod.rs +++ b/src/handlers/sonarr_handlers/blocklist/mod.rs @@ -1,7 +1,5 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; -use crate::handle_table_events; use crate::handlers::sonarr_handlers::handle_change_tab_left_right_keys; use crate::handlers::table_handler::TableHandlingConfig; use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler}; @@ -9,6 +7,7 @@ use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, BLOCKL use crate::models::sonarr_models::BlocklistItem; use crate::models::stateful_table::SortOption; use crate::network::sonarr_network::SonarrEvent; +use crate::{handle_table_events, matches_key}; #[cfg(test)] #[path = "blocklist_handler_tests.rs"] @@ -51,6 +50,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for BlocklistHandler<'a, BLOCKLIST_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -143,10 +146,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for BlocklistHandler<'a, let key = self.key; match self.active_sonarr_block { ActiveSonarrBlock::Blocklist => match self.key { - _ if key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, key) => { self.app.should_refresh = true; } - _ if key == DEFAULT_KEYBINDINGS.clear.key => { + _ if matches_key!(clear, key) => { self .app .push_navigation_stack(ActiveSonarrBlock::BlocklistClearAllItemsPrompt.into()); @@ -154,7 +157,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for BlocklistHandler<'a, _ => (), }, ActiveSonarrBlock::DeleteBlocklistItemPrompt => { - if key == DEFAULT_KEYBINDINGS.confirm.key { + if matches_key!(confirm, key) { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::DeleteBlocklistItem( self.extract_blocklist_item_id(), @@ -164,7 +167,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for BlocklistHandler<'a, } } ActiveSonarrBlock::BlocklistClearAllItemsPrompt => { - if key == DEFAULT_KEYBINDINGS.confirm.key { + if matches_key!(confirm, key) { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::ClearBlocklist); diff --git a/src/handlers/sonarr_handlers/downloads/downloads_handler_tests.rs b/src/handlers/sonarr_handlers/downloads/downloads_handler_tests.rs index 06331bf..68ff72a 100644 --- a/src/handlers/sonarr_handlers/downloads/downloads_handler_tests.rs +++ b/src/handlers/sonarr_handlers/downloads/downloads_handler_tests.rs @@ -1,6 +1,7 @@ #[cfg(test)] mod tests { use pretty_assertions::assert_eq; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -389,6 +390,22 @@ mod tests { }) } + #[rstest] + fn test_downloads_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = DownloadsHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_extract_download_id() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/downloads/mod.rs b/src/handlers/sonarr_handlers/downloads/mod.rs index b7a3c46..0ae0c5c 100644 --- a/src/handlers/sonarr_handlers/downloads/mod.rs +++ b/src/handlers/sonarr_handlers/downloads/mod.rs @@ -1,13 +1,12 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; -use crate::handle_table_events; use crate::handlers::sonarr_handlers::handle_change_tab_left_right_keys; use crate::handlers::table_handler::TableHandlingConfig; use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler}; use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, DOWNLOADS_BLOCKS}; use crate::models::sonarr_models::DownloadRecord; use crate::network::sonarr_network::SonarrEvent; +use crate::{handle_table_events, matches_key}; #[cfg(test)] #[path = "downloads_handler_tests.rs"] @@ -47,6 +46,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for DownloadsHandler<'a, DOWNLOADS_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -130,18 +133,18 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for DownloadsHandler<'a, let key = self.key; match self.active_sonarr_block { ActiveSonarrBlock::Downloads => match self.key { - _ if key == DEFAULT_KEYBINDINGS.update.key => { + _ if matches_key!(update, key) => { self .app .push_navigation_stack(ActiveSonarrBlock::UpdateDownloadsPrompt.into()); } - _ if key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, key) => { self.app.should_refresh = true; } _ => (), }, ActiveSonarrBlock::DeleteDownloadPrompt => { - if key == DEFAULT_KEYBINDINGS.confirm.key { + if matches_key!(confirm, key) { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::DeleteDownload(self.extract_download_id())); @@ -150,7 +153,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for DownloadsHandler<'a, } } ActiveSonarrBlock::UpdateDownloadsPrompt => { - if key == DEFAULT_KEYBINDINGS.confirm.key { + if matches_key!(confirm, key) { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::UpdateDownloads); diff --git a/src/handlers/sonarr_handlers/history/history_handler_tests.rs b/src/handlers/sonarr_handlers/history/history_handler_tests.rs index 3eff736..08953c0 100644 --- a/src/handlers/sonarr_handlers/history/history_handler_tests.rs +++ b/src/handlers/sonarr_handlers/history/history_handler_tests.rs @@ -4,6 +4,7 @@ mod tests { use chrono::DateTime; use pretty_assertions::{assert_eq, assert_str_eq}; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -306,6 +307,22 @@ mod tests { }) } + #[rstest] + fn test_history_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = HistoryHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_history_handler_not_ready_when_loading() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/history/mod.rs b/src/handlers/sonarr_handlers/history/mod.rs index 2a11ee7..3ea81d8 100644 --- a/src/handlers/sonarr_handlers/history/mod.rs +++ b/src/handlers/sonarr_handlers/history/mod.rs @@ -1,7 +1,5 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; -use crate::handle_table_events; use crate::handlers::sonarr_handlers::handle_change_tab_left_right_keys; use crate::handlers::table_handler::TableHandlingConfig; use crate::handlers::{handle_clear_errors, KeyEventHandler}; @@ -9,6 +7,7 @@ use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, HISTOR use crate::models::servarr_models::Language; use crate::models::sonarr_models::SonarrHistoryItem; use crate::models::stateful_table::SortOption; +use crate::{handle_table_events, matches_key}; #[cfg(test)] #[path = "history_handler_tests.rs"] @@ -52,6 +51,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for HistoryHandler<'a, ' HISTORY_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -110,7 +113,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for HistoryHandler<'a, ' let key = self.key; if self.active_sonarr_block == ActiveSonarrBlock::History { match self.key { - _ if key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, key) => { self.app.should_refresh = true; } _ => (), diff --git a/src/handlers/sonarr_handlers/indexers/edit_indexer_handler.rs b/src/handlers/sonarr_handlers/indexers/edit_indexer_handler.rs index 485a4e2..0448935 100644 --- a/src/handlers/sonarr_handlers/indexers/edit_indexer_handler.rs +++ b/src/handlers/sonarr_handlers/indexers/edit_indexer_handler.rs @@ -1,4 +1,3 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; use crate::handlers::{handle_prompt_toggle, KeyEventHandler}; @@ -6,7 +5,9 @@ use crate::models::servarr_data::modals::EditIndexerModal; use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, EDIT_INDEXER_BLOCKS}; use crate::models::servarr_models::EditIndexerParams; use crate::network::sonarr_network::SonarrEvent; -use crate::{handle_prompt_left_right_keys, handle_text_box_keys, handle_text_box_left_right_keys}; +use crate::{ + handle_prompt_left_right_keys, handle_text_box_keys, handle_text_box_left_right_keys, matches_key, +}; #[cfg(test)] #[path = "edit_indexer_handler_tests.rs"] @@ -64,6 +65,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for EditIndexerHandler<' EDIT_INDEXER_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -503,7 +508,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for EditIndexerHandler<' ActiveSonarrBlock::EditIndexerPrompt => { if self.app.data.sonarr_data.selected_block.get_active_block() == ActiveSonarrBlock::EditIndexerConfirmPrompt - && self.key == DEFAULT_KEYBINDINGS.confirm.key + && matches_key!(confirm, self.key) { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = diff --git a/src/handlers/sonarr_handlers/indexers/edit_indexer_handler_tests.rs b/src/handlers/sonarr_handlers/indexers/edit_indexer_handler_tests.rs index 22719ff..b14d07a 100644 --- a/src/handlers/sonarr_handlers/indexers/edit_indexer_handler_tests.rs +++ b/src/handlers/sonarr_handlers/indexers/edit_indexer_handler_tests.rs @@ -10,6 +10,7 @@ mod tests { use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, EDIT_INDEXER_BLOCKS}; use crate::models::servarr_models::EditIndexerParams; use pretty_assertions::assert_eq; + use rstest::rstest; use strum::IntoEnumIterator; mod test_handle_scroll_up_and_down { @@ -1597,7 +1598,7 @@ mod tests { app.data.sonarr_data.edit_indexer_modal = Some(EditIndexerModal::default()); EditIndexerHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveSonarrBlock::EditIndexerNameInput, None, @@ -1613,7 +1614,7 @@ mod tests { .unwrap() .name .text, - "h" + "a" ); } @@ -1624,7 +1625,7 @@ mod tests { app.data.sonarr_data.edit_indexer_modal = Some(EditIndexerModal::default()); EditIndexerHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveSonarrBlock::EditIndexerUrlInput, None, @@ -1640,7 +1641,7 @@ mod tests { .unwrap() .url .text, - "h" + "a" ); } @@ -1651,7 +1652,7 @@ mod tests { app.data.sonarr_data.edit_indexer_modal = Some(EditIndexerModal::default()); EditIndexerHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveSonarrBlock::EditIndexerApiKeyInput, None, @@ -1667,7 +1668,7 @@ mod tests { .unwrap() .api_key .text, - "h" + "a" ); } @@ -1678,7 +1679,7 @@ mod tests { app.data.sonarr_data.edit_indexer_modal = Some(EditIndexerModal::default()); EditIndexerHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveSonarrBlock::EditIndexerSeedRatioInput, None, @@ -1694,7 +1695,7 @@ mod tests { .unwrap() .seed_ratio .text, - "h" + "a" ); } @@ -1705,7 +1706,7 @@ mod tests { app.data.sonarr_data.edit_indexer_modal = Some(EditIndexerModal::default()); EditIndexerHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveSonarrBlock::EditIndexerTagsInput, None, @@ -1721,7 +1722,7 @@ mod tests { .unwrap() .tags .text, - "h" + "a" ); } @@ -1793,6 +1794,22 @@ mod tests { }) } + #[rstest] + fn test_edit_indexer_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = EditIndexerHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_build_edit_indexer_params() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/indexers/edit_indexer_settings_handler.rs b/src/handlers/sonarr_handlers/indexers/edit_indexer_settings_handler.rs index 4e1a45a..8ee6e1d 100644 --- a/src/handlers/sonarr_handlers/indexers/edit_indexer_settings_handler.rs +++ b/src/handlers/sonarr_handlers/indexers/edit_indexer_settings_handler.rs @@ -1,13 +1,12 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; -use crate::handle_prompt_left_right_keys; use crate::handlers::{handle_prompt_toggle, KeyEventHandler}; use crate::models::servarr_data::sonarr::sonarr_data::{ ActiveSonarrBlock, INDEXER_SETTINGS_BLOCKS, }; use crate::models::sonarr_models::IndexerSettings; use crate::network::sonarr_network::SonarrEvent; +use crate::{handle_prompt_left_right_keys, matches_key}; #[cfg(test)] #[path = "edit_indexer_settings_handler_tests.rs"] @@ -37,6 +36,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for IndexerSettingsHandl INDEXER_SETTINGS_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -183,7 +186,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for IndexerSettingsHandl if self.active_sonarr_block == ActiveSonarrBlock::AllIndexerSettingsPrompt && self.app.data.sonarr_data.selected_block.get_active_block() == ActiveSonarrBlock::IndexerSettingsConfirmPrompt - && self.key == DEFAULT_KEYBINDINGS.confirm.key + && matches_key!(confirm, self.key) { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::EditAllIndexerSettings( diff --git a/src/handlers/sonarr_handlers/indexers/edit_indexer_settings_handler_tests.rs b/src/handlers/sonarr_handlers/indexers/edit_indexer_settings_handler_tests.rs index 23446d8..d22234a 100644 --- a/src/handlers/sonarr_handlers/indexers/edit_indexer_settings_handler_tests.rs +++ b/src/handlers/sonarr_handlers/indexers/edit_indexer_settings_handler_tests.rs @@ -1,6 +1,7 @@ #[cfg(test)] mod tests { use pretty_assertions::assert_eq; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -521,6 +522,22 @@ mod tests { }) } + #[rstest] + fn test_indexer_settings_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = IndexerSettingsHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_build_edit_indexer_settings_params() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/indexers/indexers_handler_tests.rs b/src/handlers/sonarr_handlers/indexers/indexers_handler_tests.rs index b059315..8f7a963 100644 --- a/src/handlers/sonarr_handlers/indexers/indexers_handler_tests.rs +++ b/src/handlers/sonarr_handlers/indexers/indexers_handler_tests.rs @@ -643,6 +643,22 @@ mod tests { }) } + #[rstest] + fn test_indexers_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = IndexersHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_extract_indexer_id() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/indexers/mod.rs b/src/handlers/sonarr_handlers/indexers/mod.rs index 261ca3a..0b68374 100644 --- a/src/handlers/sonarr_handlers/indexers/mod.rs +++ b/src/handlers/sonarr_handlers/indexers/mod.rs @@ -1,7 +1,5 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; -use crate::handle_table_events; use crate::handlers::sonarr_handlers::handle_change_tab_left_right_keys; use crate::handlers::sonarr_handlers::indexers::edit_indexer_handler::EditIndexerHandler; use crate::handlers::sonarr_handlers::indexers::edit_indexer_settings_handler::IndexerSettingsHandler; @@ -15,6 +13,7 @@ use crate::models::servarr_data::sonarr::sonarr_data::{ use crate::models::servarr_models::Indexer; use crate::models::BlockSelectionState; use crate::network::sonarr_network::SonarrEvent; +use crate::{handle_table_events, matches_key}; mod edit_indexer_handler; mod edit_indexer_settings_handler; @@ -70,6 +69,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for IndexersHandler<'a, || INDEXERS_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -168,20 +171,20 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for IndexersHandler<'a, let key = self.key; match self.active_sonarr_block { ActiveSonarrBlock::Indexers => match self.key { - _ if key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, key) => { self.app.should_refresh = true; } - _ if key == DEFAULT_KEYBINDINGS.test.key => { + _ if matches_key!(test, key) => { self .app .push_navigation_stack(ActiveSonarrBlock::TestIndexer.into()); } - _ if key == DEFAULT_KEYBINDINGS.test_all.key => { + _ if matches_key!(test_all, key) => { self .app .push_navigation_stack(ActiveSonarrBlock::TestAllIndexers.into()); } - _ if key == DEFAULT_KEYBINDINGS.settings.key => { + _ if matches_key!(settings, key) => { self .app .push_navigation_stack(ActiveSonarrBlock::AllIndexerSettingsPrompt.into()); @@ -191,7 +194,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for IndexersHandler<'a, _ => (), }, ActiveSonarrBlock::DeleteIndexerPrompt => { - if key == DEFAULT_KEYBINDINGS.confirm.key { + if matches_key!(confirm, key) { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::DeleteIndexer(self.extract_indexer_id())); diff --git a/src/handlers/sonarr_handlers/indexers/test_all_indexers_handler.rs b/src/handlers/sonarr_handlers/indexers/test_all_indexers_handler.rs index 96de3ca..61ed861 100644 --- a/src/handlers/sonarr_handlers/indexers/test_all_indexers_handler.rs +++ b/src/handlers/sonarr_handlers/indexers/test_all_indexers_handler.rs @@ -48,6 +48,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for TestAllIndexersHandl active_block == ActiveSonarrBlock::TestAllIndexers } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, diff --git a/src/handlers/sonarr_handlers/indexers/test_all_indexers_handler_tests.rs b/src/handlers/sonarr_handlers/indexers/test_all_indexers_handler_tests.rs index b52d39d..8ad05c6 100644 --- a/src/handlers/sonarr_handlers/indexers/test_all_indexers_handler_tests.rs +++ b/src/handlers/sonarr_handlers/indexers/test_all_indexers_handler_tests.rs @@ -7,6 +7,7 @@ mod tests { use crate::models::servarr_data::modals::IndexerTestResultModalItem; use crate::models::servarr_data::sonarr::sonarr_data::ActiveSonarrBlock; use crate::models::stateful_table::StatefulTable; + use rstest::rstest; use strum::IntoEnumIterator; mod test_handle_esc { @@ -48,6 +49,22 @@ mod tests { }); } + #[rstest] + fn test_test_all_indexers_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = TestAllIndexersHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_test_all_indexers_handler_is_not_ready_when_loading() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/library/add_series_handler.rs b/src/handlers/sonarr_handlers/library/add_series_handler.rs index b50ab9d..53076c8 100644 --- a/src/handlers/sonarr_handlers/library/add_series_handler.rs +++ b/src/handlers/sonarr_handlers/library/add_series_handler.rs @@ -1,4 +1,3 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::handlers::table_handler::TableHandlingConfig; use crate::handlers::{handle_prompt_toggle, KeyEventHandler}; use crate::models::servarr_data::sonarr::modals::AddSeriesModal; @@ -9,7 +8,9 @@ use crate::models::sonarr_models::{AddSeriesBody, AddSeriesOptions, AddSeriesSea use crate::models::stateful_table::StatefulTable; use crate::models::{BlockSelectionState, Scrollable}; use crate::network::sonarr_network::SonarrEvent; -use crate::{handle_table_events, handle_text_box_keys, handle_text_box_left_right_keys, App, Key}; +use crate::{ + handle_table_events, handle_text_box_keys, handle_text_box_left_right_keys, matches_key, App, Key, +}; #[cfg(test)] #[path = "add_series_handler_tests.rs"] @@ -126,6 +127,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for AddSeriesHandler<'a, ADD_SERIES_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -609,7 +614,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for AddSeriesHandler<'a, ActiveSonarrBlock::AddSeriesPrompt => { if self.app.data.sonarr_data.selected_block.get_active_block() == ActiveSonarrBlock::AddSeriesConfirmPrompt - && key == DEFAULT_KEYBINDINGS.confirm.key + && matches_key!(confirm, key) { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = diff --git a/src/handlers/sonarr_handlers/library/add_series_handler_tests.rs b/src/handlers/sonarr_handlers/library/add_series_handler_tests.rs index 4919e5c..b1f9bb3 100644 --- a/src/handlers/sonarr_handlers/library/add_series_handler_tests.rs +++ b/src/handlers/sonarr_handlers/library/add_series_handler_tests.rs @@ -2,6 +2,7 @@ mod tests { use bimap::BiMap; use pretty_assertions::{assert_eq, assert_str_eq}; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -1570,7 +1571,7 @@ mod tests { app.data.sonarr_data.add_series_search = Some(HorizontallyScrollableText::default()); AddSeriesHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveSonarrBlock::AddSeriesSearchInput, None, @@ -1585,7 +1586,7 @@ mod tests { .as_ref() .unwrap() .text, - "h" + "a" ); } @@ -1596,7 +1597,7 @@ mod tests { app.data.sonarr_data.add_series_modal = Some(AddSeriesModal::default()); AddSeriesHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveSonarrBlock::AddSeriesTagsInput, None, @@ -1612,7 +1613,7 @@ mod tests { .unwrap() .tags .text, - "h" + "a" ); } @@ -1714,6 +1715,22 @@ mod tests { }); } + #[rstest] + fn test_add_series_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = AddSeriesHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_add_series_search_no_panic_on_none_search_result() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/library/delete_series_handler.rs b/src/handlers/sonarr_handlers/library/delete_series_handler.rs index e12f385..4b515f8 100644 --- a/src/handlers/sonarr_handlers/library/delete_series_handler.rs +++ b/src/handlers/sonarr_handlers/library/delete_series_handler.rs @@ -1,9 +1,10 @@ use crate::models::sonarr_models::DeleteSeriesParams; use crate::network::sonarr_network::SonarrEvent; use crate::{ - app::{key_binding::DEFAULT_KEYBINDINGS, App}, + app::App, event::Key, handlers::{handle_prompt_toggle, KeyEventHandler}, + matches_key, models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, DELETE_SERIES_BLOCKS}, }; @@ -38,6 +39,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for DeleteSeriesHandler< DELETE_SERIES_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -123,7 +128,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for DeleteSeriesHandler< if self.active_sonarr_block == ActiveSonarrBlock::DeleteSeriesPrompt && self.app.data.sonarr_data.selected_block.get_active_block() == ActiveSonarrBlock::DeleteSeriesConfirmPrompt - && self.key == DEFAULT_KEYBINDINGS.confirm.key + && matches_key!(confirm, self.key) { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = diff --git a/src/handlers/sonarr_handlers/library/delete_series_handler_tests.rs b/src/handlers/sonarr_handlers/library/delete_series_handler_tests.rs index cecdcbe..e3c1601 100644 --- a/src/handlers/sonarr_handlers/library/delete_series_handler_tests.rs +++ b/src/handlers/sonarr_handlers/library/delete_series_handler_tests.rs @@ -1,6 +1,7 @@ #[cfg(test)] mod tests { use pretty_assertions::assert_eq; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -320,6 +321,22 @@ mod tests { }); } + #[rstest] + fn test_delete_series_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = DeleteSeriesHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_build_delete_series_params() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/library/edit_series_handler.rs b/src/handlers/sonarr_handlers/library/edit_series_handler.rs index c8047e5..eb7667e 100644 --- a/src/handlers/sonarr_handlers/library/edit_series_handler.rs +++ b/src/handlers/sonarr_handlers/library/edit_series_handler.rs @@ -1,4 +1,3 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; use crate::handlers::{handle_prompt_toggle, KeyEventHandler}; @@ -7,7 +6,7 @@ use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, EDIT_S use crate::models::sonarr_models::EditSeriesParams; use crate::models::Scrollable; use crate::network::sonarr_network::SonarrEvent; -use crate::{handle_text_box_keys, handle_text_box_left_right_keys}; +use crate::{handle_text_box_keys, handle_text_box_left_right_keys, matches_key}; #[cfg(test)] #[path = "edit_series_handler_tests.rs"] @@ -83,6 +82,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for EditSeriesHandler<'a EDIT_SERIES_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -450,7 +453,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for EditSeriesHandler<'a ActiveSonarrBlock::EditSeriesPrompt => { if self.app.data.sonarr_data.selected_block.get_active_block() == ActiveSonarrBlock::EditSeriesConfirmPrompt - && key == DEFAULT_KEYBINDINGS.confirm.key + && matches_key!(confirm, key) { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = diff --git a/src/handlers/sonarr_handlers/library/edit_series_handler_tests.rs b/src/handlers/sonarr_handlers/library/edit_series_handler_tests.rs index 6633c55..82e6464 100644 --- a/src/handlers/sonarr_handlers/library/edit_series_handler_tests.rs +++ b/src/handlers/sonarr_handlers/library/edit_series_handler_tests.rs @@ -2,6 +2,7 @@ mod tests { use bimap::BiMap; use pretty_assertions::{assert_eq, assert_str_eq}; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -1243,7 +1244,7 @@ mod tests { app.data.sonarr_data.edit_series_modal = Some(EditSeriesModal::default()); EditSeriesHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveSonarrBlock::EditSeriesPathInput, None, @@ -1259,7 +1260,7 @@ mod tests { .unwrap() .path .text, - "h" + "a" ); } @@ -1270,7 +1271,7 @@ mod tests { app.data.sonarr_data.edit_series_modal = Some(EditSeriesModal::default()); EditSeriesHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveSonarrBlock::EditSeriesTagsInput, None, @@ -1286,7 +1287,7 @@ mod tests { .unwrap() .tags .text, - "h" + "a" ); } @@ -1368,6 +1369,22 @@ mod tests { }); } + #[rstest] + fn test_edit_series_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = EditSeriesHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_build_edit_series_params() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/library/episode_details_handler.rs b/src/handlers/sonarr_handlers/library/episode_details_handler.rs index 36370aa..4026e62 100644 --- a/src/handlers/sonarr_handlers/library/episode_details_handler.rs +++ b/src/handlers/sonarr_handlers/library/episode_details_handler.rs @@ -1,13 +1,12 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; -use crate::handle_table_events; use crate::handlers::sonarr_handlers::library::season_details_handler::releases_sorting_options; use crate::handlers::table_handler::TableHandlingConfig; use crate::handlers::{handle_prompt_toggle, KeyEventHandler}; use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, EPISODE_DETAILS_BLOCKS}; use crate::models::sonarr_models::{SonarrHistoryItem, SonarrRelease, SonarrReleaseDownloadBody}; use crate::network::sonarr_network::SonarrEvent; +use crate::{handle_table_events, matches_key}; #[cfg(test)] #[path = "episode_details_handler_tests.rs"] @@ -88,6 +87,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for EpisodeDetailsHandle EPISODE_DETAILS_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -142,7 +145,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for EpisodeDetailsHandle | ActiveSonarrBlock::EpisodeHistory | ActiveSonarrBlock::EpisodeFile | ActiveSonarrBlock::ManualEpisodeSearch => match self.key { - _ if self.key == DEFAULT_KEYBINDINGS.left.key => { + _ if matches_key!(left, self.key) => { self .app .data @@ -170,7 +173,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for EpisodeDetailsHandle .get_active_route(), ); } - _ if self.key == DEFAULT_KEYBINDINGS.right.key => { + _ if matches_key!(right, self.key) => { self .app .data @@ -306,21 +309,19 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for EpisodeDetailsHandle | ActiveSonarrBlock::EpisodeHistory | ActiveSonarrBlock::EpisodeFile | ActiveSonarrBlock::ManualEpisodeSearch => match self.key { - _ if self.key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, self.key) => { self .app .pop_and_push_navigation_stack(self.active_sonarr_block.into()); } - _ if self.key == DEFAULT_KEYBINDINGS.auto_search.key => { + _ if matches_key!(auto_search, self.key) => { self .app .push_navigation_stack(ActiveSonarrBlock::AutomaticallySearchEpisodePrompt.into()); } _ => (), }, - ActiveSonarrBlock::AutomaticallySearchEpisodePrompt - if key == DEFAULT_KEYBINDINGS.confirm.key => - { + ActiveSonarrBlock::AutomaticallySearchEpisodePrompt if matches_key!(confirm, key) => { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = Some( SonarrEvent::TriggerAutomaticEpisodeSearch(self.extract_episode_id()), @@ -328,9 +329,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for EpisodeDetailsHandle self.app.pop_navigation_stack(); } - ActiveSonarrBlock::ManualEpisodeSearchConfirmPrompt - if key == DEFAULT_KEYBINDINGS.confirm.key => - { + ActiveSonarrBlock::ManualEpisodeSearchConfirmPrompt if matches_key!(confirm, key) => { if self.app.data.sonarr_data.prompt_confirm { let SonarrRelease { guid, indexer_id, .. diff --git a/src/handlers/sonarr_handlers/library/episode_details_handler_tests.rs b/src/handlers/sonarr_handlers/library/episode_details_handler_tests.rs index ffe2761..72cece8 100644 --- a/src/handlers/sonarr_handlers/library/episode_details_handler_tests.rs +++ b/src/handlers/sonarr_handlers/library/episode_details_handler_tests.rs @@ -625,6 +625,22 @@ mod tests { }); } + #[rstest] + fn test_episode_details_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = EpisodeDetailsHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_extract_episode_id() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/library/library_handler_tests.rs b/src/handlers/sonarr_handlers/library/library_handler_tests.rs index 8466193..d26046e 100644 --- a/src/handlers/sonarr_handlers/library/library_handler_tests.rs +++ b/src/handlers/sonarr_handlers/library/library_handler_tests.rs @@ -827,6 +827,22 @@ mod tests { }); } + #[rstest] + fn test_library_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = LibraryHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_library_handler_not_ready_when_loading() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/library/mod.rs b/src/handlers/sonarr_handlers/library/mod.rs index 870876e..068b986 100644 --- a/src/handlers/sonarr_handlers/library/mod.rs +++ b/src/handlers/sonarr_handlers/library/mod.rs @@ -8,6 +8,7 @@ use crate::{ event::Key, handle_table_events, handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler}, + matches_key, models::{ servarr_data::sonarr::sonarr_data::{ ActiveSonarrBlock, DELETE_SERIES_SELECTION_BLOCKS, EDIT_SERIES_SELECTION_BLOCKS, @@ -21,7 +22,6 @@ use crate::{ }; use super::handle_change_tab_left_right_keys; -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::handlers::sonarr_handlers::library::episode_details_handler::EpisodeDetailsHandler; use crate::handlers::sonarr_handlers::library::season_details_handler::SeasonDetailsHandler; use crate::handlers::sonarr_handlers::library::series_details_handler::SeriesDetailsHandler; @@ -102,6 +102,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for LibraryHandler<'a, ' || LIBRARY_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -182,7 +186,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for LibraryHandler<'a, ' let key = self.key; match self.active_sonarr_block { ActiveSonarrBlock::Series => match self.key { - _ if key == DEFAULT_KEYBINDINGS.edit.key => { + _ if matches_key!(edit, key) => { self.app.push_navigation_stack( ( ActiveSonarrBlock::EditSeriesPrompt, @@ -194,25 +198,25 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for LibraryHandler<'a, ' self.app.data.sonarr_data.selected_block = BlockSelectionState::new(EDIT_SERIES_SELECTION_BLOCKS); } - _ if key == DEFAULT_KEYBINDINGS.add.key => { + _ if matches_key!(add, key) => { self .app .push_navigation_stack(ActiveSonarrBlock::AddSeriesSearchInput.into()); self.app.data.sonarr_data.add_series_search = Some(HorizontallyScrollableText::default()); self.app.should_ignore_quit_key = true; } - _ if key == DEFAULT_KEYBINDINGS.update.key => { + _ if matches_key!(update, key) => { self .app .push_navigation_stack(ActiveSonarrBlock::UpdateAllSeriesPrompt.into()); } - _ if key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, key) => { self.app.should_refresh = true; } _ => (), }, ActiveSonarrBlock::UpdateAllSeriesPrompt => { - if key == DEFAULT_KEYBINDINGS.confirm.key { + if matches_key!(confirm, key) { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::UpdateAllSeries); diff --git a/src/handlers/sonarr_handlers/library/season_details_handler.rs b/src/handlers/sonarr_handlers/library/season_details_handler.rs index bf041b5..d3cf187 100644 --- a/src/handlers/sonarr_handlers/library/season_details_handler.rs +++ b/src/handlers/sonarr_handlers/library/season_details_handler.rs @@ -1,7 +1,5 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; -use crate::handle_table_events; use crate::handlers::sonarr_handlers::history::history_sorting_options; use crate::handlers::table_handler::TableHandlingConfig; use crate::handlers::{handle_prompt_toggle, KeyEventHandler}; @@ -12,6 +10,7 @@ use crate::models::sonarr_models::{ }; use crate::models::stateful_table::SortOption; use crate::network::sonarr_network::SonarrEvent; +use crate::{handle_table_events, matches_key}; use serde_json::Number; #[cfg(test)] @@ -140,6 +139,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeasonDetailsHandler SEASON_DETAILS_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -193,7 +196,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeasonDetailsHandler ActiveSonarrBlock::SeasonDetails | ActiveSonarrBlock::SeasonHistory | ActiveSonarrBlock::ManualSeasonSearch => match self.key { - _ if self.key == DEFAULT_KEYBINDINGS.left.key => { + _ if matches_key!(left, self.key) => { self .app .data @@ -215,7 +218,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeasonDetailsHandler .get_active_route(), ); } - _ if self.key == DEFAULT_KEYBINDINGS.right.key => { + _ if matches_key!(right, self.key) => { self .app .data @@ -378,7 +381,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeasonDetailsHandler fn handle_char_key_event(&mut self) { let key = self.key; match self.active_sonarr_block { - ActiveSonarrBlock::SeasonDetails if self.key == DEFAULT_KEYBINDINGS.toggle_monitoring.key => { + ActiveSonarrBlock::SeasonDetails if matches_key!(toggle_monitoring, self.key) => { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = Some( SonarrEvent::ToggleEpisodeMonitoring(self.extract_episode_id()), @@ -391,21 +394,19 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeasonDetailsHandler ActiveSonarrBlock::SeasonDetails | ActiveSonarrBlock::SeasonHistory | ActiveSonarrBlock::ManualSeasonSearch => match self.key { - _ if self.key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, self.key) => { self .app .pop_and_push_navigation_stack(self.active_sonarr_block.into()); } - _ if self.key == DEFAULT_KEYBINDINGS.auto_search.key => { + _ if matches_key!(auto_search, self.key) => { self .app .push_navigation_stack(ActiveSonarrBlock::AutomaticallySearchSeasonPrompt.into()); } _ => (), }, - ActiveSonarrBlock::AutomaticallySearchSeasonPrompt - if key == DEFAULT_KEYBINDINGS.confirm.key => - { + ActiveSonarrBlock::AutomaticallySearchSeasonPrompt if matches_key!(confirm, key) => { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = Some( SonarrEvent::TriggerAutomaticSeasonSearch(self.extract_series_id_season_number_tuple()), @@ -413,7 +414,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeasonDetailsHandler self.app.pop_navigation_stack(); } - ActiveSonarrBlock::DeleteEpisodeFilePrompt if key == DEFAULT_KEYBINDINGS.confirm.key => { + ActiveSonarrBlock::DeleteEpisodeFilePrompt if matches_key!(confirm, key) => { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::DeleteEpisodeFile( self.extract_episode_file_id(), @@ -421,9 +422,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeasonDetailsHandler self.app.pop_navigation_stack(); } - ActiveSonarrBlock::ManualSeasonSearchConfirmPrompt - if key == DEFAULT_KEYBINDINGS.confirm.key => - { + ActiveSonarrBlock::ManualSeasonSearchConfirmPrompt if matches_key!(confirm, key) => { self.app.data.sonarr_data.prompt_confirm = true; let SonarrRelease { guid, indexer_id, .. diff --git a/src/handlers/sonarr_handlers/library/season_details_handler_tests.rs b/src/handlers/sonarr_handlers/library/season_details_handler_tests.rs index 3751514..ec3f25c 100644 --- a/src/handlers/sonarr_handlers/library/season_details_handler_tests.rs +++ b/src/handlers/sonarr_handlers/library/season_details_handler_tests.rs @@ -789,6 +789,22 @@ mod tests { }); } + #[rstest] + fn test_season_details_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = SeasonDetailsHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_extract_episode_file_id() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/library/series_details_handler.rs b/src/handlers/sonarr_handlers/library/series_details_handler.rs index 52beadb..723f629 100644 --- a/src/handlers/sonarr_handlers/library/series_details_handler.rs +++ b/src/handlers/sonarr_handlers/library/series_details_handler.rs @@ -1,7 +1,5 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; -use crate::handle_table_events; use crate::handlers::sonarr_handlers::history::history_sorting_options; use crate::handlers::table_handler::TableHandlingConfig; use crate::handlers::{handle_prompt_toggle, KeyEventHandler}; @@ -11,6 +9,7 @@ use crate::models::servarr_data::sonarr::sonarr_data::{ use crate::models::sonarr_models::{Season, SonarrHistoryItem}; use crate::models::BlockSelectionState; use crate::network::sonarr_network::SonarrEvent; +use crate::{handle_table_events, matches_key}; #[cfg(test)] #[path = "series_details_handler_tests.rs"] @@ -91,6 +90,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeriesDetailsHandler SERIES_DETAILS_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -130,7 +133,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeriesDetailsHandler fn handle_left_right_action(&mut self) { match self.active_sonarr_block { ActiveSonarrBlock::SeriesDetails | ActiveSonarrBlock::SeriesHistory => match self.key { - _ if self.key == DEFAULT_KEYBINDINGS.left.key => { + _ if matches_key!(left, self.key) => { self.app.data.sonarr_data.series_info_tabs.previous(); self.app.pop_and_push_navigation_stack( self @@ -141,7 +144,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeriesDetailsHandler .get_active_route(), ); } - _ if self.key == DEFAULT_KEYBINDINGS.right.key => { + _ if matches_key!(right, self.key) => { self.app.data.sonarr_data.series_info_tabs.next(); self.app.pop_and_push_navigation_stack( self @@ -250,20 +253,20 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeriesDetailsHandler let key = self.key; match self.active_sonarr_block { ActiveSonarrBlock::SeriesDetails => match self.key { - _ if key == DEFAULT_KEYBINDINGS.refresh.key => self + _ if matches_key!(refresh, key) => self .app .pop_and_push_navigation_stack(self.active_sonarr_block.into()), - _ if key == DEFAULT_KEYBINDINGS.auto_search.key => { + _ if matches_key!(auto_search, key) => { self .app .push_navigation_stack(ActiveSonarrBlock::AutomaticallySearchSeriesPrompt.into()); } - _ if key == DEFAULT_KEYBINDINGS.update.key => { + _ if matches_key!(update, key) => { self .app .push_navigation_stack(ActiveSonarrBlock::UpdateAndScanSeriesPrompt.into()); } - _ if key == DEFAULT_KEYBINDINGS.edit.key => { + _ if matches_key!(edit, key) => { self.app.push_navigation_stack( ( ActiveSonarrBlock::EditSeriesPrompt, @@ -275,7 +278,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeriesDetailsHandler self.app.data.sonarr_data.selected_block = BlockSelectionState::new(EDIT_SERIES_SELECTION_BLOCKS); } - _ if key == DEFAULT_KEYBINDINGS.toggle_monitoring.key => { + _ if matches_key!(toggle_monitoring, key) => { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = Some( SonarrEvent::ToggleSeasonMonitoring(self.extract_series_id_season_number_tuple()), @@ -288,15 +291,15 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeriesDetailsHandler _ => (), }, ActiveSonarrBlock::SeriesHistory => match self.key { - _ if key == DEFAULT_KEYBINDINGS.refresh.key => self + _ if matches_key!(refresh, key) => self .app .pop_and_push_navigation_stack(self.active_sonarr_block.into()), - _ if key == DEFAULT_KEYBINDINGS.auto_search.key => { + _ if matches_key!(auto_search, key) => { self .app .push_navigation_stack(ActiveSonarrBlock::AutomaticallySearchSeriesPrompt.into()); } - _ if key == DEFAULT_KEYBINDINGS.edit.key => { + _ if matches_key!(edit, key) => { self.app.push_navigation_stack( ( ActiveSonarrBlock::EditSeriesPrompt, @@ -308,7 +311,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeriesDetailsHandler self.app.data.sonarr_data.selected_block = BlockSelectionState::new(EDIT_SERIES_SELECTION_BLOCKS); } - _ if key == DEFAULT_KEYBINDINGS.update.key => { + _ if matches_key!(update, key) => { self .app .push_navigation_stack(ActiveSonarrBlock::UpdateAndScanSeriesPrompt.into()); @@ -316,7 +319,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeriesDetailsHandler _ => (), }, ActiveSonarrBlock::AutomaticallySearchSeriesPrompt => { - if key == DEFAULT_KEYBINDINGS.confirm.key { + if matches_key!(confirm, key) { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = Some( SonarrEvent::TriggerAutomaticSeriesSearch(self.extract_series_id()), diff --git a/src/handlers/sonarr_handlers/library/series_details_handler_tests.rs b/src/handlers/sonarr_handlers/library/series_details_handler_tests.rs index cb93842..c534c2e 100644 --- a/src/handlers/sonarr_handlers/library/series_details_handler_tests.rs +++ b/src/handlers/sonarr_handlers/library/series_details_handler_tests.rs @@ -611,6 +611,22 @@ mod tests { }); } + #[rstest] + fn test_series_details_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = SeriesDetailsHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_extract_series_id_season_number_tuple() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/mod.rs b/src/handlers/sonarr_handlers/mod.rs index 2cecd0d..100b935 100644 --- a/src/handlers/sonarr_handlers/mod.rs +++ b/src/handlers/sonarr_handlers/mod.rs @@ -7,9 +7,7 @@ use root_folders::RootFoldersHandler; use system::SystemHandler; use crate::{ - app::{key_binding::DEFAULT_KEYBINDINGS, App}, - event::Key, - models::servarr_data::sonarr::sonarr_data::ActiveSonarrBlock, + app::App, event::Key, matches_key, models::servarr_data::sonarr::sonarr_data::ActiveSonarrBlock, }; use super::KeyEventHandler; @@ -69,6 +67,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SonarrHandler<'a, 'b true } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -113,11 +115,11 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SonarrHandler<'a, 'b pub fn handle_change_tab_left_right_keys(app: &mut App<'_>, key: Key) { let key_ref = key; match key_ref { - _ if key == DEFAULT_KEYBINDINGS.left.key => { + _ if matches_key!(left, key, app.should_ignore_quit_key) => { app.data.sonarr_data.main_tabs.previous(); app.pop_and_push_navigation_stack(app.data.sonarr_data.main_tabs.get_active_route()); } - _ if key == DEFAULT_KEYBINDINGS.right.key => { + _ if matches_key!(right, key, app.should_ignore_quit_key) => { app.data.sonarr_data.main_tabs.next(); app.pop_and_push_navigation_stack(app.data.sonarr_data.main_tabs.get_active_route()); } diff --git a/src/handlers/sonarr_handlers/root_folders/mod.rs b/src/handlers/sonarr_handlers/root_folders/mod.rs index 5bd51cb..4aceb14 100644 --- a/src/handlers/sonarr_handlers/root_folders/mod.rs +++ b/src/handlers/sonarr_handlers/root_folders/mod.rs @@ -1,4 +1,3 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; use crate::handlers::sonarr_handlers::handle_change_tab_left_right_keys; @@ -8,7 +7,9 @@ use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, ROOT_F use crate::models::servarr_models::{AddRootFolderBody, RootFolder}; use crate::models::HorizontallyScrollableText; use crate::network::sonarr_network::SonarrEvent; -use crate::{handle_table_events, handle_text_box_keys, handle_text_box_left_right_keys}; +use crate::{ + handle_table_events, handle_text_box_keys, handle_text_box_left_right_keys, matches_key, +}; #[cfg(test)] #[path = "root_folders_handler_tests.rs"] @@ -66,6 +67,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for RootFoldersHandler<' ROOT_FOLDERS_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -193,10 +198,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for RootFoldersHandler<' let key = self.key; match self.active_sonarr_block { ActiveSonarrBlock::RootFolders => match self.key { - _ if key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, key) => { self.app.should_refresh = true; } - _ if key == DEFAULT_KEYBINDINGS.add.key => { + _ if matches_key!(add, key) => { self .app .push_navigation_stack(ActiveSonarrBlock::AddRootFolderPrompt.into()); @@ -213,7 +218,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for RootFoldersHandler<' ) } ActiveSonarrBlock::DeleteRootFolderPrompt => { - if key == DEFAULT_KEYBINDINGS.confirm.key { + if matches_key!(confirm, key) { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::DeleteRootFolder(self.extract_root_folder_id())); diff --git a/src/handlers/sonarr_handlers/root_folders/root_folders_handler_tests.rs b/src/handlers/sonarr_handlers/root_folders/root_folders_handler_tests.rs index a18efac..5719db2 100644 --- a/src/handlers/sonarr_handlers/root_folders/root_folders_handler_tests.rs +++ b/src/handlers/sonarr_handlers/root_folders/root_folders_handler_tests.rs @@ -1,6 +1,7 @@ #[cfg(test)] mod tests { use pretty_assertions::assert_eq; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -600,7 +601,7 @@ mod tests { app.data.sonarr_data.edit_root_folder = Some(HorizontallyScrollableText::default()); RootFoldersHandler::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveSonarrBlock::AddRootFolderPrompt, None, @@ -609,7 +610,7 @@ mod tests { assert_str_eq!( app.data.sonarr_data.edit_root_folder.as_ref().unwrap().text, - "h" + "a" ); } @@ -655,6 +656,22 @@ mod tests { }) } + #[rstest] + fn test_root_folders_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = RootFoldersHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_extract_root_folder_id() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/sonarr_handler_tests.rs b/src/handlers/sonarr_handlers/sonarr_handler_tests.rs index b55d07b..4edb3dd 100644 --- a/src/handlers/sonarr_handlers/sonarr_handler_tests.rs +++ b/src/handlers/sonarr_handlers/sonarr_handler_tests.rs @@ -9,6 +9,7 @@ mod tests { use crate::test_handler_delegation; use pretty_assertions::assert_eq; use rstest::rstest; + use strum::IntoEnumIterator; #[rstest] #[case(0, ActiveSonarrBlock::System, ActiveSonarrBlock::Downloads)] @@ -45,6 +46,77 @@ mod tests { assert_eq!(app.get_current_route(), right_block.into()); } + #[rstest] + #[case(0, ActiveSonarrBlock::System, ActiveSonarrBlock::Downloads)] + #[case(1, ActiveSonarrBlock::Series, ActiveSonarrBlock::Blocklist)] + #[case(2, ActiveSonarrBlock::Downloads, ActiveSonarrBlock::History)] + #[case(3, ActiveSonarrBlock::Blocklist, ActiveSonarrBlock::RootFolders)] + #[case(4, ActiveSonarrBlock::History, ActiveSonarrBlock::Indexers)] + #[case(5, ActiveSonarrBlock::RootFolders, ActiveSonarrBlock::System)] + #[case(6, ActiveSonarrBlock::Indexers, ActiveSonarrBlock::Series)] + fn test_sonarr_handler_change_tab_left_right_keys_alt_navigation( + #[case] index: usize, + #[case] left_block: ActiveSonarrBlock, + #[case] right_block: ActiveSonarrBlock, + ) { + let mut app = App::test_default(); + app.data.sonarr_data.main_tabs.set_index(index); + + handle_change_tab_left_right_keys(&mut app, DEFAULT_KEYBINDINGS.left.alt.unwrap()); + + assert_eq!( + app.data.sonarr_data.main_tabs.get_active_route(), + left_block.into() + ); + assert_eq!(app.get_current_route(), left_block.into()); + + app.data.sonarr_data.main_tabs.set_index(index); + + handle_change_tab_left_right_keys(&mut app, DEFAULT_KEYBINDINGS.right.alt.unwrap()); + + assert_eq!( + app.data.sonarr_data.main_tabs.get_active_route(), + right_block.into() + ); + assert_eq!(app.get_current_route(), right_block.into()); + } + + #[rstest] + #[case(0, ActiveSonarrBlock::Series)] + #[case(1, ActiveSonarrBlock::Downloads)] + #[case(2, ActiveSonarrBlock::Blocklist)] + #[case(3, ActiveSonarrBlock::History)] + #[case(4, ActiveSonarrBlock::RootFolders)] + #[case(5, ActiveSonarrBlock::Indexers)] + #[case(6, ActiveSonarrBlock::System)] + fn test_sonarr_handler_change_tab_left_right_keys_alt_navigation_no_op_when_ignoring_quit_key( + #[case] index: usize, + #[case] block: ActiveSonarrBlock, + ) { + let mut app = App::test_default(); + app.push_navigation_stack(block.into()); + app.should_ignore_quit_key = true; + app.data.sonarr_data.main_tabs.set_index(index); + + handle_change_tab_left_right_keys(&mut app, DEFAULT_KEYBINDINGS.left.alt.unwrap()); + + assert_eq!( + app.data.sonarr_data.main_tabs.get_active_route(), + block.into() + ); + assert_eq!(app.get_current_route(), block.into()); + + app.data.sonarr_data.main_tabs.set_index(index); + + handle_change_tab_left_right_keys(&mut app, DEFAULT_KEYBINDINGS.right.alt.unwrap()); + + assert_eq!( + app.data.sonarr_data.main_tabs.get_active_route(), + block.into() + ); + assert_eq!(app.get_current_route(), block.into()); + } + #[rstest] fn test_delegates_library_blocks_to_library_handler( #[values( @@ -59,10 +131,10 @@ mod tests { ActiveSonarrBlock::AddSeriesSelectRootFolder, ActiveSonarrBlock::AddSeriesSelectSeriesType, ActiveSonarrBlock::AddSeriesTagsInput, - // ActiveSonarrBlock::AutomaticallySearchEpisodePrompt, - // ActiveSonarrBlock::AutomaticallySearchSeasonPrompt, - // ActiveSonarrBlock::AutomaticallySearchSeriesPrompt, - // ActiveSonarrBlock::DeleteEpisodeFilePrompt, + ActiveSonarrBlock::AutomaticallySearchEpisodePrompt, + ActiveSonarrBlock::AutomaticallySearchSeasonPrompt, + ActiveSonarrBlock::AutomaticallySearchSeriesPrompt, + ActiveSonarrBlock::DeleteEpisodeFilePrompt, ActiveSonarrBlock::DeleteSeriesPrompt, ActiveSonarrBlock::EditSeriesPrompt, ActiveSonarrBlock::EditSeriesPathInput, @@ -70,39 +142,36 @@ mod tests { ActiveSonarrBlock::EditSeriesSelectQualityProfile, ActiveSonarrBlock::EditSeriesSelectLanguageProfile, ActiveSonarrBlock::EditSeriesTagsInput, - // ActiveSonarrBlock::EpisodeDetails, - // ActiveSonarrBlock::EpisodeFile, - // ActiveSonarrBlock::EpisodeHistory, - // ActiveSonarrBlock::EpisodesSortPrompt, - // ActiveSonarrBlock::FilterEpisodes, - // ActiveSonarrBlock::FilterEpisodesError, + ActiveSonarrBlock::EpisodeDetails, + ActiveSonarrBlock::EpisodeFile, + ActiveSonarrBlock::EpisodeHistory, ActiveSonarrBlock::FilterSeries, ActiveSonarrBlock::FilterSeriesError, - // ActiveSonarrBlock::FilterSeriesHistory, - // ActiveSonarrBlock::FilterSeriesHistoryError, - // ActiveSonarrBlock::ManualEpisodeSearch, - // ActiveSonarrBlock::ManualEpisodeSearchConfirmPrompt, - // ActiveSonarrBlock::ManualEpisodeSearchSortPrompt, - // ActiveSonarrBlock::ManualSeasonSearch, - // ActiveSonarrBlock::ManualSeasonSearchConfirmPrompt, - // ActiveSonarrBlock::ManualSeasonSearchSortPrompt, - // ActiveSonarrBlock::SearchEpisodes, - // ActiveSonarrBlock::SearchEpisodesError, - // ActiveSonarrBlock::SearchSeason, - // ActiveSonarrBlock::SearchSeasonError, + ActiveSonarrBlock::FilterSeriesHistory, + ActiveSonarrBlock::FilterSeriesHistoryError, + ActiveSonarrBlock::ManualEpisodeSearch, + ActiveSonarrBlock::ManualEpisodeSearchConfirmPrompt, + ActiveSonarrBlock::ManualEpisodeSearchSortPrompt, + ActiveSonarrBlock::ManualSeasonSearch, + ActiveSonarrBlock::ManualSeasonSearchConfirmPrompt, + ActiveSonarrBlock::ManualSeasonSearchSortPrompt, + ActiveSonarrBlock::SearchEpisodes, + ActiveSonarrBlock::SearchEpisodesError, + ActiveSonarrBlock::SearchSeason, + ActiveSonarrBlock::SearchSeasonError, ActiveSonarrBlock::SearchSeries, ActiveSonarrBlock::SearchSeriesError, - // ActiveSonarrBlock::SearchSeriesHistory, - // ActiveSonarrBlock::SearchSeriesHistoryError, - // ActiveSonarrBlock::SeasonDetails, + ActiveSonarrBlock::SearchSeriesHistory, + ActiveSonarrBlock::SearchSeriesHistoryError, + ActiveSonarrBlock::SeasonDetails, ActiveSonarrBlock::Series, - // ActiveSonarrBlock::SeriesDetails, - // ActiveSonarrBlock::SeriesHistory, - // ActiveSonarrBlock::SeriesHistorySortPrompt, + ActiveSonarrBlock::SeriesDetails, + ActiveSonarrBlock::SeriesHistory, + ActiveSonarrBlock::SeriesHistorySortPrompt, ActiveSonarrBlock::SeriesSortPrompt, ActiveSonarrBlock::UpdateAllSeriesPrompt, - // ActiveSonarrBlock::UpdateAndScanSeriesPrompt - // ActiveSonarrBlock::SeriesHistoryDetails, + ActiveSonarrBlock::UpdateAndScanSeriesPrompt, + ActiveSonarrBlock::SeriesHistoryDetails )] active_sonarr_block: ActiveSonarrBlock, ) { @@ -222,4 +291,42 @@ mod tests { active_sonarr_block ); } + + #[test] + fn test_sonarr_handler_accepts() { + ActiveSonarrBlock::iter().for_each(|active_sonarr_block| { + assert!(SonarrHandler::accepts(active_sonarr_block)); + }) + } + + #[rstest] + fn test_sonarr_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = SonarrHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + + #[test] + fn test_sonarr_handler_is_ready() { + let mut app = App::test_default(); + app.is_loading = true; + + let handler = SonarrHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert!(handler.is_ready()); + } } diff --git a/src/handlers/sonarr_handlers/system/mod.rs b/src/handlers/sonarr_handlers/system/mod.rs index 5b1261b..8cf721c 100644 --- a/src/handlers/sonarr_handlers/system/mod.rs +++ b/src/handlers/sonarr_handlers/system/mod.rs @@ -1,9 +1,9 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; use crate::handlers::sonarr_handlers::handle_change_tab_left_right_keys; use crate::handlers::sonarr_handlers::system::system_details_handler::SystemDetailsHandler; use crate::handlers::{handle_clear_errors, KeyEventHandler}; +use crate::matches_key; use crate::models::servarr_data::sonarr::sonarr_data::ActiveSonarrBlock; use crate::models::Scrollable; @@ -35,6 +35,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SystemHandler<'a, 'b SystemDetailsHandler::accepts(active_block) || active_block == ActiveSonarrBlock::System } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -86,15 +90,15 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SystemHandler<'a, 'b if self.active_sonarr_block == ActiveSonarrBlock::System { let key = self.key; match self.key { - _ if key == DEFAULT_KEYBINDINGS.refresh.key => { + _ if matches_key!(refresh, key) => { self.app.should_refresh = true; } - _ if key == DEFAULT_KEYBINDINGS.events.key => { + _ if matches_key!(events, key) => { self .app .push_navigation_stack(ActiveSonarrBlock::SystemQueuedEvents.into()); } - _ if key == DEFAULT_KEYBINDINGS.logs.key => { + _ if matches_key!(logs, key) => { self .app .push_navigation_stack(ActiveSonarrBlock::SystemLogs.into()); @@ -106,12 +110,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SystemHandler<'a, 'b .set_items(self.app.data.sonarr_data.logs.items.to_vec()); self.app.data.sonarr_data.log_details.scroll_to_bottom(); } - _ if key == DEFAULT_KEYBINDINGS.tasks.key => { + _ if matches_key!(tasks, key) => { self .app .push_navigation_stack(ActiveSonarrBlock::SystemTasks.into()); } - _ if key == DEFAULT_KEYBINDINGS.update.key => { + _ if matches_key!(update, key) => { self .app .push_navigation_stack(ActiveSonarrBlock::SystemUpdates.into()); diff --git a/src/handlers/sonarr_handlers/system/system_details_handler.rs b/src/handlers/sonarr_handlers/system/system_details_handler.rs index a9786f6..f309552 100644 --- a/src/handlers/sonarr_handlers/system/system_details_handler.rs +++ b/src/handlers/sonarr_handlers/system/system_details_handler.rs @@ -1,7 +1,7 @@ -use crate::app::key_binding::DEFAULT_KEYBINDINGS; use crate::app::App; use crate::event::Key; use crate::handlers::{handle_prompt_toggle, KeyEventHandler}; +use crate::matches_key; use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, SYSTEM_DETAILS_BLOCKS}; use crate::models::sonarr_models::SonarrTaskName; use crate::models::stateful_list::StatefulList; @@ -36,6 +36,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SystemDetailsHandler SYSTEM_DETAILS_BLOCKS.contains(&active_block) } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -114,7 +118,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SystemDetailsHandler match self.active_sonarr_block { ActiveSonarrBlock::SystemLogs => match self.key { - _ if key == DEFAULT_KEYBINDINGS.left.key => { + _ if matches_key!(left, key) => { self .app .data @@ -124,7 +128,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SystemDetailsHandler .iter() .for_each(|log| log.scroll_right()); } - _ if key == DEFAULT_KEYBINDINGS.right.key => { + _ if matches_key!(right, key) => { self .app .data @@ -178,14 +182,13 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SystemDetailsHandler } fn handle_char_key_event(&mut self) { - if SYSTEM_DETAILS_BLOCKS.contains(&self.active_sonarr_block) - && self.key == DEFAULT_KEYBINDINGS.refresh.key + if SYSTEM_DETAILS_BLOCKS.contains(&self.active_sonarr_block) && matches_key!(refresh, self.key) { self.app.should_refresh = true; } if self.active_sonarr_block == ActiveSonarrBlock::SystemTaskStartConfirmPrompt - && self.key == DEFAULT_KEYBINDINGS.confirm.key + && matches_key!(confirm, self.key) { self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm_action = diff --git a/src/handlers/sonarr_handlers/system/system_details_handler_tests.rs b/src/handlers/sonarr_handlers/system/system_details_handler_tests.rs index 18657af..eb7817b 100644 --- a/src/handlers/sonarr_handlers/system/system_details_handler_tests.rs +++ b/src/handlers/sonarr_handlers/system/system_details_handler_tests.rs @@ -1,6 +1,7 @@ #[cfg(test)] mod tests { use pretty_assertions::{assert_eq, assert_str_eq}; + use rstest::rstest; use strum::IntoEnumIterator; use crate::app::key_binding::DEFAULT_KEYBINDINGS; @@ -960,6 +961,22 @@ mod tests { }) } + #[rstest] + fn test_system_details_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = SystemDetailsHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_extract_task_name() { let mut app = App::test_default(); diff --git a/src/handlers/sonarr_handlers/system/system_handler_tests.rs b/src/handlers/sonarr_handlers/system/system_handler_tests.rs index 9b866de..e772f4d 100644 --- a/src/handlers/sonarr_handlers/system/system_handler_tests.rs +++ b/src/handlers/sonarr_handlers/system/system_handler_tests.rs @@ -456,6 +456,22 @@ mod tests { }) } + #[rstest] + fn test_system_handler_ignore_alt_navigation( + #[values(true, false)] should_ignore_quit_key: bool, + ) { + let mut app = App::test_default(); + app.should_ignore_quit_key = should_ignore_quit_key; + let handler = SystemHandler::new( + DEFAULT_KEYBINDINGS.esc.key, + &mut app, + ActiveSonarrBlock::default(), + None, + ); + + assert_eq!(handler.ignore_alt_navigation(), should_ignore_quit_key); + } + #[test] fn test_system_handler_is_not_ready_when_loading() { let mut app = App::test_default(); diff --git a/src/handlers/table_handler.rs b/src/handlers/table_handler.rs index 56b77b1..884f413 100644 --- a/src/handlers/table_handler.rs +++ b/src/handlers/table_handler.rs @@ -42,17 +42,17 @@ macro_rules! handle_table_events { fn [](&mut $self, config: $crate::handlers::table_handler::TableHandlingConfig<$row>) -> bool { if $self.is_ready() { match $self.key { - _ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.up.key => $self.[](config), - _ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.down.key => $self.[](config), - _ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.home.key => $self.[](config), - _ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.end.key => $self.[](config), - _ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.left.key - || $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.right.key => + _ if $crate::matches_key!(up, $self.key, $self.ignore_alt_navigation()) => $self.[](config), + _ if $crate::matches_key!(down, $self.key, $self.ignore_alt_navigation()) => $self.[](config), + _ if $crate::matches_key!(home, $self.key) => $self.[](config), + _ if $crate::matches_key!(end, $self.key) => $self.[](config), + _ if $crate::matches_key!(left, $self.key, $self.ignore_alt_navigation()) + || $crate::matches_key!(right, $self.key, $self.ignore_alt_navigation()) => { $self.[](config) } - _ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.submit.key => $self.[](config), - _ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.esc.key => $self.[](config), + _ if $crate::matches_key!(submit, $self.key) => $self.[](config), + _ if $crate::matches_key!(esc, $self.key) => $self.[](config), _ if config.searching_block.is_some() && $self.app.get_current_route() == *config.searching_block.as_ref().unwrap() => { @@ -63,11 +63,11 @@ macro_rules! handle_table_events { { $self.[]() } - _ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.filter.key + _ if $crate::matches_key!(filter, $self.key) && config.filtering_block.is_some() => $self.[](config), - _ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.search.key + _ if $crate::matches_key!(search, $self.key) && config.searching_block.is_some() => $self.[](config), - _ if $self.key == $crate::app::key_binding::DEFAULT_KEYBINDINGS.sort.key + _ if $crate::matches_key!(sort, $self.key) && config.sorting_block.is_some() => $self.[](config), _ => false, } diff --git a/src/handlers/table_handler_tests.rs b/src/handlers/table_handler_tests.rs index b7119fb..0418557 100644 --- a/src/handlers/table_handler_tests.rs +++ b/src/handlers/table_handler_tests.rs @@ -48,6 +48,10 @@ mod tests { true } + fn ignore_alt_navigation(&self) -> bool { + self.app.should_ignore_quit_key + } + fn new( key: Key, app: &'a mut App<'b>, @@ -1040,7 +1044,7 @@ mod tests { app.data.radarr_data.movies.search = Some(HorizontallyScrollableText::default()); TableHandlerUnit::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveRadarrBlock::SearchMovie, None, @@ -1049,7 +1053,7 @@ mod tests { assert_str_eq!( app.data.radarr_data.movies.search.as_ref().unwrap().text, - "h" + "a" ); } @@ -1065,7 +1069,7 @@ mod tests { app.data.radarr_data.movies.filter = Some(HorizontallyScrollableText::default()); TableHandlerUnit::new( - Key::Char('h'), + Key::Char('a'), &mut app, ActiveRadarrBlock::FilterMovies, None, @@ -1074,7 +1078,7 @@ mod tests { assert_str_eq!( app.data.radarr_data.movies.filter.as_ref().unwrap().text, - "h" + "a" ); }