Define the Mutt-like TUI keymap

This commit is contained in:
Hermes Agent
2026-08-10 08:03:20 +00:00
parent c82c792699
commit 639ae0d08e
4 changed files with 519 additions and 80 deletions

View File

@@ -9,7 +9,7 @@ use ratatui::{
};
use crate::{
action::available_actions,
action::{context_actions, help_actions},
app::{App, Mode, PaneFocus},
editor::EntryEditor,
viewer::EntryViewer,
@@ -78,25 +78,31 @@ fn render_content(frame: &mut Frame, app: &App, area: Rect) {
}
if app.mode() == Mode::Help {
let available_rows = usize::from(area.height.saturating_sub(2)).max(1);
let lines = (0..available_rows).map(|row| {
let mut spans = Vec::new();
for index in (row..crate::action::ACTIONS.len()).step_by(available_rows) {
let spec = &crate::action::ACTIONS[index];
let lines = help_actions(app.help_context_mode()).map(|spec| {
let bindings = spec
.bindings
.iter()
.map(|binding| binding.display)
.collect::<Vec<_>>()
.join(", ");
let mut spans = vec![
Span::styled(format!("{bindings:>14}"), Style::default().fg(Color::Cyan)),
Span::raw(format!(" {:<24} :{:<18}", spec.label, spec.command)),
];
if !spec.help().is_empty() {
spans.push(Span::styled(
format!("{:>6}", spec.bindings[0].display),
Style::default().fg(Color::Cyan),
spec.help(),
Style::default().fg(Color::Yellow),
));
spans.push(Span::raw(format!(
" {:<16} :{:<16}",
spec.label, spec.command
)));
}
Line::from(spans)
});
frame.render_widget(
Paragraph::new(lines.collect::<Vec<_>>())
.block(Block::bordered().title("Contextual help"))
.block(Block::bordered().title(format!(
"Contextual help — {}",
mode_title(app.help_context_mode())
)))
.wrap(Wrap { trim: false }),
area,
);
@@ -403,7 +409,7 @@ fn status_line(app: &App) -> Paragraph<'_> {
}
fn context_line(app: &App) -> Paragraph<'static> {
let text = available_actions(app.mode())
let text = context_actions(app.mode())
.map(|spec| format!("{} {}", spec.bindings[0].display, spec.label))
.collect::<Vec<_>>()
.join(" ");
@@ -489,10 +495,22 @@ mod tests {
let mut app = App::new();
assert!(app.transition(Transition::OpenHelp));
let output = render(140, 35, &app);
for spec in crate::action::ACTIONS {
for spec in crate::action::help_actions(Mode::Browser) {
assert!(output.contains(spec.label));
assert!(output.contains(spec.command));
}
assert!(output.contains("d d"));
assert!(output.contains("confirmation"));
assert!(output.contains("g p"));
assert!(!output.contains("edit field"));
app.dispatch(crate::action::Action::Cancel);
app.open_test_document("email/personal", fixture_document("email/personal"));
app.dispatch(crate::action::Action::Help);
let viewer_help = render(140, 35, &app);
assert!(viewer_help.contains("edit entry"));
assert!(viewer_help.contains("copy field"));
assert!(!viewer_help.contains("insert entry"));
}
#[test]