diff --git a/src/main.rs b/src/main.rs index e2fd177..3fa803b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -94,7 +94,6 @@ fn with( let app = App::new(music_hoard, musicbrainz, app_sender); let ui = Ui; - // Run the TUI application. Tui::run(terminal, app, ui, handler, listener).expect("failed to run tui"); } diff --git a/src/tui/app/machine/browse.rs b/src/tui/app/machine/browse.rs index 770cca4..17a1ffe 100644 --- a/src/tui/app/machine/browse.rs +++ b/src/tui/app/machine/browse.rs @@ -13,7 +13,7 @@ use crate::tui::{ app::{ machine::{App, AppInner, AppMachine}, selection::{Delta, ListSelection}, - AppMatchesInfo, AppPublic, AppState, IAppInteractBrowse, + AppMatchesInfo, AppPublic, AppState, IAppBase, IAppInteractBrowse, }, event::{Event, EventSender}, lib::interface::musicbrainz::{self, IMusicBrainz}, @@ -183,6 +183,10 @@ impl IAppInteractBrowse for AppMachine { AppMachine::app_fetch_new(self.inner, fetch_rx) } +} + +impl IAppBase for AppMachine { + type APP = App; fn no_op(self) -> Self::APP { self.into() diff --git a/src/tui/app/machine/critical.rs b/src/tui/app/machine/critical.rs index 476ba8a..3e6c402 100644 --- a/src/tui/app/machine/critical.rs +++ b/src/tui/app/machine/critical.rs @@ -1,6 +1,6 @@ use crate::tui::app::{ machine::{App, AppInner, AppMachine}, - AppPublic, AppState, IAppInteractCritical, + AppPublic, AppState, IAppBase, }; pub struct AppCritical { @@ -33,7 +33,7 @@ impl<'a> From<&'a mut AppMachine> for AppPublic<'a> { } } -impl IAppInteractCritical for AppMachine { +impl IAppBase for AppMachine { type APP = App; fn no_op(self) -> Self::APP { diff --git a/src/tui/app/machine/error.rs b/src/tui/app/machine/error.rs index 11abff7..4d910f2 100644 --- a/src/tui/app/machine/error.rs +++ b/src/tui/app/machine/error.rs @@ -1,6 +1,6 @@ use crate::tui::app::{ machine::{App, AppInner, AppMachine}, - AppPublic, AppState, IAppInteractError, + AppPublic, AppState, IAppBase, IAppInteractError, }; pub struct AppError { @@ -39,6 +39,10 @@ impl IAppInteractError for AppMachine { fn dismiss_error(self) -> Self::APP { AppMachine::browse(self.inner).into() } +} + +impl IAppBase for AppMachine { + type APP = App; fn no_op(self) -> Self::APP { self.into() diff --git a/src/tui/app/machine/fetch.rs b/src/tui/app/machine/fetch.rs index cfabd3e..625f983 100644 --- a/src/tui/app/machine/fetch.rs +++ b/src/tui/app/machine/fetch.rs @@ -3,7 +3,7 @@ use std::sync::mpsc::{self, TryRecvError}; use crate::tui::{ app::{ machine::{App, AppInner, AppMachine}, - AppMatchesInfo, AppPublic, AppState, IAppEventFetch, IAppInteractFetch, + AppMatchesInfo, AppPublic, AppState, IAppBase, IAppEventFetch, IAppInteractFetch, }, lib::interface::musicbrainz::Error as MbError, }; @@ -85,6 +85,10 @@ impl IAppInteractFetch for AppMachine { fn abort(self) -> Self::APP { AppMachine::browse(self.inner).into() } +} + +impl IAppBase for AppMachine { + type APP = App; fn no_op(self) -> Self::APP { self.into() diff --git a/src/tui/app/machine/info.rs b/src/tui/app/machine/info.rs index 6dd90b6..ced252a 100644 --- a/src/tui/app/machine/info.rs +++ b/src/tui/app/machine/info.rs @@ -1,6 +1,6 @@ use crate::tui::app::{ machine::{App, AppInner, AppMachine}, - AppPublic, AppState, IAppInteractInfo, + AppPublic, AppState, IAppBase, IAppInteractInfo, }; pub struct AppInfo; @@ -35,6 +35,10 @@ impl IAppInteractInfo for AppMachine { fn hide_info_overlay(self) -> Self::APP { AppMachine::browse(self.inner).into() } +} + +impl IAppBase for AppMachine { + type APP = App; fn no_op(self) -> Self::APP { self.into() diff --git a/src/tui/app/machine/matches.rs b/src/tui/app/machine/matches.rs index e6a5e32..c6b4b17 100644 --- a/src/tui/app/machine/matches.rs +++ b/src/tui/app/machine/matches.rs @@ -3,7 +3,7 @@ use std::cmp; use crate::tui::app::{ machine::{App, AppInner, AppMachine}, AppAlbumMatches, AppArtistMatches, AppMatchesInfo, AppPublic, AppPublicMatches, AppState, - IAppInteractMatches, MatchOption, WidgetState, + IAppBase, IAppInteractMatches, MatchOption, WidgetState, }; use super::fetch::AppFetch; @@ -122,6 +122,10 @@ impl IAppInteractMatches for AppMachine { fn abort(self) -> Self::APP { AppMachine::browse(self.inner).into() } +} + +impl IAppBase for AppMachine { + type APP = App; fn no_op(self) -> Self::APP { self.into() diff --git a/src/tui/app/machine/reload.rs b/src/tui/app/machine/reload.rs index 6659434..06c857b 100644 --- a/src/tui/app/machine/reload.rs +++ b/src/tui/app/machine/reload.rs @@ -1,7 +1,7 @@ use crate::tui::app::{ machine::{App, AppInner, AppMachine}, selection::KeySelection, - AppPublic, AppState, IAppInteractReload, + AppPublic, AppState, IAppBase, IAppInteractReload, }; pub struct AppReload; @@ -53,6 +53,10 @@ impl IAppInteractReload for AppMachine { fn hide_reload_menu(self) -> Self::APP { AppMachine::browse(self.inner).into() } +} + +impl IAppBase for AppMachine { + type APP = App; fn no_op(self) -> Self::APP { self.into() diff --git a/src/tui/app/machine/search.rs b/src/tui/app/machine/search.rs index 17ed189..dda0f9d 100644 --- a/src/tui/app/machine/search.rs +++ b/src/tui/app/machine/search.rs @@ -6,7 +6,7 @@ use musichoard::collection::{album::Album, artist::Artist, track::Track}; use crate::tui::app::{ machine::{App, AppInner, AppMachine}, selection::{ListSelection, SelectionState}, - AppPublic, AppState, Category, IAppInteractSearch, + AppPublic, AppState, Category, IAppBase, IAppInteractSearch, }; // Unlikely that this covers all possible strings, but it should at least cover strings @@ -98,6 +98,10 @@ impl IAppInteractSearch for AppMachine { self.inner.selection.select_by_list(self.state.orig); AppMachine::browse(self.inner).into() } +} + +impl IAppBase for AppMachine { + type APP = App; fn no_op(self) -> Self::APP { self.into() diff --git a/src/tui/app/mod.rs b/src/tui/app/mod.rs index 5dfaca6..866f9a0 100644 --- a/src/tui/app/mod.rs +++ b/src/tui/app/mod.rs @@ -20,14 +20,14 @@ pub enum AppState { } pub trait IAppInteract { - type BS: IAppInteractBrowse; - type IS: IAppInteractInfo; - type RS: IAppInteractReload; - type SS: IAppInteractSearch; - type FS: IAppInteractFetch + IAppEventFetch; - type MS: IAppInteractMatches; - type ES: IAppInteractError; - type CS: IAppInteractCritical; + 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; fn is_running(&self) -> bool; fn force_quit(self) -> Self; @@ -38,6 +38,12 @@ pub trait IAppInteract { ) -> AppState; } +pub trait IAppBase { + type APP: IAppInteract; + + fn no_op(self) -> Self::APP; +} + pub trait IAppInteractBrowse { type APP: IAppInteract; @@ -55,16 +61,12 @@ pub trait IAppInteractBrowse { fn begin_search(self) -> Self::APP; fn fetch_musicbrainz(self) -> Self::APP; - - fn no_op(self) -> Self::APP; } pub trait IAppInteractInfo { type APP: IAppInteract; fn hide_info_overlay(self) -> Self::APP; - - fn no_op(self) -> Self::APP; } pub trait IAppInteractReload { @@ -73,8 +75,6 @@ pub trait IAppInteractReload { fn reload_library(self) -> Self::APP; fn reload_database(self) -> Self::APP; fn hide_reload_menu(self) -> Self::APP; - - fn no_op(self) -> Self::APP; } pub trait IAppInteractSearch { @@ -85,16 +85,12 @@ pub trait IAppInteractSearch { fn step_back(self) -> Self::APP; fn finish_search(self) -> Self::APP; fn cancel_search(self) -> Self::APP; - - fn no_op(self) -> Self::APP; } pub trait IAppInteractFetch { type APP: IAppInteract; fn abort(self) -> Self::APP; - - fn no_op(self) -> Self::APP; } pub trait IAppEventFetch { @@ -111,22 +107,12 @@ pub trait IAppInteractMatches { fn select(self) -> Self::APP; fn abort(self) -> Self::APP; - - fn no_op(self) -> Self::APP; } pub trait IAppInteractError { type APP: IAppInteract; fn dismiss_error(self) -> Self::APP; - - fn no_op(self) -> Self::APP; -} - -pub trait IAppInteractCritical { - type APP: IAppInteract; - - fn no_op(self) -> Self::APP; } // It would be preferable to have a getter for each field separately. However, the selection field diff --git a/src/tui/handler.rs b/src/tui/handler.rs index e934870..513a9fd 100644 --- a/src/tui/handler.rs +++ b/src/tui/handler.rs @@ -5,14 +5,13 @@ use mockall::automock; use crate::tui::{ app::{ - AppState, Delta, IAppInteract, IAppInteractBrowse, IAppInteractCritical, IAppInteractError, - IAppInteractFetch, IAppInteractInfo, IAppInteractMatches, IAppInteractReload, - IAppInteractSearch, + AppState, Delta, IAppInteract, IAppInteractBrowse, IAppInteractError, IAppInteractFetch, + IAppInteractInfo, IAppInteractMatches, IAppInteractReload, IAppInteractSearch, }, event::{Event, EventError, EventReceiver}, }; -use super::app::IAppEventFetch; +use super::app::{IAppBase, IAppEventFetch}; #[cfg_attr(test, automock)] pub trait IEventHandler {