Provide search functionality through the TUI #134

Merged
wojtek merged 35 commits from 24---provide-search-functionality-through-the-tui into main 2024-02-18 22:12:42 +01:00
3 changed files with 18 additions and 3 deletions
Showing only changes of commit 5b7263d5d8 - Show all commits

View File

@ -111,6 +111,7 @@ pub trait IAppInteractSearch {
fn search_next(&mut self); fn search_next(&mut self);
fn step_back(&mut self); fn step_back(&mut self);
fn finish_search(&mut self); fn finish_search(&mut self);
fn cancel_search(&mut self);
} }
pub trait IAppInteractError { pub trait IAppInteractError {
@ -301,7 +302,6 @@ impl<MH: IMusicHoard> IAppInteractReloadPrivate for App<MH> {
} }
} }
// FIXME: Also add a `cancel_search` which returns to the previous selection.
impl<MH: IMusicHoard> IAppInteractSearch for App<MH> { impl<MH: IMusicHoard> IAppInteractSearch for App<MH> {
fn append_character(&mut self, ch: char) { fn append_character(&mut self, ch: char) {
let collection = self.music_hoard.get_collection(); let collection = self.music_hoard.get_collection();
@ -339,6 +339,13 @@ impl<MH: IMusicHoard> IAppInteractSearch for App<MH> {
assert!(self.state.is_search()); assert!(self.state.is_search());
self.state = AppState::Browse(()); self.state = AppState::Browse(());
} }
fn cancel_search(&mut self) {
assert!(self.state.is_search());
let collection = self.music_hoard.get_collection();
self.selection.select_artist(collection, self.orig);
self.state = AppState::Browse(());
}
} }
impl<MH: IMusicHoard> IAppInteractError for App<MH> { impl<MH: IMusicHoard> IAppInteractError for App<MH> {

View File

@ -151,6 +151,9 @@ impl<APP: IAppInteract> IEventHandlerPrivate<APP> for EventHandler {
KeyCode::Char('s') | KeyCode::Char('S') => { KeyCode::Char('s') | KeyCode::Char('S') => {
app.search_next(); app.search_next();
}, },
KeyCode::Char('g') | KeyCode::Char('G') => {
app.cancel_search();
},
_ => {} _ => {}
} }
return; return;

View File

@ -348,6 +348,7 @@ impl<'a, 'b> TrackState<'a, 'b> {
struct Minibuffer<'a> { struct Minibuffer<'a> {
paragraphs: Vec<Paragraph<'a>>, paragraphs: Vec<Paragraph<'a>>,
// FIXME: make this an option
columns: u16, columns: u16,
} }
@ -376,8 +377,12 @@ impl Minibuffer<'_> {
columns, columns,
}, },
AppState::Search(ref s) => Minibuffer { AppState::Search(ref s) => Minibuffer {
paragraphs: vec![Paragraph::new(format!("I-search: {s}"))], paragraphs: vec![
columns: 1, Paragraph::new(format!("I-search: {s}")),
Paragraph::new(format!("ctrl+s: search next")).alignment(Alignment::Center),
Paragraph::new(format!("ctrl+g: cancel search")).alignment(Alignment::Center),
],
columns,
}, },
AppState::Error(_) => Minibuffer { AppState::Error(_) => Minibuffer {
paragraphs: vec![Paragraph::new( paragraphs: vec![Paragraph::new(