Verbosity

This commit is contained in:
Wojciech Kozlowski 2024-09-12 21:09:55 +02:00
parent 9d1caffd9c
commit 1404666e12
3 changed files with 96 additions and 44 deletions

View File

@ -97,14 +97,14 @@ impl App {
} }
impl IAppInteract for App { impl IAppInteract for App {
type BS = AppMachine<AppBrowse>; type BrowseState = AppMachine<AppBrowse>;
type IS = AppMachine<AppInfo>; type InfoState = AppMachine<AppInfo>;
type RS = AppMachine<AppReload>; type ReloadState = AppMachine<AppReload>;
type SS = AppMachine<AppSearch>; type SearchState = AppMachine<AppSearch>;
type FS = AppMachine<AppFetch>; type FetchState = AppMachine<AppFetch>;
type MS = AppMachine<AppMatches>; type MatchesState = AppMachine<AppMatches>;
type ES = AppMachine<AppError>; type ErrorState = AppMachine<AppError>;
type CS = AppMachine<AppCritical>; type CriticalState = AppMachine<AppCritical>;
fn is_running(&self) -> bool { fn is_running(&self) -> bool {
self.inner_ref().running self.inner_ref().running
@ -117,8 +117,16 @@ impl IAppInteract for App {
fn state( fn state(
self, self,
) -> AppState<Self::BS, Self::IS, Self::RS, Self::SS, Self::FS, Self::MS, Self::ES, Self::CS> ) -> AppState<
{ Self::BrowseState,
Self::InfoState,
Self::ReloadState,
Self::SearchState,
Self::FetchState,
Self::MatchesState,
Self::ErrorState,
Self::CriticalState,
> {
self self
} }
} }

View File

@ -8,26 +8,37 @@ use musichoard::collection::{album::AlbumMeta, artist::ArtistMeta, Collection};
use crate::tui::lib::interface::musicbrainz::Match; use crate::tui::lib::interface::musicbrainz::Match;
pub enum AppState<BS, IS, RS, SS, FS, MS, ES, CS> { pub enum AppState<
Browse(BS), BrowseState,
Info(IS), InfoState,
Reload(RS), ReloadState,
Search(SS), SearchState,
Fetch(FS), FetchState,
Matches(MS), MatchesState,
Error(ES), ErrorState,
Critical(CS), CriticalState,
> {
Browse(BrowseState),
Info(InfoState),
Reload(ReloadState),
Search(SearchState),
Fetch(FetchState),
Matches(MatchesState),
Error(ErrorState),
Critical(CriticalState),
} }
pub trait IAppInteract { pub trait IAppInteract {
type BS: IAppBase<APP = Self> + IAppInteractBrowse<APP = Self>; type BrowseState: IAppBase<APP = Self> + IAppInteractBrowse<APP = Self>;
type IS: IAppBase<APP = Self> + IAppInteractInfo<APP = Self>; type InfoState: IAppBase<APP = Self> + IAppInteractInfo<APP = Self>;
type RS: IAppBase<APP = Self> + IAppInteractReload<APP = Self>; type ReloadState: IAppBase<APP = Self> + IAppInteractReload<APP = Self>;
type SS: IAppBase<APP = Self> + IAppInteractSearch<APP = Self>; type SearchState: IAppBase<APP = Self> + IAppInteractSearch<APP = Self>;
type FS: IAppBase<APP = Self> + IAppInteractFetch<APP = Self> + IAppEventFetch<APP = Self>; type FetchState: IAppBase<APP = Self>
type MS: IAppBase<APP = Self> + IAppInteractMatches<APP = Self>; + IAppInteractFetch<APP = Self>
type ES: IAppBase<APP = Self> + IAppInteractError<APP = Self>; + IAppEventFetch<APP = Self>;
type CS: IAppBase<APP = Self>; type MatchesState: IAppBase<APP = Self> + IAppInteractMatches<APP = Self>;
type ErrorState: IAppBase<APP = Self> + IAppInteractError<APP = Self>;
type CriticalState: IAppBase<APP = Self>;
fn is_running(&self) -> bool; fn is_running(&self) -> bool;
fn force_quit(self) -> Self; fn force_quit(self) -> Self;
@ -35,7 +46,16 @@ pub trait IAppInteract {
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
fn state( fn state(
self, self,
) -> AppState<Self::BS, Self::IS, Self::RS, Self::SS, Self::FS, Self::MS, Self::ES, Self::CS>; ) -> AppState<
Self::BrowseState,
Self::InfoState,
Self::ReloadState,
Self::SearchState,
Self::FetchState,
Self::MatchesState,
Self::ErrorState,
Self::CriticalState,
>;
} }
pub trait IAppBase { pub trait IAppBase {

View File

@ -20,14 +20,23 @@ pub trait IEventHandler<APP: IAppInteract> {
trait IEventHandlerPrivate<APP: IAppInteract> { trait IEventHandlerPrivate<APP: IAppInteract> {
fn handle_key_event(app: APP, key_event: KeyEvent) -> APP; fn handle_key_event(app: APP, key_event: KeyEvent) -> APP;
fn handle_browse_key_event(app: <APP as IAppInteract>::BS, key_event: KeyEvent) -> APP; fn handle_browse_key_event(app: <APP as IAppInteract>::BrowseState, key_event: KeyEvent)
fn handle_info_key_event(app: <APP as IAppInteract>::IS, key_event: KeyEvent) -> APP; -> APP;
fn handle_reload_key_event(app: <APP as IAppInteract>::RS, key_event: KeyEvent) -> APP; fn handle_info_key_event(app: <APP as IAppInteract>::InfoState, key_event: KeyEvent) -> APP;
fn handle_search_key_event(app: <APP as IAppInteract>::SS, key_event: KeyEvent) -> APP; fn handle_reload_key_event(app: <APP as IAppInteract>::ReloadState, key_event: KeyEvent)
fn handle_fetch_key_event(app: <APP as IAppInteract>::FS, key_event: KeyEvent) -> APP; -> APP;
fn handle_matches_key_event(app: <APP as IAppInteract>::MS, key_event: KeyEvent) -> APP; fn handle_search_key_event(app: <APP as IAppInteract>::SearchState, key_event: KeyEvent)
fn handle_error_key_event(app: <APP as IAppInteract>::ES, key_event: KeyEvent) -> APP; -> APP;
fn handle_critical_key_event(app: <APP as IAppInteract>::CS, key_event: KeyEvent) -> APP; fn handle_fetch_key_event(app: <APP as IAppInteract>::FetchState, key_event: KeyEvent) -> APP;
fn handle_matches_key_event(
app: <APP as IAppInteract>::MatchesState,
key_event: KeyEvent,
) -> APP;
fn handle_error_key_event(app: <APP as IAppInteract>::ErrorState, key_event: KeyEvent) -> APP;
fn handle_critical_key_event(
app: <APP as IAppInteract>::CriticalState,
key_event: KeyEvent,
) -> APP;
fn handle_fetch_result_ready_event(app: APP) -> APP; fn handle_fetch_result_ready_event(app: APP) -> APP;
} }
@ -103,7 +112,10 @@ impl<APP: IAppInteract> IEventHandlerPrivate<APP> for EventHandler {
} }
} }
fn handle_browse_key_event(app: <APP as IAppInteract>::BS, key_event: KeyEvent) -> APP { fn handle_browse_key_event(
app: <APP as IAppInteract>::BrowseState,
key_event: KeyEvent,
) -> APP {
match key_event.code { match key_event.code {
// Exit application on `ESC` or `q`. // Exit application on `ESC` or `q`.
KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => app.quit(), KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => app.quit(),
@ -133,7 +145,7 @@ impl<APP: IAppInteract> IEventHandlerPrivate<APP> for EventHandler {
} }
} }
fn handle_info_key_event(app: <APP as IAppInteract>::IS, key_event: KeyEvent) -> APP { fn handle_info_key_event(app: <APP as IAppInteract>::InfoState, key_event: KeyEvent) -> APP {
match key_event.code { match key_event.code {
// Toggle overlay. // Toggle overlay.
KeyCode::Esc KeyCode::Esc
@ -146,7 +158,10 @@ impl<APP: IAppInteract> IEventHandlerPrivate<APP> for EventHandler {
} }
} }
fn handle_reload_key_event(app: <APP as IAppInteract>::RS, key_event: KeyEvent) -> APP { fn handle_reload_key_event(
app: <APP as IAppInteract>::ReloadState,
key_event: KeyEvent,
) -> APP {
match key_event.code { match key_event.code {
// Reload keys. // Reload keys.
KeyCode::Char('l') | KeyCode::Char('L') => app.reload_library(), KeyCode::Char('l') | KeyCode::Char('L') => app.reload_library(),
@ -162,7 +177,10 @@ impl<APP: IAppInteract> IEventHandlerPrivate<APP> for EventHandler {
} }
} }
fn handle_search_key_event(app: <APP as IAppInteract>::SS, key_event: KeyEvent) -> APP { fn handle_search_key_event(
app: <APP as IAppInteract>::SearchState,
key_event: KeyEvent,
) -> APP {
if key_event.modifiers == KeyModifiers::CONTROL { if key_event.modifiers == KeyModifiers::CONTROL {
return match key_event.code { return match key_event.code {
KeyCode::Char('s') | KeyCode::Char('S') => app.search_next(), KeyCode::Char('s') | KeyCode::Char('S') => app.search_next(),
@ -182,7 +200,7 @@ impl<APP: IAppInteract> IEventHandlerPrivate<APP> for EventHandler {
} }
} }
fn handle_fetch_key_event(app: <APP as IAppInteract>::FS, key_event: KeyEvent) -> APP { fn handle_fetch_key_event(app: <APP as IAppInteract>::FetchState, key_event: KeyEvent) -> APP {
match key_event.code { match key_event.code {
// Abort. // Abort.
KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => app.abort(), KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => app.abort(),
@ -191,7 +209,10 @@ impl<APP: IAppInteract> IEventHandlerPrivate<APP> for EventHandler {
} }
} }
fn handle_matches_key_event(app: <APP as IAppInteract>::MS, key_event: KeyEvent) -> APP { fn handle_matches_key_event(
app: <APP as IAppInteract>::MatchesState,
key_event: KeyEvent,
) -> APP {
match key_event.code { match key_event.code {
// Abort. // Abort.
KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => app.abort(), KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => app.abort(),
@ -204,12 +225,15 @@ impl<APP: IAppInteract> IEventHandlerPrivate<APP> for EventHandler {
} }
} }
fn handle_error_key_event(app: <APP as IAppInteract>::ES, _key_event: KeyEvent) -> APP { fn handle_error_key_event(app: <APP as IAppInteract>::ErrorState, _key_event: KeyEvent) -> APP {
// Any key dismisses the error. // Any key dismisses the error.
app.dismiss_error() app.dismiss_error()
} }
fn handle_critical_key_event(app: <APP as IAppInteract>::CS, _key_event: KeyEvent) -> APP { fn handle_critical_key_event(
app: <APP as IAppInteract>::CriticalState,
_key_event: KeyEvent,
) -> APP {
// No action is allowed. // No action is allowed.
app.no_op() app.no_op()
} }