diff --git a/kittens/help/__init__.py b/kittens/help/__init__.py new file mode 100644 index 0000000..820dbc6 --- /dev/null +++ b/kittens/help/__init__.py @@ -0,0 +1 @@ +# License: GPLv3 Copyright: 2026, FWS diff --git a/kittens/help/main.py b/kittens/help/main.py new file mode 100644 index 0000000..1460a4c --- /dev/null +++ b/kittens/help/main.py @@ -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' diff --git a/tools/cmd/at/shell.go b/tools/cmd/at/shell.go index 9a359b1..9fea4d9 100644 --- a/tools/cmd/at/shell.go +++ b/tools/cmd/at/shell.go @@ -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)