From bdc189e32e7c9dd61811fe17e50ac171ca94c647 Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Sat, 30 May 2026 23:58:02 +0300 Subject: feat: support custom command descriptions refs #362 --- src/ui.rs | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 10 deletions(-) (limited to 'src/ui.rs') diff --git a/src/ui.rs b/src/ui.rs index c9999a9a..b9d9827a 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1019,23 +1019,79 @@ mod tests { .1 .clone(); - assert!(workspace_tab.contains(&("unset".to_string(), "previous workspace"))); - assert!(workspace_tab.contains(&("unset".to_string(), "next workspace"))); - assert!(workspace_tab.contains(&("unset".to_string(), "previous agent"))); - assert!(workspace_tab.contains(&("unset".to_string(), "next agent"))); - assert!(workspace_tab.contains(&("unset".to_string(), "focus agent 1-9"))); - assert!(workspace_tab.contains(&("unset".to_string(), "switch workspace 1-9"))); + assert!(workspace_tab + .iter() + .any(|(key, label)| key == "unset" && label.as_ref() == "previous workspace")); + assert!(workspace_tab + .iter() + .any(|(key, label)| key == "unset" && label.as_ref() == "next workspace")); + assert!(workspace_tab + .iter() + .any(|(key, label)| key == "unset" && label.as_ref() == "previous agent")); + assert!(workspace_tab + .iter() + .any(|(key, label)| key == "unset" && label.as_ref() == "next agent")); + assert!(workspace_tab + .iter() + .any(|(key, label)| key == "unset" && label.as_ref() == "focus agent 1-9")); + assert!(workspace_tab + .iter() + .any(|(key, label)| key == "unset" && label.as_ref() == "switch workspace 1-9")); assert!(panes .iter() - .any(|(key, label)| key == "prefix+h" && *label == "focus pane left")); + .any(|(key, label)| key == "prefix+h" && label.as_ref() == "focus pane left")); assert!(panes .iter() - .any(|(key, label)| key == "prefix+j" && *label == "focus pane down")); + .any(|(key, label)| key == "prefix+j" && label.as_ref() == "focus pane down")); assert!(panes .iter() - .any(|(key, label)| key == "prefix+k" && *label == "focus pane up")); + .any(|(key, label)| key == "prefix+k" && label.as_ref() == "focus pane up")); assert!(panes .iter() - .any(|(key, label)| key == "prefix+l" && *label == "focus pane right")); + .any(|(key, label)| key == "prefix+l" && label.as_ref() == "focus pane right")); + } + + #[test] + fn keybind_help_shows_custom_command_descriptions() { + let mut app = crate::app::state::AppState::test_new(); + app.keybinds.custom_commands = vec![ + crate::config::CustomCommandKeybind { + bindings: crate::config::ActionKeybinds::prefix("alt+g"), + label: "prefix+alt+g".to_string(), + command: "lazygit".to_string(), + action: crate::config::CustomCommandAction::Pane, + description: Some("open lazygit".to_string()), + }, + crate::config::CustomCommandKeybind { + bindings: crate::config::ActionKeybinds::prefix("alt+h"), + label: "prefix+alt+h".to_string(), + command: "echo hello".to_string(), + action: crate::config::CustomCommandAction::Shell, + description: None, + }, + ]; + + let groups = keybind_help_groups(&app); + let custom = groups + .iter() + .find(|(name, _)| *name == "custom") + .expect("custom group") + .1 + .clone(); + assert!(custom + .iter() + .any(|(key, label)| key == "prefix+alt+g" && label.as_ref() == "open lazygit")); + assert!(custom + .iter() + .any(|(key, label)| key == "prefix+alt+h" && label.as_ref() == "custom command")); + + let rendered_help = keybind_help_lines(&app) + .into_iter() + .flat_map(|(_, line)| line.spans) + .map(|span| span.content.into_owned()) + .collect::>() + .join(""); + assert!(rendered_help.contains("open lazygit")); + assert!(rendered_help.contains("custom command")); } } -- cgit v1.2.3