From 1404666e12ccc80592c72bbc13b346e8a44e48e5 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Thu, 12 Sep 2024 21:09:55 +0200 Subject: [PATCH] Verbosity --- src/tui/app/machine/mod.rs | 28 ++++++++++++------- src/tui/app/mod.rs | 56 ++++++++++++++++++++++++++------------ src/tui/handler.rs | 56 +++++++++++++++++++++++++++----------- 3 files changed, 96 insertions(+), 44 deletions(-) diff --git a/src/tui/app/machine/mod.rs b/src/tui/app/machine/mod.rs index 70ae5b4..54afa4e 100644 --- a/src/tui/app/machine/mod.rs +++ b/src/tui/app/machine/mod.rs @@ -97,14 +97,14 @@ impl App { } impl IAppInteract for App { - type BS = AppMachine; - type IS = AppMachine; - type RS = AppMachine; - type SS = AppMachine; - type FS = AppMachine; - type MS = AppMachine; - type ES = AppMachine; - type CS = AppMachine; + type BrowseState = AppMachine; + type InfoState = AppMachine; + type ReloadState = AppMachine; + type SearchState = AppMachine; + type FetchState = AppMachine; + type MatchesState = AppMachine; + type ErrorState = AppMachine; + type CriticalState = AppMachine; fn is_running(&self) -> bool { self.inner_ref().running @@ -117,8 +117,16 @@ impl IAppInteract for App { fn state( self, - ) -> AppState - { + ) -> AppState< + Self::BrowseState, + Self::InfoState, + Self::ReloadState, + Self::SearchState, + Self::FetchState, + Self::MatchesState, + Self::ErrorState, + Self::CriticalState, + > { self } } diff --git a/src/tui/app/mod.rs b/src/tui/app/mod.rs index 866f9a0..b2f17fe 100644 --- a/src/tui/app/mod.rs +++ b/src/tui/app/mod.rs @@ -8,26 +8,37 @@ use musichoard::collection::{album::AlbumMeta, artist::ArtistMeta, Collection}; use crate::tui::lib::interface::musicbrainz::Match; -pub enum AppState { - Browse(BS), - Info(IS), - Reload(RS), - Search(SS), - Fetch(FS), - Matches(MS), - Error(ES), - Critical(CS), +pub enum AppState< + BrowseState, + InfoState, + ReloadState, + SearchState, + FetchState, + MatchesState, + ErrorState, + CriticalState, +> { + Browse(BrowseState), + Info(InfoState), + Reload(ReloadState), + Search(SearchState), + Fetch(FetchState), + Matches(MatchesState), + Error(ErrorState), + Critical(CriticalState), } pub trait IAppInteract { - type BS: IAppBase + IAppInteractBrowse; - type IS: IAppBase + IAppInteractInfo; - type RS: IAppBase + IAppInteractReload; - type SS: IAppBase + IAppInteractSearch; - type FS: IAppBase + IAppInteractFetch + IAppEventFetch; - type MS: IAppBase + IAppInteractMatches; - type ES: IAppBase + IAppInteractError; - type CS: IAppBase; + type BrowseState: IAppBase + IAppInteractBrowse; + type InfoState: IAppBase + IAppInteractInfo; + type ReloadState: IAppBase + IAppInteractReload; + type SearchState: IAppBase + IAppInteractSearch; + type FetchState: IAppBase + + IAppInteractFetch + + IAppEventFetch; + type MatchesState: IAppBase + IAppInteractMatches; + type ErrorState: IAppBase + IAppInteractError; + type CriticalState: IAppBase; fn is_running(&self) -> bool; fn force_quit(self) -> Self; @@ -35,7 +46,16 @@ pub trait IAppInteract { #[allow(clippy::type_complexity)] fn state( self, - ) -> AppState; + ) -> AppState< + Self::BrowseState, + Self::InfoState, + Self::ReloadState, + Self::SearchState, + Self::FetchState, + Self::MatchesState, + Self::ErrorState, + Self::CriticalState, + >; } pub trait IAppBase { diff --git a/src/tui/handler.rs b/src/tui/handler.rs index 513a9fd..2e10f34 100644 --- a/src/tui/handler.rs +++ b/src/tui/handler.rs @@ -20,14 +20,23 @@ pub trait IEventHandler { trait IEventHandlerPrivate { fn handle_key_event(app: APP, key_event: KeyEvent) -> APP; - fn handle_browse_key_event(app: ::BS, key_event: KeyEvent) -> APP; - fn handle_info_key_event(app: ::IS, key_event: KeyEvent) -> APP; - fn handle_reload_key_event(app: ::RS, key_event: KeyEvent) -> APP; - fn handle_search_key_event(app: ::SS, key_event: KeyEvent) -> APP; - fn handle_fetch_key_event(app: ::FS, key_event: KeyEvent) -> APP; - fn handle_matches_key_event(app: ::MS, key_event: KeyEvent) -> APP; - fn handle_error_key_event(app: ::ES, key_event: KeyEvent) -> APP; - fn handle_critical_key_event(app: ::CS, key_event: KeyEvent) -> APP; + fn handle_browse_key_event(app: ::BrowseState, key_event: KeyEvent) + -> APP; + fn handle_info_key_event(app: ::InfoState, key_event: KeyEvent) -> APP; + fn handle_reload_key_event(app: ::ReloadState, key_event: KeyEvent) + -> APP; + fn handle_search_key_event(app: ::SearchState, key_event: KeyEvent) + -> APP; + fn handle_fetch_key_event(app: ::FetchState, key_event: KeyEvent) -> APP; + fn handle_matches_key_event( + app: ::MatchesState, + key_event: KeyEvent, + ) -> APP; + fn handle_error_key_event(app: ::ErrorState, key_event: KeyEvent) -> APP; + fn handle_critical_key_event( + app: ::CriticalState, + key_event: KeyEvent, + ) -> APP; fn handle_fetch_result_ready_event(app: APP) -> APP; } @@ -103,7 +112,10 @@ impl IEventHandlerPrivate for EventHandler { } } - fn handle_browse_key_event(app: ::BS, key_event: KeyEvent) -> APP { + fn handle_browse_key_event( + app: ::BrowseState, + key_event: KeyEvent, + ) -> APP { match key_event.code { // Exit application on `ESC` or `q`. KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => app.quit(), @@ -133,7 +145,7 @@ impl IEventHandlerPrivate for EventHandler { } } - fn handle_info_key_event(app: ::IS, key_event: KeyEvent) -> APP { + fn handle_info_key_event(app: ::InfoState, key_event: KeyEvent) -> APP { match key_event.code { // Toggle overlay. KeyCode::Esc @@ -146,7 +158,10 @@ impl IEventHandlerPrivate for EventHandler { } } - fn handle_reload_key_event(app: ::RS, key_event: KeyEvent) -> APP { + fn handle_reload_key_event( + app: ::ReloadState, + key_event: KeyEvent, + ) -> APP { match key_event.code { // Reload keys. KeyCode::Char('l') | KeyCode::Char('L') => app.reload_library(), @@ -162,7 +177,10 @@ impl IEventHandlerPrivate for EventHandler { } } - fn handle_search_key_event(app: ::SS, key_event: KeyEvent) -> APP { + fn handle_search_key_event( + app: ::SearchState, + key_event: KeyEvent, + ) -> APP { if key_event.modifiers == KeyModifiers::CONTROL { return match key_event.code { KeyCode::Char('s') | KeyCode::Char('S') => app.search_next(), @@ -182,7 +200,7 @@ impl IEventHandlerPrivate for EventHandler { } } - fn handle_fetch_key_event(app: ::FS, key_event: KeyEvent) -> APP { + fn handle_fetch_key_event(app: ::FetchState, key_event: KeyEvent) -> APP { match key_event.code { // Abort. KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => app.abort(), @@ -191,7 +209,10 @@ impl IEventHandlerPrivate for EventHandler { } } - fn handle_matches_key_event(app: ::MS, key_event: KeyEvent) -> APP { + fn handle_matches_key_event( + app: ::MatchesState, + key_event: KeyEvent, + ) -> APP { match key_event.code { // Abort. KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => app.abort(), @@ -204,12 +225,15 @@ impl IEventHandlerPrivate for EventHandler { } } - fn handle_error_key_event(app: ::ES, _key_event: KeyEvent) -> APP { + fn handle_error_key_event(app: ::ErrorState, _key_event: KeyEvent) -> APP { // Any key dismisses the error. app.dismiss_error() } - fn handle_critical_key_event(app: ::CS, _key_event: KeyEvent) -> APP { + fn handle_critical_key_event( + app: ::CriticalState, + _key_event: KeyEvent, + ) -> APP { // No action is allowed. app.no_op() }