Compare commits
3 Commits
4c39988d96
...
694242e386
Author | SHA1 | Date | |
---|---|---|---|
694242e386 | |||
18bbf78a92 | |||
48e19c1f7f |
@ -24,14 +24,14 @@ impl IAppInput for AppInputMode {
|
|||||||
self.app
|
self.app
|
||||||
}
|
}
|
||||||
|
|
||||||
fn confirm(self) -> Self::APP {
|
fn confirm(mut self) -> Self::APP {
|
||||||
self.cancel()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn cancel(mut self) -> Self::APP {
|
|
||||||
if let AppState::Match(state) = &mut self.app {
|
if let AppState::Match(state) = &mut self.app {
|
||||||
state.submit_input(self.input)
|
state.submit_input(self.input)
|
||||||
};
|
};
|
||||||
self.app
|
self.app
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cancel(self) -> Self::APP {
|
||||||
|
self.app
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -273,6 +273,7 @@ mod tests {
|
|||||||
match_state(Some(album_match.clone())),
|
match_state(Some(album_match.clone())),
|
||||||
);
|
);
|
||||||
album_match.push_cannot_have_mbid();
|
album_match.push_cannot_have_mbid();
|
||||||
|
album_match.push_manual_input_mbid();
|
||||||
|
|
||||||
let mut widget_state = WidgetState::default();
|
let mut widget_state = WidgetState::default();
|
||||||
widget_state.list.select(Some(0));
|
widget_state.list.select(Some(0));
|
||||||
@ -296,6 +297,7 @@ mod tests {
|
|||||||
|
|
||||||
let matches = AppMachine::match_state(inner(music_hoard(vec![])), app_matches);
|
let matches = AppMachine::match_state(inner(music_hoard(vec![])), app_matches);
|
||||||
matches_info.push_cannot_have_mbid();
|
matches_info.push_cannot_have_mbid();
|
||||||
|
matches_info.push_manual_input_mbid();
|
||||||
|
|
||||||
let mut widget_state = WidgetState::default();
|
let mut widget_state = WidgetState::default();
|
||||||
widget_state.list.select(Some(0));
|
widget_state.list.select(Some(0));
|
||||||
@ -319,12 +321,19 @@ mod tests {
|
|||||||
assert_eq!(matches.state.current.as_ref(), Some(&matches_info));
|
assert_eq!(matches.state.current.as_ref(), Some(&matches_info));
|
||||||
assert_eq!(matches.state.state.list.selected(), Some(2));
|
assert_eq!(matches.state.state.list.selected(), Some(2));
|
||||||
|
|
||||||
|
// Next is ManualInputMbid
|
||||||
let matches = matches.next_match().unwrap_match();
|
let matches = matches.next_match().unwrap_match();
|
||||||
|
|
||||||
assert_eq!(matches.state.current.as_ref(), Some(&matches_info));
|
assert_eq!(matches.state.current.as_ref(), Some(&matches_info));
|
||||||
assert_eq!(matches.state.state.list.selected(), Some(2));
|
assert_eq!(matches.state.state.list.selected(), Some(3));
|
||||||
|
|
||||||
// And it's done
|
let matches = matches.next_match().unwrap_match();
|
||||||
|
|
||||||
|
assert_eq!(matches.state.current.as_ref(), Some(&matches_info));
|
||||||
|
assert_eq!(matches.state.state.list.selected(), Some(3));
|
||||||
|
|
||||||
|
// Go prev_match first as selecting on manual input does not go back to fetch.
|
||||||
|
let matches = matches.prev_match().unwrap_match();
|
||||||
matches.select().unwrap_fetch();
|
matches.select().unwrap_fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,6 +355,7 @@ mod tests {
|
|||||||
match_state(Some(album_match.clone())),
|
match_state(Some(album_match.clone())),
|
||||||
);
|
);
|
||||||
album_match.push_cannot_have_mbid();
|
album_match.push_cannot_have_mbid();
|
||||||
|
album_match.push_manual_input_mbid();
|
||||||
|
|
||||||
let mut widget_state = WidgetState::default();
|
let mut widget_state = WidgetState::default();
|
||||||
widget_state.list.select(Some(0));
|
widget_state.list.select(Some(0));
|
||||||
|
20
src/tui/ui/input.rs
Normal file
20
src/tui/ui/input.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
use ratatui::{layout::Rect, widgets::Paragraph, Frame};
|
||||||
|
|
||||||
|
use crate::tui::app::InputPublic;
|
||||||
|
|
||||||
|
pub struct InputOverlay;
|
||||||
|
|
||||||
|
impl InputOverlay {
|
||||||
|
pub fn paragraph<'a>(text: &str) -> Paragraph<'a> {
|
||||||
|
Paragraph::new(format!(" {text}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn place_cursor(input: InputPublic, area: Rect, frame: &mut Frame) {
|
||||||
|
let width = area.width.max(4) - 4; // keep 2 for borders, 1 for left-pad, and 1 for cursor
|
||||||
|
let scroll = input.visual_scroll(width as usize);
|
||||||
|
frame.set_cursor_position((
|
||||||
|
area.x + ((input.visual_cursor()).max(scroll) - scroll) as u16 + 2,
|
||||||
|
area.y + 1,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ mod display;
|
|||||||
mod error_state;
|
mod error_state;
|
||||||
mod fetch_state;
|
mod fetch_state;
|
||||||
mod info_state;
|
mod info_state;
|
||||||
|
mod input;
|
||||||
mod match_state;
|
mod match_state;
|
||||||
mod minibuffer;
|
mod minibuffer;
|
||||||
mod overlay;
|
mod overlay;
|
||||||
@ -25,6 +26,7 @@ use crate::tui::{
|
|||||||
error_state::ErrorOverlay,
|
error_state::ErrorOverlay,
|
||||||
fetch_state::FetchOverlay,
|
fetch_state::FetchOverlay,
|
||||||
info_state::{AlbumOverlay, ArtistOverlay},
|
info_state::{AlbumOverlay, ArtistOverlay},
|
||||||
|
input::InputOverlay,
|
||||||
match_state::MatchOverlay,
|
match_state::MatchOverlay,
|
||||||
minibuffer::Minibuffer,
|
minibuffer::Minibuffer,
|
||||||
overlay::{OverlayBuilder, OverlaySize},
|
overlay::{OverlayBuilder, OverlaySize},
|
||||||
@ -152,15 +154,9 @@ impl Ui {
|
|||||||
.with_width(OverlaySize::MarginFactor(4))
|
.with_width(OverlaySize::MarginFactor(4))
|
||||||
.with_height(OverlaySize::Value(3))
|
.with_height(OverlaySize::Value(3))
|
||||||
.build(frame.area());
|
.build(frame.area());
|
||||||
let text_area = format!(" {}", input.value());
|
let input_text = InputOverlay::paragraph(input.value());
|
||||||
UiWidget::render_overlay_widget("Input", Paragraph::new(text_area), area, false, frame);
|
UiWidget::render_overlay_widget("Input", input_text, area, false, frame);
|
||||||
|
InputOverlay::place_cursor(input, area, frame);
|
||||||
let width = area.width.max(4) - 4; // keep 2 for borders, 1 for left-pad, and 1 for cursor
|
|
||||||
let scroll = input.visual_scroll(width as usize);
|
|
||||||
frame.set_cursor_position((
|
|
||||||
area.x + ((input.visual_cursor()).max(scroll) - scroll) as u16 + 2,
|
|
||||||
area.y + 1,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_error_overlay<S: AsRef<str>>(title: S, msg: S, frame: &mut Frame) {
|
fn render_error_overlay<S: AsRef<str>>(title: S, msg: S, frame: &mut Frame) {
|
||||||
|
Loading…
Reference in New Issue
Block a user