Use more verbose type names for clarity #214
@ -97,14 +97,14 @@ impl App {
|
||||
}
|
||||
|
||||
impl IAppInteract for App {
|
||||
type BS = AppMachine<AppBrowse>;
|
||||
type IS = AppMachine<AppInfo>;
|
||||
type RS = AppMachine<AppReload>;
|
||||
type SS = AppMachine<AppSearch>;
|
||||
type FS = AppMachine<AppFetch>;
|
||||
type MS = AppMachine<AppMatches>;
|
||||
type ES = AppMachine<AppError>;
|
||||
type CS = AppMachine<AppCritical>;
|
||||
type BrowseState = AppMachine<AppBrowse>;
|
||||
type InfoState = AppMachine<AppInfo>;
|
||||
type ReloadState = AppMachine<AppReload>;
|
||||
type SearchState = AppMachine<AppSearch>;
|
||||
type FetchState = AppMachine<AppFetch>;
|
||||
type MatchesState = AppMachine<AppMatches>;
|
||||
type ErrorState = AppMachine<AppError>;
|
||||
type CriticalState = AppMachine<AppCritical>;
|
||||
|
||||
fn is_running(&self) -> bool {
|
||||
self.inner_ref().running
|
||||
@ -117,8 +117,16 @@ impl IAppInteract for App {
|
||||
|
||||
fn state(
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -8,26 +8,37 @@ use musichoard::collection::{album::AlbumMeta, artist::ArtistMeta, Collection};
|
||||
|
||||
use crate::tui::lib::interface::musicbrainz::Match;
|
||||
|
||||
pub enum AppState<BS, IS, RS, SS, FS, MS, ES, CS> {
|
||||
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<APP = Self> + IAppInteractBrowse<APP = Self>;
|
||||
type IS: IAppBase<APP = Self> + IAppInteractInfo<APP = Self>;
|
||||
type RS: IAppBase<APP = Self> + IAppInteractReload<APP = Self>;
|
||||
type SS: IAppBase<APP = Self> + IAppInteractSearch<APP = Self>;
|
||||
type FS: IAppBase<APP = Self> + IAppInteractFetch<APP = Self> + IAppEventFetch<APP = Self>;
|
||||
type MS: IAppBase<APP = Self> + IAppInteractMatches<APP = Self>;
|
||||
type ES: IAppBase<APP = Self> + IAppInteractError<APP = Self>;
|
||||
type CS: IAppBase<APP = Self>;
|
||||
type BrowseState: IAppBase<APP = Self> + IAppInteractBrowse<APP = Self>;
|
||||
type InfoState: IAppBase<APP = Self> + IAppInteractInfo<APP = Self>;
|
||||
type ReloadState: IAppBase<APP = Self> + IAppInteractReload<APP = Self>;
|
||||
type SearchState: IAppBase<APP = Self> + IAppInteractSearch<APP = Self>;
|
||||
type FetchState: IAppBase<APP = Self>
|
||||
+ IAppInteractFetch<APP = Self>
|
||||
+ IAppEventFetch<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 force_quit(self) -> Self;
|
||||
@ -35,7 +46,16 @@ pub trait IAppInteract {
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn state(
|
||||
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 {
|
||||
|
@ -20,14 +20,23 @@ pub trait IEventHandler<APP: IAppInteract> {
|
||||
|
||||
trait IEventHandlerPrivate<APP: IAppInteract> {
|
||||
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_info_key_event(app: <APP as IAppInteract>::IS, key_event: KeyEvent) -> APP;
|
||||
fn handle_reload_key_event(app: <APP as IAppInteract>::RS, key_event: KeyEvent) -> APP;
|
||||
fn handle_search_key_event(app: <APP as IAppInteract>::SS, key_event: KeyEvent) -> APP;
|
||||
fn handle_fetch_key_event(app: <APP as IAppInteract>::FS, key_event: KeyEvent) -> APP;
|
||||
fn handle_matches_key_event(app: <APP as IAppInteract>::MS, key_event: KeyEvent) -> APP;
|
||||
fn handle_error_key_event(app: <APP as IAppInteract>::ES, key_event: KeyEvent) -> APP;
|
||||
fn handle_critical_key_event(app: <APP as IAppInteract>::CS, key_event: KeyEvent) -> APP;
|
||||
fn handle_browse_key_event(app: <APP as IAppInteract>::BrowseState, key_event: KeyEvent)
|
||||
-> APP;
|
||||
fn handle_info_key_event(app: <APP as IAppInteract>::InfoState, key_event: KeyEvent) -> APP;
|
||||
fn handle_reload_key_event(app: <APP as IAppInteract>::ReloadState, key_event: KeyEvent)
|
||||
-> APP;
|
||||
fn handle_search_key_event(app: <APP as IAppInteract>::SearchState, 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;
|
||||
}
|
||||
@ -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 {
|
||||
// Exit application on `ESC` or `q`.
|
||||
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 {
|
||||
// Toggle overlay.
|
||||
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 {
|
||||
// Reload keys.
|
||||
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 {
|
||||
return match key_event.code {
|
||||
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 {
|
||||
// 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 {
|
||||
// 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.
|
||||
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.
|
||||
app.no_op()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user