2024-05-28 15:11:07 +01:00
|
|
|
use ratatui::{
|
2024-05-28 15:32:03 +01:00
|
|
|
prelude::*,
|
2024-05-28 15:11:07 +01:00
|
|
|
style::{Color, Style},
|
2024-05-28 15:32:03 +01:00
|
|
|
widgets::*,
|
2024-05-28 15:11:07 +01:00
|
|
|
Frame,
|
|
|
|
};
|
|
|
|
|
|
|
|
use crate::app::App;
|
|
|
|
|
2024-05-28 15:32:03 +01:00
|
|
|
/// Renders the user interface.
|
2024-05-28 15:11:07 +01:00
|
|
|
pub fn render(app: &mut App, frame: &mut Frame) {
|
2024-05-28 15:32:03 +01:00
|
|
|
let chunks = Layout::default()
|
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.margin(2)
|
|
|
|
.constraints(
|
|
|
|
[
|
|
|
|
Constraint::Length(1),
|
|
|
|
Constraint::Length(3),
|
|
|
|
Constraint::Min(1),
|
|
|
|
]
|
|
|
|
.as_ref(),
|
2024-05-28 15:11:07 +01:00
|
|
|
)
|
2024-05-28 15:32:03 +01:00
|
|
|
.split(frame.size());
|
|
|
|
|
2024-05-28 15:51:15 +01:00
|
|
|
let text: Vec<Line> = vec![Line::from(vec![
|
|
|
|
"Press ".into(),
|
|
|
|
"Esc".bold(),
|
|
|
|
" or ".into(),
|
|
|
|
"Ctrl+C".bold(),
|
|
|
|
" to quit, and ".into(),
|
|
|
|
"Enter".bold(),
|
|
|
|
" to submit your query.".into(),
|
|
|
|
])];
|
2024-05-28 15:32:03 +01:00
|
|
|
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))
|
2024-05-28 15:51:15 +01:00
|
|
|
.block(
|
|
|
|
Block::default()
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
.title("Search (Anime)"),
|
|
|
|
);
|
2024-05-28 15:32:03 +01:00
|
|
|
frame.render_widget(input, chunks[1]);
|
2024-05-28 15:51:15 +01:00
|
|
|
frame.set_cursor(
|
|
|
|
chunks[1].x + ((app.input.visual_cursor()).max(scroll) - scroll) as u16 + 1,
|
2024-05-28 15:32:03 +01:00
|
|
|
chunks[1].y + 1,
|
2024-05-28 15:42:49 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
let messages = Paragraph::new("Another placeholder")
|
|
|
|
.block(Block::default().borders(Borders::ALL).title("Results"));
|
|
|
|
frame.render_widget(messages, chunks[2]);
|
2024-05-28 15:11:07 +01:00
|
|
|
}
|