Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a small table of key bindings to the "?" help dialog #91

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 48 additions & 8 deletions scm-record/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use crossterm::terminal::{
};
use ratatui::backend::{Backend, TestBackend};
use ratatui::buffer::Buffer;
use ratatui::style::{Color, Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::style::{Color, Modifier, Style, Stylize};
use ratatui::text::{Line, Span, Text};
use ratatui::widgets::{Block, Borders, Clear, Paragraph};
use ratatui::{backend::CrosstermBackend, Terminal};
use tracing::warn;
Expand Down Expand Up @@ -3363,7 +3363,7 @@ impl Component for QuitDialog {
} else {
format!("You have changes to {}. ", alert_items.join(" and "))
};
let body = format!("{alert}Are you sure you want to quit?",);
let body = Text::from(format!("{alert}Are you sure you want to quit?",));

let quit_button = Button {
id: ComponentId::QuitDialogButton(QuitDialogButtonId::Quit),
Expand Down Expand Up @@ -3407,7 +3407,47 @@ impl Component for HelpDialog {

fn draw(&self, viewport: &mut Viewport<Self::Id>, _: isize, _: isize) {
let title = "Help";
let body = "You can click the menus with the mouse to view keyboard shortcuts.";
let body = Text::from(vec![
Line::from("You can click the menus with a mouse, or use these keyboard shortcuts:"),
Line::from(""),
Line::from(vec![
Span::raw(" "),
Span::styled("General", Style::new().bold().underlined()),
Span::raw(" "),
Span::styled("Navigation", Style::new().bold().underlined()),
]),
Line::from(
" Quit/Cancel q Next/Prev j/k or ↓/↑",
),
Line::from(" Confirm changes c Next/Prev of same type PgDn/PgUp"),
Line::from(" Force quit ^c Move out & fold h or ←"),
Line::from(
" Move out & don't fold H or Shift-← ",
),
Line::from(vec![
Span::raw(" "),
Span::styled("View controls", Style::new().bold().underlined()),
Span::raw(" Move in & unfold l or →"),
]),
Line::from(" Expand/Collapse f"),
Line::from(vec![
Span::raw(" Expand/Collapse all F "),
Span::styled("Scrolling", Style::new().bold().underlined()),
]),
Line::from(" Edit commit message e Scroll up/down ^y/^e"),
Line::from(" or ^↑/^↓"),
Line::from(vec![
Span::raw(" "),
Span::styled("Selection", Style::new().bold().underlined()),
Span::raw(" Page up/down ^b/^f"),
]),
Line::from(
" Toggle current Space or ^PgUp/^PgDn",
),
Line::from(" Toggle and advance Enter Previous/Next page ^u/^d"),
Line::from(" Invert all a"),
Line::from(" Invert all uniformly A"),
]);

let quit_button = Button {
id: ComponentId::HelpDialogQuitButton,
Expand All @@ -3420,7 +3460,7 @@ impl Component for HelpDialog {
let dialog = Dialog {
id: self.id(),
title: Cow::Borrowed(title),
body: Cow::Borrowed(body),
body: Cow::Borrowed(&body),
buttons: &buttons,
};
viewport.draw_component(0, 0, &dialog);
Expand Down Expand Up @@ -3470,7 +3510,7 @@ impl<Id: Clone + Debug + Eq + Hash> Component for Button<'_, Id> {
struct Dialog<'a, Id> {
id: Id,
title: Cow<'a, str>,
body: Cow<'a, str>,
body: Cow<'a, Text<'a>>,
buttons: &'a [Button<'a, Id>],
}

Expand All @@ -3490,7 +3530,7 @@ impl<Id: Clone + Debug + Eq + Hash> Component for Dialog<'_, Id> {
} = self;
let rect = {
let border_size = 2;
let body_lines = body.lines().count();
let body_lines = body.lines.len();
let rect = centered_rect(
viewport.rect(),
RectSize {
Expand All @@ -3503,7 +3543,7 @@ impl<Id: Clone + Debug + Eq + Hash> Component for Dialog<'_, Id> {
20,
);

let paragraph = Paragraph::new(body.as_ref()).block(
let paragraph = Paragraph::new((*body.as_ref()).clone()).block(
Block::default()
.title(title.as_ref())
.borders(Borders::all()),
Expand Down