Compare commits

..

No commits in common. "694242e386b20d2f9839c4877beb39d2ca2a387f" and "4c39988d964094706ad26dac404047270ff3bc44" have entirely different histories.

4 changed files with 16 additions and 42 deletions

View File

@ -24,14 +24,14 @@ impl IAppInput for AppInputMode {
self.app
}
fn confirm(mut self) -> Self::APP {
fn confirm(self) -> Self::APP {
self.cancel()
}
fn cancel(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
}
}

View File

@ -273,7 +273,6 @@ 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));
@ -297,7 +296,6 @@ 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));
@ -321,19 +319,12 @@ 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(3));
assert_eq!(matches.state.state.list.selected(), Some(2));
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();
// And it's done
matches.select().unwrap_fetch();
}
@ -355,7 +346,6 @@ 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));

View File

@ -1,20 +0,0 @@
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,
))
}
}

View File

@ -3,7 +3,6 @@ mod display;
mod error_state;
mod fetch_state;
mod info_state;
mod input;
mod match_state;
mod minibuffer;
mod overlay;
@ -26,7 +25,6 @@ use crate::tui::{
error_state::ErrorOverlay,
fetch_state::FetchOverlay,
info_state::{AlbumOverlay, ArtistOverlay},
input::InputOverlay,
match_state::MatchOverlay,
minibuffer::Minibuffer,
overlay::{OverlayBuilder, OverlaySize},
@ -154,9 +152,15 @@ impl Ui {
.with_width(OverlaySize::MarginFactor(4))
.with_height(OverlaySize::Value(3))
.build(frame.area());
let input_text = InputOverlay::paragraph(input.value());
UiWidget::render_overlay_widget("Input", input_text, area, false, frame);
InputOverlay::place_cursor(input, area, frame);
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,
))
}
fn render_error_overlay<S: AsRef<str>>(title: S, msg: S, frame: &mut Frame) {