toon_format/tui/components/
help_screen.rs

1//! Help screen showing keyboard shortcuts.
2
3use ratatui::{
4    layout::{
5        Alignment,
6        Constraint,
7        Direction,
8        Layout,
9        Rect,
10    },
11    text::{
12        Line,
13        Span,
14    },
15    widgets::{
16        Block,
17        Borders,
18        List,
19        ListItem,
20        Paragraph,
21    },
22    Frame,
23};
24
25use crate::tui::{
26    keybindings::KeyBindings,
27    theme::Theme,
28};
29
30pub struct HelpScreen;
31
32impl HelpScreen {
33    pub fn render(f: &mut Frame, area: Rect, theme: &Theme) {
34        let block = Block::default()
35            .borders(Borders::ALL)
36            .border_style(theme.border_style(true))
37            .title(" Help - Press F1 or Esc to close ")
38            .title_alignment(Alignment::Center);
39
40        let inner = block.inner(area);
41        f.render_widget(block, area);
42
43        let chunks = Layout::default()
44            .direction(Direction::Vertical)
45            .constraints([
46                Constraint::Length(3),
47                Constraint::Min(10),
48                Constraint::Length(5),
49            ])
50            .split(inner);
51
52        let title = Paragraph::new(vec![
53            Line::from(Span::styled(
54                "TOON Format - Interactive TUI",
55                theme.title_style(),
56            )),
57            Line::from(Span::styled(
58                "Token-Oriented Object Notation",
59                theme.info_style(),
60            )),
61        ])
62        .alignment(Alignment::Center);
63        f.render_widget(title, chunks[0]);
64
65        let shortcuts = KeyBindings::shortcuts();
66        let items: Vec<ListItem> = shortcuts
67            .iter()
68            .map(|(key, desc)| {
69                ListItem::new(Line::from(vec![
70                    Span::styled(format!("  {key:18} "), theme.info_style()),
71                    Span::styled(*desc, theme.normal_style()),
72                ]))
73            })
74            .collect();
75
76        let list = List::new(items).block(
77            Block::default()
78                .borders(Borders::ALL)
79                .border_style(theme.border_style(false))
80                .title(" Keyboard Shortcuts "),
81        );
82        f.render_widget(list, chunks[1]);
83
84        let footer = Paragraph::new(vec![
85            Line::from(Span::styled(
86                "TOON is a compact, human-readable format for passing structured data to LLMs",
87                theme.normal_style(),
88            )),
89            Line::from(vec![
90                Span::styled("Repository: ", theme.line_number_style()),
91                Span::styled("github.com/toon-format/toon-rust", theme.info_style()),
92            ]),
93        ])
94        .alignment(Alignment::Center);
95        f.render_widget(footer, chunks[2]);
96    }
97}