aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-05-30 23:58:02 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-05-31 00:02:08 +0300
commitbdc189e32e7c9dd61811fe17e50ac171ca94c647 (patch)
tree730e0e14d571e9bb693ad583b02e24622e4258d4 /src/ui
parentfc4e1bbf6b0fa2ec37445a5b72356514c7c6be6a (diff)
feat: support custom command descriptions
refs #362
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/keybind_help.rs122
1 files changed, 69 insertions, 53 deletions
diff --git a/src/ui/keybind_help.rs b/src/ui/keybind_help.rs
index 4fb559c6..76a68f0d 100644
--- a/src/ui/keybind_help.rs
+++ b/src/ui/keybind_help.rs
@@ -1,3 +1,5 @@
+use std::borrow::Cow;
+
use ratatui::{
layout::{Constraint, Layout, Rect},
style::{Modifier, Style},
@@ -14,6 +16,13 @@ use super::widgets::{
};
use crate::app::AppState;
+pub(super) type HelpEntry = (String, Cow<'static, str>);
+pub(super) type HelpGroup = (&'static str, Vec<HelpEntry>);
+
+fn help_entry(key: impl Into<String>, label: &'static str) -> HelpEntry {
+ (key.into(), Cow::Borrowed(label))
+}
+
fn keybind_label(bindings: &crate::config::ActionKeybinds) -> String {
bindings.label().unwrap_or_else(|| "unset".to_string())
}
@@ -41,24 +50,22 @@ fn indexed_label(bindings: &[crate::config::IndexedKeybind]) -> String {
}
}
-pub(super) fn keybind_help_groups(
- app: &AppState,
-) -> Vec<(&'static str, Vec<(String, &'static str)>)> {
+pub(super) fn keybind_help_groups(app: &AppState) -> Vec<HelpGroup> {
let kb = &app.keybinds;
let mut groups = Vec::new();
groups.push((
"global",
vec![
- (
+ help_entry(
crate::config::format_key_combo((app.prefix_code, app.prefix_mods)),
"prefix mode",
),
- (keybind_label(&kb.help), "keybinds"),
- (keybind_label(&kb.settings), "settings"),
- (keybind_label(&kb.detach), "detach"),
- (keybind_label(&kb.reload_config), "reload config"),
- (
+ help_entry(keybind_label(&kb.help), "keybinds"),
+ help_entry(keybind_label(&kb.settings), "settings"),
+ help_entry(keybind_label(&kb.detach), "detach"),
+ help_entry(keybind_label(&kb.reload_config), "reload config"),
+ help_entry(
keybind_label(&kb.open_notification_target),
"open notification target",
),
@@ -68,8 +75,8 @@ pub(super) fn keybind_help_groups(
groups.push((
"navigation",
vec![
- ("esc".to_string(), "back"),
- (
+ help_entry("esc", "back"),
+ help_entry(
format!(
"{} / {}",
keybind_label(&kb.navigate.workspace_up),
@@ -77,7 +84,7 @@ pub(super) fn keybind_help_groups(
),
"workspace list",
),
- (
+ help_entry(
format!(
"{} / {} / {} / {} / left / right",
keybind_label(&kb.navigate.pane_left),
@@ -87,59 +94,59 @@ pub(super) fn keybind_help_groups(
),
"move focus",
),
- ("tab / shift+tab".to_string(), "cycle pane"),
- ("enter".to_string(), "open workspace"),
- ("1..9".to_string(), "switch workspace"),
+ help_entry("tab / shift+tab", "cycle pane"),
+ help_entry("enter", "open workspace"),
+ help_entry("1..9", "switch workspace"),
],
));
let workspace_tab = vec![
- (keybind_label(&kb.workspace_picker), "workspace navigation"),
- (keybind_label(&kb.goto), "session navigator"),
- (keybind_label(&kb.new_workspace), "new workspace"),
- (keybind_label(&kb.new_worktree), "new worktree"),
- (keybind_label(&kb.open_worktree), "open worktree"),
- (
+ help_entry(keybind_label(&kb.workspace_picker), "workspace navigation"),
+ help_entry(keybind_label(&kb.goto), "session navigator"),
+ help_entry(keybind_label(&kb.new_workspace), "new workspace"),
+ help_entry(keybind_label(&kb.new_worktree), "new worktree"),
+ help_entry(keybind_label(&kb.open_worktree), "open worktree"),
+ help_entry(
keybind_label(&kb.remove_worktree),
"delete worktree checkout",
),
- (keybind_label(&kb.rename_workspace), "rename workspace"),
- (keybind_label(&kb.close_workspace), "close workspace"),
- (keybind_label(&kb.previous_workspace), "previous workspace"),
- (keybind_label(&kb.next_workspace), "next workspace"),
- (indexed_label(&kb.switch_workspace), "switch workspace 1-9"),
- (keybind_label(&kb.previous_agent), "previous agent"),
- (keybind_label(&kb.next_agent), "next agent"),
- (indexed_label(&kb.focus_agent), "focus agent 1-9"),
- (keybind_label(&kb.new_tab), "new tab"),
- (keybind_label(&kb.rename_tab), "rename tab"),
- (keybind_label(&kb.previous_tab), "previous tab"),
- (keybind_label(&kb.next_tab), "next tab"),
- (indexed_label(&kb.switch_tab), "switch tab 1-9"),
- (keybind_label(&kb.close_tab), "close tab"),
+ help_entry(keybind_label(&kb.rename_workspace), "rename workspace"),
+ help_entry(keybind_label(&kb.close_workspace), "close workspace"),
+ help_entry(keybind_label(&kb.previous_workspace), "previous workspace"),
+ help_entry(keybind_label(&kb.next_workspace), "next workspace"),
+ help_entry(indexed_label(&kb.switch_workspace), "switch workspace 1-9"),
+ help_entry(keybind_label(&kb.previous_agent), "previous agent"),
+ help_entry(keybind_label(&kb.next_agent), "next agent"),
+ help_entry(indexed_label(&kb.focus_agent), "focus agent 1-9"),
+ help_entry(keybind_label(&kb.new_tab), "new tab"),
+ help_entry(keybind_label(&kb.rename_tab), "rename tab"),
+ help_entry(keybind_label(&kb.previous_tab), "previous tab"),
+ help_entry(keybind_label(&kb.next_tab), "next tab"),
+ help_entry(indexed_label(&kb.switch_tab), "switch tab 1-9"),
+ help_entry(keybind_label(&kb.close_tab), "close tab"),
];
groups.push(("workspaces / tabs", workspace_tab));
let panes = vec![
- (keybind_label(&kb.split_vertical), "split vertical"),
- (keybind_label(&kb.split_horizontal), "split horizontal"),
- (keybind_label(&kb.close_pane), "close pane"),
- (keybind_label(&kb.rename_pane), "rename pane"),
- (keybind_label(&kb.edit_scrollback), "edit scrollback"),
- (keybind_label(&kb.copy_mode), "copy mode"),
- (keybind_label(&kb.zoom), "zoom pane"),
- (keybind_label(&kb.resize_mode), "resize mode"),
- (keybind_label(&kb.toggle_sidebar), "toggle sidebar"),
- (keybind_label(&kb.focus_pane_left), "focus pane left"),
- (keybind_label(&kb.focus_pane_down), "focus pane down"),
- (keybind_label(&kb.focus_pane_up), "focus pane up"),
- (keybind_label(&kb.focus_pane_right), "focus pane right"),
- (keybind_label(&kb.cycle_pane_next), "cycle pane next"),
- (
+ help_entry(keybind_label(&kb.split_vertical), "split vertical"),
+ help_entry(keybind_label(&kb.split_horizontal), "split horizontal"),
+ help_entry(keybind_label(&kb.close_pane), "close pane"),
+ help_entry(keybind_label(&kb.rename_pane), "rename pane"),
+ help_entry(keybind_label(&kb.edit_scrollback), "edit scrollback"),
+ help_entry(keybind_label(&kb.copy_mode), "copy mode"),
+ help_entry(keybind_label(&kb.zoom), "zoom pane"),
+ help_entry(keybind_label(&kb.resize_mode), "resize mode"),
+ help_entry(keybind_label(&kb.toggle_sidebar), "toggle sidebar"),
+ help_entry(keybind_label(&kb.focus_pane_left), "focus pane left"),
+ help_entry(keybind_label(&kb.focus_pane_down), "focus pane down"),
+ help_entry(keybind_label(&kb.focus_pane_up), "focus pane up"),
+ help_entry(keybind_label(&kb.focus_pane_right), "focus pane right"),
+ help_entry(keybind_label(&kb.cycle_pane_next), "cycle pane next"),
+ help_entry(
keybind_label(&kb.cycle_pane_previous),
"cycle pane previous",
),
- (keybind_label(&kb.last_pane), "last pane"),
+ help_entry(keybind_label(&kb.last_pane), "last pane"),
];
groups.push(("panes", panes));
@@ -148,7 +155,16 @@ pub(super) fn keybind_help_groups(
"custom",
kb.custom_commands
.iter()
- .map(|binding| (binding.label.clone(), "custom command"))
+ .map(|binding| {
+ (
+ binding.label.clone(),
+ binding
+ .description
+ .clone()
+ .map(Cow::Owned)
+ .unwrap_or(Cow::Borrowed("custom command")),
+ )
+ })
.collect(),
));
}
@@ -186,7 +202,7 @@ pub(crate) fn keybind_help_lines(app: &AppState) -> Vec<(usize, Line<'static>)>
width,
Line::from(vec![
Span::styled(padded_key, key_style),
- Span::styled(label.to_string(), label_style),
+ Span::styled(label.into_owned(), label_style),
]),
));
}