Skip to main content

git_tailor/views/
help.rs

1// Copyright 2026 Thomas Johannesson
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Help dialog view showing keybindings
16
17use super::dialog::render_centered_dialog;
18use crate::app::{AppAction, KeyCommand};
19
20use ratatui::{
21    Frame,
22    style::{Color, Modifier, Style},
23    text::{Line, Span},
24};
25
26/// Handle an action while in Help mode.
27pub fn handle_key(action: KeyCommand, app: &mut crate::app::AppState) -> AppAction {
28    match action {
29        KeyCommand::Quit | KeyCommand::ShowHelp => {
30            app.toggle_help();
31            AppAction::Handled
32        }
33        _ => AppAction::Handled,
34    }
35}
36
37/// Render the help dialog as a centered overlay.
38pub fn render(frame: &mut Frame) {
39    // Build help content first to calculate required size
40    let help_lines = vec![
41        Line::from(""),
42        Line::from(Span::styled(
43            " Navigation",
44            Style::default()
45                .fg(Color::Yellow)
46                .add_modifier(Modifier::BOLD),
47        )),
48        Line::from(""),
49        Line::from(vec![
50            Span::styled("   ↑/↓, j/k  ", Style::default().fg(Color::Cyan)),
51            Span::raw("Move selection up/down"),
52        ]),
53        Line::from(vec![
54            Span::styled("   PgUp/PgDn ", Style::default().fg(Color::Cyan)),
55            Span::raw("Move one page up/down"),
56        ]),
57        Line::from(vec![
58            Span::styled("   ←/→       ", Style::default().fg(Color::Cyan)),
59            Span::raw("Scroll fragmap left/right"),
60        ]),
61        Line::from(vec![
62            Span::styled("   Ctrl ←/→  ", Style::default().fg(Color::Cyan)),
63            Span::raw("Move separator bar left/right"),
64        ]),
65        Line::from(""),
66        Line::from(Span::styled(
67            " Operations",
68            Style::default()
69                .fg(Color::Yellow)
70                .add_modifier(Modifier::BOLD),
71        )),
72        Line::from(""),
73        Line::from(vec![
74            Span::styled("   p         ", Style::default().fg(Color::Cyan)),
75            Span::raw("Split commit (choose strategy)"),
76        ]),
77        Line::from(vec![
78            Span::styled("   s         ", Style::default().fg(Color::Cyan)),
79            Span::raw("Squash commit (pick target)"),
80        ]),
81        Line::from(vec![
82            Span::styled("   f         ", Style::default().fg(Color::Cyan)),
83            Span::raw("Fixup commit (pick target)"),
84        ]),
85        Line::from(vec![
86            Span::styled("   r         ", Style::default().fg(Color::Cyan)),
87            Span::raw("Reword commit message"),
88        ]),
89        Line::from(vec![
90            Span::styled("   d         ", Style::default().fg(Color::Cyan)),
91            Span::raw("Drop commit"),
92        ]),
93        Line::from(vec![
94            Span::styled("   m         ", Style::default().fg(Color::Cyan)),
95            Span::raw("Move commit (pick new position)"),
96        ]),
97        Line::from(""),
98        Line::from(Span::styled(
99            " Views",
100            Style::default()
101                .fg(Color::Yellow)
102                .add_modifier(Modifier::BOLD),
103        )),
104        Line::from(""),
105        Line::from(vec![
106            Span::styled("   Enter, i  ", Style::default().fg(Color::Cyan)),
107            Span::raw("Toggle commit detail view"),
108        ]),
109        Line::from(vec![
110            Span::styled("   h         ", Style::default().fg(Color::Cyan)),
111            Span::raw("Show this help dialog"),
112        ]),
113        Line::from(vec![
114            Span::styled("   u         ", Style::default().fg(Color::Cyan)),
115            Span::raw("Update commit list from HEAD"),
116        ]),
117        Line::from(""),
118        Line::from(Span::styled(
119            " Other",
120            Style::default()
121                .fg(Color::Yellow)
122                .add_modifier(Modifier::BOLD),
123        )),
124        Line::from(""),
125        Line::from(vec![
126            Span::styled("   Esc, q    ", Style::default().fg(Color::Cyan)),
127            Span::raw("Close dialog / Quit application"),
128        ]),
129        Line::from(""),
130    ];
131
132    render_centered_dialog(frame, " Help - Keybindings ", Color::White, 48, help_lines);
133}