diff --git a/src/tui/app/machine/input.rs b/src/tui/app/machine/input.rs index d1873ff..189b113 100644 --- a/src/tui/app/machine/input.rs +++ b/src/tui/app/machine/input.rs @@ -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 for AppMode { + 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; diff --git a/src/tui/app/machine/mod.rs b/src/tui/app/machine/mod.rs index acabcd1..4c6b447 100644 --- a/src/tui/app/machine/mod.rs +++ b/src/tui/app/machine/mod.rs @@ -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( mut music_hoard: MH, @@ -147,12 +136,8 @@ impl IApp for App { self } - fn mode(mut self) -> super::AppMode { - if let Some(input) = self.input_mut().take() { - AppMode::Input(AppInputMode::new(input, self.state())) - } else { - AppMode::State(self.state()) - } + fn mode(self) -> AppMode { + self.into() } }