Compare commits
3 Commits
4c39988d96
...
694242e386
Author | SHA1 | Date | |
---|---|---|---|
694242e386 | |||
18bbf78a92 | |||
48e19c1f7f |
@ -24,14 +24,14 @@ impl IAppInput for AppInputMode {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn confirm(self) -> Self::APP {
|
||||
self.cancel()
|
||||
}
|
||||
|
||||
fn cancel(mut self) -> Self::APP {
|
||||
fn confirm(mut self) -> Self::APP {
|
||||
if let AppState::Match(state) = &mut self.app {
|
||||
state.submit_input(self.input)
|
||||
};
|
||||
self.app
|
||||
}
|
||||
|
||||
fn cancel(self) -> Self::APP {
|
||||
self.app
|
||||
}
|
||||
}
|
||||
|
@ -273,6 +273,7 @@ mod tests {
|
||||
match_state(Some(album_match.clone())),
|
||||
);
|
||||
album_match.push_cannot_have_mbid();
|
||||
album_match.push_manual_input_mbid();
|
||||
|
||||
let mut widget_state = WidgetState::default();
|
||||
widget_state.list.select(Some(0));
|
||||
@ -296,6 +297,7 @@ mod tests {
|
||||
|
||||
let matches = AppMachine::match_state(inner(music_hoard(vec![])), app_matches);
|
||||
matches_info.push_cannot_have_mbid();
|
||||
matches_info.push_manual_input_mbid();
|
||||
|
||||
let mut widget_state = WidgetState::default();
|
||||
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.state.list.selected(), Some(2));
|
||||
|
||||
// Next is ManualInputMbid
|
||||
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(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();
|
||||
}
|
||||
|
||||
@ -346,6 +355,7 @@ mod tests {
|
||||
match_state(Some(album_match.clone())),
|
||||
);
|
||||
album_match.push_cannot_have_mbid();
|
||||
album_match.push_manual_input_mbid();
|
||||
|
||||
let mut widget_state = WidgetState::default();
|
||||
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 fetch_state;
|
||||
mod info_state;
|
||||
mod input;
|
||||
mod match_state;
|
||||
mod minibuffer;
|
||||
mod overlay;
|
||||
@ -25,6 +26,7 @@ use crate::tui::{
|
||||
error_state::ErrorOverlay,
|
||||
fetch_state::FetchOverlay,
|
||||
info_state::{AlbumOverlay, ArtistOverlay},
|
||||
input::InputOverlay,
|
||||
match_state::MatchOverlay,
|
||||
minibuffer::Minibuffer,
|
||||
overlay::{OverlayBuilder, OverlaySize},
|
||||
@ -152,15 +154,9 @@ impl Ui {
|
||||
.with_width(OverlaySize::MarginFactor(4))
|
||||
.with_height(OverlaySize::Value(3))
|
||||
.build(frame.area());
|
||||
let text_area = format!(" {}", input.value());
|
||||
UiWidget::render_overlay_widget("Input", Paragraph::new(text_area), area, false, 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,
|
||||
))
|
||||
let input_text = InputOverlay::paragraph(input.value());
|
||||
UiWidget::render_overlay_widget("Input", input_text, area, false, frame);
|
||||
InputOverlay::place_cursor(input, area, frame);
|
||||
}
|
||||
|
||||
fn render_error_overlay<S: AsRef<str>>(title: S, msg: S, frame: &mut Frame) {
|
||||
|
Loading…
Reference in New Issue
Block a user