Isolate input lifecycle in one place
This commit is contained in:
parent
e4c77c982d
commit
4b92254a4d
@ -1,8 +1,6 @@
|
||||
use tui_input::backend::crossterm::EventHandler;
|
||||
|
||||
use crate::tui::app::{machine::App, AppState, IAppInput, InputEvent, InputPublic};
|
||||
|
||||
use super::AppInputMode;
|
||||
use crate::tui::app::{machine::App, AppMode, AppState, IAppInput, InputEvent, InputPublic};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Input(tui_input::Input);
|
||||
@ -13,6 +11,27 @@ impl<'app> From<&'app Input> for InputPublic<'app> {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<App> for AppMode<App, AppInputMode> {
|
||||
fn from(mut app: App) -> Self {
|
||||
if let Some(input) = app.input_mut().take() {
|
||||
AppMode::Input(AppInputMode::new(input, app))
|
||||
} else {
|
||||
AppMode::State(app)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AppInputMode {
|
||||
input: Input,
|
||||
app: App,
|
||||
}
|
||||
|
||||
impl AppInputMode {
|
||||
pub fn new(input: Input, app: App) -> Self {
|
||||
AppInputMode { input, app }
|
||||
}
|
||||
}
|
||||
|
||||
impl IAppInput for AppInputMode {
|
||||
type APP = App;
|
||||
|
||||
|
@ -21,7 +21,7 @@ use critical_state::CriticalState;
|
||||
use error_state::ErrorState;
|
||||
use fetch_state::FetchState;
|
||||
use info_state::InfoState;
|
||||
use input::Input;
|
||||
use input::{AppInputMode, Input};
|
||||
use match_state::MatchState;
|
||||
use reload_state::ReloadState;
|
||||
use search_state::SearchState;
|
||||
@ -53,17 +53,6 @@ pub struct AppInner {
|
||||
events: EventSender,
|
||||
}
|
||||
|
||||
pub struct AppInputMode {
|
||||
input: Input,
|
||||
app: App,
|
||||
}
|
||||
|
||||
impl AppInputMode {
|
||||
fn new(input: Input, app: App) -> Self {
|
||||
AppInputMode { input, app }
|
||||
}
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn new<MH: IMusicHoard + 'static, MB: IMusicBrainz + Send + 'static>(
|
||||
mut music_hoard: MH,
|
||||
@ -147,12 +136,8 @@ impl IApp for App {
|
||||
self
|
||||
}
|
||||
|
||||
fn mode(mut self) -> super::AppMode<IAppState!(), Self::InputMode> {
|
||||
if let Some(input) = self.input_mut().take() {
|
||||
AppMode::Input(AppInputMode::new(input, self.state()))
|
||||
} else {
|
||||
AppMode::State(self.state())
|
||||
}
|
||||
fn mode(self) -> AppMode<IAppState!(), Self::InputMode> {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user