mal/ui/
help.rs

1use crate::app::App;
2use ratatui::{
3    layout::{Constraint, Direction, Layout},
4    style::Style,
5    text::Span,
6    widgets::{Block, Borders, Cell, Row, Table},
7    Frame,
8};
9
10pub fn draw_help_menu(f: &mut Frame, app: &App) {
11    let chunks = Layout::default()
12        .direction(Direction::Vertical)
13        .constraints([Constraint::Percentage(100)].as_ref())
14        .margin(2)
15        .split(f.area());
16
17    let white = Style::default().fg(app.app_config.theme.text);
18    let gray = Style::default().fg(app.app_config.theme.inactive); //
19
20    let header = ["Description", "Event", "Context"];
21    let help_docs = get_help();
22    let help_docs: &[Vec<&str>] = &help_docs[app.help_menu_offset as usize..];
23
24    let rows: Vec<Row> = help_docs
25        .iter()
26        .map(|i| -> Row {
27            Row::new(
28                i.iter()
29                    .map(|&cell| -> Cell { Cell::from(cell).style(gray) })
30                    .collect::<Vec<Cell>>(),
31            )
32        })
33        .collect::<Vec<Row>>();
34
35    let header = Row::new(
36        header
37            .iter()
38            .map(|&header| Cell::from(header).style(white))
39            .collect::<Vec<Cell>>(),
40    );
41
42    let help_menu = Table::default()
43        .rows(rows)
44        .header(header)
45        .block(
46            Block::default()
47                .borders(Borders::ALL)
48                .style(white)
49                .title(Span::styled("Help (press <Esc> to go back)", gray))
50                .border_style(gray),
51        )
52        .style(Style::default().fg(app.app_config.theme.text))
53        .widths([
54            Constraint::Length(50),
55            Constraint::Length(40),
56            Constraint::Length(20),
57        ]);
58
59    f.render_widget(help_menu, chunks[0]);
60}
61
62pub fn get_help() -> Vec<Vec<&'static str>> {
63    // TODO: Help docs
64    vec![vec!["Down", "j", "Pagination"]]
65}