From fab611347851a3924aa0a9f0e3fdd8c890349791 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sun, 24 Nov 2024 19:09:31 +0100 Subject: [PATCH] wip: midi import/export browser, pt.2 --- crates/tek_tui/src/tui_command.rs | 4 ++-- crates/tek_tui/src/tui_input.rs | 29 ++++++++++++++++++++++++++++- crates/tek_tui/src/tui_model.rs | 14 ++++++++++++-- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/crates/tek_tui/src/tui_command.rs b/crates/tek_tui/src/tui_command.rs index 546f13b4..bbaaa24d 100644 --- a/crates/tek_tui/src/tui_command.rs +++ b/crates/tek_tui/src/tui_command.rs @@ -149,7 +149,7 @@ impl Command for PhrasesCommand { Import(command) => match command { FileBrowserCommand::Begin => { *state.phrases_mode_mut() = Some( - PhrasesMode::Import(state.phrase_index(), FileBrowser::new()) + PhrasesMode::Import(state.phrase_index(), FileBrowser::new(None)?) ); None }, @@ -158,7 +158,7 @@ impl Command for PhrasesCommand { Export(command) => match command { FileBrowserCommand::Begin => { *state.phrases_mode_mut() = Some( - PhrasesMode::Export(state.phrase_index(), FileBrowser::new()) + PhrasesMode::Export(state.phrase_index(), FileBrowser::new(None)?) ); None }, diff --git a/crates/tek_tui/src/tui_input.rs b/crates/tek_tui/src/tui_input.rs index 00b5da25..2b7b7b30 100644 --- a/crates/tek_tui/src/tui_input.rs +++ b/crates/tek_tui/src/tui_input.rs @@ -316,7 +316,34 @@ fn to_phrases_command (state: &T, input: &TuiInput) -> Optio impl InputToCommand for FileBrowserCommand { fn input_to_command (state: &T, from: &TuiInput) -> Option { - todo!() + use KeyCode::{Up, Down, Right, Left, Enter, Esc, Char, Backspace}; + if let Some(PhrasesMode::Import(index, browser)) = state.phrases_mode() { + Some(match from.event() { + key!(Up) => Self::Select(0), + key!(Down) => Self::Select(0), + key!(Right) => Self::Chdir(browser.cwd.clone()), + key!(Left) => Self::Chdir(browser.cwd.clone()), + key!(Enter) => { todo!() }, + key!(Char(c)) => { todo!() }, + key!(Backspace) => { todo!() }, + key!(Esc) => Self::Cancel, + _ => return None + }) + } else if let Some(PhrasesMode::Export(index, browser)) = state.phrases_mode() { + Some(match from.event() { + key!(Up) => Self::Select(0), + key!(Down) => Self::Select(0), + key!(Right) => Self::Chdir(browser.cwd.clone()), + key!(Left) => Self::Chdir(browser.cwd.clone()), + key!(Enter) => { todo!() }, + key!(Char(c)) => { todo!() }, + key!(Backspace) => { todo!() }, + key!(Esc) => Self::Cancel, + _ => return None + }) + } else { + unreachable!() + } } } diff --git a/crates/tek_tui/src/tui_model.rs b/crates/tek_tui/src/tui_model.rs index e530e76a..0a3f628f 100644 --- a/crates/tek_tui/src/tui_model.rs +++ b/crates/tek_tui/src/tui_model.rs @@ -174,14 +174,24 @@ pub struct FileBrowser { pub cwd: PathBuf, pub dirs: Vec, pub files: Vec, + pub filter: String, pub index: usize, pub scroll: usize, pub size: Measure } impl FileBrowser { - pub fn new () -> Self { - todo!() + pub fn new (cwd: Option) -> Usually { + let cwd = if let Some(cwd) = cwd { cwd } else { std::env::current_dir()? }; + Ok(Self { + cwd, + dirs: vec![/*todo*/], + files: vec![/*todo*/], + filter: "".to_string(), + index: 0, + scroll: 0, + size: Measure::new(), + }) } }