diff --git a/src/ui.rs b/src/ui.rs index 5d20ae0..242a73c 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,25 +1,54 @@ use ratatui::{ - layout::Alignment, + prelude::*, style::{Color, Style}, - widgets::{Block, BorderType, Paragraph}, + widgets::*, Frame, }; use crate::app::App; -/// Renders the user interface widgets. +/// Renders the user interface. pub fn render(app: &mut App, frame: &mut Frame) { - frame.render_widget( - Paragraph::new(format!( - "This is just a placeholder." - )) - .block( - Block::bordered() - .title("Template") - .title_alignment(Alignment::Center) - .border_type(BorderType::Rounded), + let chunks = Layout::default() + .direction(Direction::Vertical) + .margin(2) + .constraints( + [ + Constraint::Length(1), + Constraint::Length(3), + Constraint::Min(1), + ] + .as_ref(), ) - .centered(), - frame.size(), + .split(frame.size()); + + let mut text: Vec = vec![]; + text.push( + Line::from(vec![ + "Press ".into(), + "Esc".bold(), + " or ".into(), + "Ctrl+C".bold(), + " to quit, and ".into(), + "Enter".bold(), + " to submit your query.".into(), + ]), + ); + let help_message = Paragraph::new(text); + frame.render_widget(help_message, chunks[0]); + + let width = chunks[0].width.max(3) - 3; + + let scroll = app.input.visual_scroll(width as usize); + let input = Paragraph::new(app.input.value()) + .style(Style::default().fg(Color::Yellow)) + .scroll((0, scroll as u16)) + .block(Block::default().borders(Borders::ALL).title("Search (Anime)")); + frame.render_widget(input, chunks[1]); + frame.set_cursor( + chunks[1].x + + ((app.input.visual_cursor()).max(scroll) - scroll) as u16 + + 1, + chunks[1].y + 1, ) }