feat(help): open a searchable shortcuts panel from help

Running help without arguments in the kitty shell now opens a categorized,
searchable reference in a left dock instead of a pager. The new kitten collects
the effective bindings and hands them to the palette in read-only mode.
This commit is contained in:
BlackAngelTV committed 2026-11-12 12:43:46 +01:00
1 parent 45a16ea61c
commit 81df6f2d3a
3 files changed
+67 -4

No files matched your search

+1
View File
@@ -0,0 +1 @@
# License: GPLv3 Copyright: 2026, FWS
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env python
# License: GPLv3 Copyright: 2026, FWS
# The keybindings live in the Python options object, while the searchable list
# UI lives in the Go command palette. Collect the data here, then replace this
# process with the palette reading the same terminal, so the panel can run in a
# dock without a second protocol between the two.
import json
import os
import sys
import tempfile
from contextlib import suppress
help_text = 'Browse all keyboard shortcuts in a searchable panel'
usage = ''
OPTIONS = r"""
""".format
def main(args: list[str]) -> None:
from kittens.command_palette.main import collect_keys_data
from kitty.config import load_config
from kitty.constants import config_dir, kitten_exe
conf = os.path.join(config_dir, 'kitty.conf')
opts = load_config(conf) if os.path.exists(conf) else load_config()
fd, path = tempfile.mkstemp(prefix='kitty-shortcuts-', suffix='.json')
try:
with os.fdopen(fd, 'w', encoding='utf-8') as f:
json.dump(collect_keys_data(opts), f)
exe = kitten_exe()
os.execv(exe, [exe, 'command-palette', '--data-file=' + path, '--read-only'])
finally:
# execv only returns on failure; on success the Go side removes the file.
with suppress(OSError):
os.unlink(path)
if __name__ == '__main__':
main(sys.argv)
elif __name__ == '__doc__':
cd = sys.cli_docs # type: ignore
cd['usage'] = usage
cd['options'] = OPTIONS
cd['help_text'] = help_text
cd['short_desc'] = 'Browse all keyboard shortcuts in a searchable panel'
+19 -4
View File
@@ -97,6 +97,21 @@ func shell_loop(rl *readline.Readline, kill_if_signaled bool) (int, error) {
return 0, nil
}
// launch_shortcuts_panel opens the searchable keybinding reference in a dock,
// next to the terminal, instead of taking over the shell window.
func launch_shortcuts_panel() int {
kitty := utils.KittyExe()
if kitty == "" {
kitty = "kitty"
}
root := cli.NewRootCommand()
EntryPoint(root)
return root.ExecArgs([]string{
"kitten", "@", "launch", "--type=window-dock", "--dock-edge=left", "--dock-size=60",
kitty, "+kitten", "help",
})
}
func show_basic_help() {
output := strings.Builder{}
fmt.Fprintln(&output, "Control kitty by sending it commands.")
@@ -110,7 +125,7 @@ func show_basic_help() {
}
}
fmt.Fprintln(&output, " ", formatter.Green("help"))
fmt.Fprintln(&output, " ", "Show this help")
fmt.Fprintln(&output, " ", "Show keyboard shortcuts")
fmt.Fprintln(&output, " ", formatter.Green("exit"))
fmt.Fprintln(&output, " ", "Exit this shell")
cli.ShowHelpInPager(output.String())
@@ -136,14 +151,14 @@ func exec_command(at_root_command *cli.Command, rl *readline.Readline, cmdline s
hi.ExitCode = 0
defer rl.AddHistoryItem(hi)
if len(parsed_cmdline) == 1 {
show_basic_help()
hi.ExitCode = launch_shortcuts_panel()
return true
}
switch parsed_cmdline[1] {
case "exit":
fmt.Println("Exit this shell")
case "help":
fmt.Println("Show help")
fmt.Println("Show keyboard shortcuts")
default:
sc := at_root_command.FindSubCommand(parsed_cmdline[1])
if sc == nil {
@@ -190,7 +205,7 @@ func completions(before_cursor, after_cursor string) (ans *cli.Completions) {
}
x.ShortDescription = desc
}
add_sc("help", "Show help")
add_sc("help", "Show keyboard shortcuts")
add_sc("exit", "Exit the kitty shell")
root.Validate()
ans = root.GetCompletions(argv, nil)