Add shortcut help popup

This commit is contained in:
2026-09-18 14:32:58 +00:00
parent 6e420b2db5
commit a5e8e32f1e
5 changed files with 268 additions and 8 deletions
+17 -4
View File
@@ -24,6 +24,7 @@ from urllib.parse import quote
from .aliases import AliasRegistry, AliasRegistryError, default_alias_registry_path
from .control import CONTROL_KEY, CONTROL_SHORTCUT, ControlMenu, HerdrControl
from .domain import validate_session_name
from .key_help import KeyHelpPopup
from .remotes import (
RegistryError,
RemoteEntry,
@@ -582,7 +583,7 @@ class TmuxHub:
["set-option", "-g", "mouse", "on"],
["set-option", "-g", "focus-events", "on"],
["set-option", "-g", "status-left-length", "18"],
["set-option", "-g", "status-right-length", "64"],
["set-option", "-g", "status-right-length", "14"],
[
"set-option",
"-g",
@@ -595,9 +596,9 @@ class TmuxHub:
"set-option",
"-g",
"status-right",
"#{?#{<:#{client_width},80},,"
"#[dim]#{?pane_dead,连接已断开 · C-a R 重连,"
f"{CONTROL_SHORTCUT} commands · C-a g choose · q close · r refresh}}#[default]}}",
"#{?#{<:#{client_width},50},"
"#[dim]C-a ?#[default],"
"#[dim]C-a ? 帮助#[default]}",
],
["set-option", "-g", "status-style", "bg=colour235,fg=colour250"],
["set-window-option", "-g", "window-status-separator", ""],
@@ -640,6 +641,7 @@ class TmuxHub:
[self.python_bin, self.script_path, "close", "--window", "#{window_id}"]
)
control = shlex.join([self.python_bin, self.script_path, "control"])
key_help = shlex.join([self.python_bin, self.script_path, "keys"])
confirm_close = shlex.join(["run-shell", "-b", close])
# Remove tmux's default/legacy '&' binding when reconfiguring both new
# and already-running Hub servers.
@@ -649,6 +651,8 @@ class TmuxHub:
# prototype when reconfiguring an already-running Hub.
self.run(["unbind-key", "-T", "root", "C-g"], check=False)
binding_commands = [
["bind-key", "-T", "prefix", "?", "display-popup", "-EE",
"-w", "72%", "-h", "80%", "-T", "快捷键", key_help],
["bind-key", "-T", "prefix", CONTROL_KEY, "display-popup", "-EE",
"-w", "80%", "-h", "50%", "-T", "Herdr 命令", control],
["bind-key", "-T", "prefix", "C-a", "send-prefix"],
@@ -1451,6 +1455,13 @@ def command_control(arguments: argparse.Namespace) -> int:
return curses.wrapper(ControlMenu(control).run)
def command_keys(arguments: argparse.Namespace) -> int:
try:
return curses.wrapper(KeyHelpPopup().run)
except curses.error as error:
raise HubError(f"无法打开快捷键帮助: {error}") from error
def command_remote(arguments: argparse.Namespace) -> int:
registry = make_registry()
action = arguments.remote_command
@@ -1600,6 +1611,7 @@ def build_parser() -> argparse.ArgumentParser:
control_parser = subparsers.add_parser("control", help="open Herdr commands for the current Hub window")
control_parser.add_argument("--window", help="originating tmux window ID")
subparsers.add_parser("keys", help="show Hub shortcut mappings")
subparsers.add_parser("choose", help="browse and open local or remote sessions")
remote_parser = subparsers.add_parser("remote", help="manage remembered remote targets")
remote_subparsers = remote_parser.add_subparsers(dest="remote_command")
@@ -1644,6 +1656,7 @@ def main(argv: Sequence[str] | None = None) -> int:
"open": command_open,
"choose": command_choose,
"control": command_control,
"keys": command_keys,
"remote": command_remote,
"reconnect": command_reconnect,
"close": command_close,