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 20:53:41 +01:00
|
|
|
|
|
|
|
let raw_results = &*app.list.items;
|
|
|
|
let mut results: Vec<String> = Vec::new();
|
2024-05-28 20:56:20 +01:00
|
|
|
for result in raw_results {
|
|
|
|
results.push(format!("{}\n{}", result.title, result.releaseDate));
|
2024-05-28 20:53:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
let list = List::new(results)
|
|
|
|
.block(Block::bordered().title("Search Results"))
|
|
|
|
.style(Style::default().fg(Color::White))
|
|
|
|
.highlight_style(Style::default().add_modifier(Modifier::ITALIC))
|
|
|
|
.highlight_symbol("┃ ")
|
|
|
|
.repeat_highlight_symbol(true)
|
|
|
|
.direction(ListDirection::TopToBottom);
|
|
|
|
|
|
|
|
frame.render_stateful_widget(list, chunks[2], &mut app.list.state);
|
2024-05-28 15:11:07 +01:00
|
|
|
}
|