pub const ROOT_DEFAULTS: &[(&str, &str)] = &[
("PageUp", "copy-mode -u"),
];
pub const PREFIX_DEFAULTS: &[(&str, &str)] = &[
("c", "new-window"),
("n", "next-window"),
("p", "previous-window"),
("l", "last-window"),
("w", "choose-tree"),
("&", "kill-window"),
(",", "rename-window"),
("'", "select-window-index"),
("0", "select-window -t :0"),
("1", "select-window -t :1"),
("2", "select-window -t :2"),
("3", "select-window -t :3"),
("4", "select-window -t :4"),
("5", "select-window -t :5"),
("6", "select-window -t :6"),
("7", "select-window -t :7"),
("8", "select-window -t :8"),
("9", "select-window -t :9"),
("%", "split-window -h"),
("\"", "split-window -v"),
("Up", "select-pane -U"),
("Down", "select-pane -D"),
("Left", "select-pane -L"),
("Right", "select-pane -R"),
("o", "select-pane -t +"),
(";", "last-pane"),
("q", "display-panes"),
("x", "kill-pane"),
("z", "resize-pane -Z"),
("{", "swap-pane -U"),
("}", "swap-pane -D"),
("!", "break-pane"),
("C-Up", "resize-pane -U"),
("C-Down", "resize-pane -D"),
("C-Left", "resize-pane -L"),
("C-Right", "resize-pane -R"),
("M-Up", "resize-pane -U 5"),
("M-Down", "resize-pane -D 5"),
("M-Left", "resize-pane -L 5"),
("M-Right", "resize-pane -R 5"),
("Space", "next-layout"),
("M-1", "select-layout even-horizontal"),
("M-2", "select-layout even-vertical"),
("M-3", "select-layout main-horizontal"),
("M-4", "select-layout main-vertical"),
("M-5", "select-layout tiled"),
("d", "detach-client"),
("$", "rename-session"),
("[", "copy-mode"),
("]", "paste-buffer"),
("=", "choose-buffer"),
("#", "list-buffers"),
(":", "command-prompt"),
("?", "list-keys"),
("i", "display-message"),
("t", "clock-mode"),
("s", "choose-session"),
("(", "switch-client -p"),
(")", "switch-client -n"),
("v", "rectangle-toggle"),
("y", "copy-yank"),
];
pub fn copy_mode_vi_lines() -> Vec<String> {
let mut v = Vec::new();
v.push(String::new());
v.push("── copy-mode-vi ──────────────────────────────────────────".into());
for (k, desc) in COPY_MODE_VI {
v.push(format!("bind-key -T copy-mode-vi {} {}", k, desc));
}
v
}
const COPY_MODE_VI: &[(&str, &str)] = &[
("Escape", "cancel (exit copy mode)"),
("q", "cancel (exit copy mode)"),
("h", "cursor-left"),
("j", "cursor-down"),
("k", "cursor-up"),
("l", "cursor-right"),
("Left", "cursor-left"),
("Down", "cursor-down"),
("Up", "cursor-up"),
("Right", "cursor-right"),
("w", "next-word"),
("b", "previous-word"),
("e", "next-word-end"),
("W", "next-space"),
("B", "previous-space"),
("E", "next-space-end"),
("0", "start-of-line"),
("$", "end-of-line"),
("^", "back-to-indentation"),
("Home", "start-of-line"),
("End", "end-of-line"),
("C-u", "halfpage-up"),
("C-d", "halfpage-down"),
("C-b", "page-up"),
("C-f", "page-down"),
("PageUp", "page-up"),
("PageDown", "page-down"),
("g", "history-top"),
("G", "history-bottom"),
("H", "top-line"),
("M", "middle-line"),
("L", "bottom-line"),
("f{char}", "jump-forward"),
("F{char}", "jump-backward"),
("t{char}", "jump-to-forward"),
("T{char}", "jump-to-backward"),
("%", "next-matching-bracket"),
("{", "previous-paragraph"),
("}", "next-paragraph"),
("v", "rectangle-toggle"),
("V", "select-line"),
("C-v", "rectangle-toggle"),
("Space", "begin-selection"),
("o", "other-end (swap cursor/anchor)"),
("y", "copy-selection-and-cancel"),
("Enter", "copy-selection-and-cancel"),
("D", "copy-end-of-line-and-cancel"),
("A", "append-selection-and-cancel"),
("/", "search-forward"),
("?", "search-backward"),
("n", "search-again"),
("N", "search-reverse"),
("\"{a-z}", "set register for next yank"),
("aw", "select-word (a word)"),
("iw", "select-word (inner word)"),
("1-9", "numeric prefix for motions"),
];
pub fn copy_search_lines() -> Vec<String> {
let mut v = Vec::new();
v.push(String::new());
v.push("── copy-mode search ──────────────────────────────────────".into());
for (k, desc) in COPY_SEARCH {
v.push(format!("bind-key -T copy-mode-search {} {}", k, desc));
}
v
}
const COPY_SEARCH: &[(&str, &str)] = &[
("Escape", "cancel search"),
("Enter", "accept search / jump to match"),
("Backspace", "delete character"),
("{char}", "append character to search pattern"),
];
pub fn command_prompt_lines() -> Vec<String> {
let mut v = Vec::new();
v.push(String::new());
v.push("── command-prompt ─────────────────────────────────────────".into());
for (k, desc) in COMMAND_PROMPT {
v.push(format!(" {} {}", k, desc));
}
v
}
const COMMAND_PROMPT: &[(&str, &str)] = &[
("Escape", "cancel"),
("Enter", "execute command (saved to history)"),
("Backspace", "delete char before cursor"),
("Delete", "delete char at cursor"),
("Left", "move cursor left"),
("Right", "move cursor right"),
("Home", "move cursor to start"),
("End", "move cursor to end"),
("Up", "history: older command"),
("Down", "history: newer command"),
("C-a", "move cursor to start"),
("C-e", "move cursor to end"),
("C-u", "kill line (clear to start)"),
("C-k", "kill to end of line"),
("C-w", "delete word backwards"),
];
pub fn cli_command_lines() -> Vec<String> {
let mut v = Vec::new();
v.push(String::new());
v.push("── commands ───────────────────────────────────────────────".into());
v.push(" (alias) description".into());
for (name, alias, desc) in CLI_COMMANDS {
if alias.is_empty() {
v.push(format!(" {:<24}{}", name, desc));
} else {
v.push(format!(" {:<13}({:<9}) {}", name, alias, desc));
}
}
v
}
const CLI_COMMANDS: &[(&str, &str, &str)] = &[
("attach-session", "attach", "Attach to an existing session"),
("detach-client", "detach", "Detach from the current session"),
("has-session", "has", "Check if a session exists"),
("kill-server", "", "Kill the server and all sessions"),
("kill-session", "", "Destroy a session"),
("list-sessions", "ls", "List sessions"),
("new-session", "new", "Create a new session"),
("rename-session", "rename", "Rename the current session"),
("switch-client", "switchc", "Switch to another session"),
("choose-tree", "", "Interactive session/window chooser"),
("find-window", "findw", "Search for a window by name"),
("kill-window", "killw", "Destroy the current window"),
("last-window", "last", "Select the previous window"),
("link-window", "linkw", "Link window into another session"),
("list-windows", "lsw", "List windows"),
("move-window", "movew", "Move window to another index"),
("new-window", "neww", "Create a new window"),
("next-window", "next", "Move to the next window"),
("previous-window", "prev", "Move to the previous window"),
("rename-window", "renamew", "Rename the current window"),
("resize-window", "resizew", "Resize a window"),
("respawn-window", "respawnw", "Restart the process in a window"),
("rotate-window", "rotatew", "Rotate pane positions"),
("select-window", "selectw", "Select a window by index"),
("swap-window", "swapw", "Swap two windows"),
("unlink-window", "unlinkw", "Unlink a window from the session"),
("break-pane", "breakp", "Break pane out to a new window"),
("capture-pane", "capturep", "Capture pane contents to buffer"),
("display-panes", "displayp", "Show pane numbers"),
("join-pane", "joinp", "Move a pane into another window"),
("kill-pane", "killp", "Kill the active pane"),
("last-pane", "lastp", "Select the previously active pane"),
("move-pane", "movep", "Move a pane to another window"),
("pipe-pane", "pipep", "Pipe pane output to a command"),
("resize-pane", "resizep", "Resize a pane (-Z to zoom)"),
("respawn-pane", "respawnp", "Restart the process in a pane"),
("select-pane", "selectp", "Select/focus a pane"),
("split-window", "splitw", "Split current pane"),
("swap-pane", "swapp", "Swap two panes"),
("next-layout", "nextl", "Cycle to the next layout"),
("previous-layout", "prevl", "Cycle to the previous layout"),
("select-layout", "selectl", "Apply a layout preset"),
("choose-buffer", "chooseb", "Interactive buffer chooser"),
("clear-history", "clearhist","Clear pane scrollback"),
("copy-mode", "", "Enter copy mode"),
("delete-buffer", "deleteb", "Delete a paste buffer"),
("list-buffers", "lsb", "List paste buffers"),
("load-buffer", "loadb", "Load buffer from file"),
("paste-buffer", "pasteb", "Paste buffer into pane"),
("save-buffer", "saveb", "Save buffer to file"),
("set-buffer", "setb", "Set a buffer's contents"),
("show-buffer", "showb", "Show buffer contents"),
("bind-key", "bind", "Bind a key to a command"),
("list-keys", "lsk", "List key bindings"),
("unbind-key", "unbind", "Unbind a key"),
("set-option", "set", "Set a session/server option"),
("set-window-option", "setw", "Set a window option"),
("show-options", "show", "Show options"),
("show-window-options","showw", "Show window options"),
("source-file", "source", "Load config file"),
("clock-mode", "", "Show a large clock"),
("command-prompt", "", "Open the command prompt"),
("display-menu", "menu", "Display an interactive menu"),
("display-message", "display", "Display a message / pane info"),
("display-popup", "popup", "Display a popup window"),
("list-commands", "lscm", "List available commands"),
("server-info", "info", "Show server information"),
("confirm-before", "confirm", "Confirm before running command"),
("if-shell", "if", "Conditional command execution"),
("list-clients", "lsc", "List connected clients"),
("refresh-client", "refresh", "Refresh the client display"),
("run-shell", "run", "Run a shell command"),
("send-keys", "send", "Send keys/text to a pane"),
("set-environment", "setenv", "Set an environment variable"),
("set-hook", "", "Set a hook on an event"),
("show-environment", "showenv", "Show environment variables"),
("show-hooks", "", "Show defined hooks"),
("show-messages", "showmsgs", "Show server message log"),
("wait-for", "wait", "Wait/signal a named channel"),
];
pub fn options_lines() -> Vec<String> {
let mut v = Vec::new();
v.push(String::new());
v.push("── options (set-option / set) ──────────────────────────────".into());
v.push(" option default".into());
for (name, default) in OPTIONS_REF {
v.push(format!(" {:<30}{}", name, default));
}
v
}
const OPTIONS_REF: &[(&str, &str)] = &[
("prefix", "C-b"),
("prefix2", "none"),
("escape-time", "500"),
("base-index", "0"),
("pane-base-index", "0"),
("history-limit", "2000"),
("mouse", "on"),
("mode-keys", "emacs"),
("focus-events", "off"),
("remain-on-exit", "off"),
("renumber-windows", "off"),
("aggressive-resize", "off"),
("automatic-rename", "on"),
("synchronize-panes", "off"),
("set-titles", "off"),
("allow-passthrough", "off"),
("default-command", "(system shell)"),
("word-separators", "\" -_@\""),
("display-time", "750"),
("display-panes-time", "1000"),
("status-interval", "15"),
("status", "on"),
("status-position", "bottom"),
("status-justify", "left"),
("status-left", "\"[#S] \""),
("status-right", "\"#{?window_bigger,[#{window_offset_x}#,#{window_offset_y}] ,}\"#{=21:pane_title}\" %H:%M %d-%b-%y\""),
("status-left-length", "10"),
("status-right-length", "40"),
("status-style", "bg=green,fg=black"),
("status-left-style", "\"\""),
("status-right-style", "\"\""),
("window-status-format", "#I:#W#{...}"),
("window-status-current-format", "#I:#W#{...}"),
("window-status-separator", "\" \""),
("window-status-style", "\"\""),
("window-status-current-style","\"\""),
("window-status-activity-style","reverse"),
("window-status-bell-style", "reverse"),
("window-status-last-style", "\"\""),
("pane-border-style", "\"\""),
("pane-active-border-style", "fg=green"),
("pane-border-hover-style", "fg=yellow"),
("message-style", "bg=yellow,fg=black"),
("message-command-style", "bg=black,fg=yellow"),
("mode-style", "bg=yellow,fg=black"),
("monitor-activity", "off"),
("monitor-silence", "0"),
("visual-activity", "off"),
("visual-bell", "off"),
("bell-action", "any"),
("main-pane-width", "0 (60% heuristic)"),
("main-pane-height", "0 (60% heuristic)"),
("copy-command", "\"\""),
("set-clipboard", "on"),
("set-titles-string", "\"\""),
("cursor-style", "\"\""),
("cursor-blink", "off"),
("prediction-dimming", "off"),
("allow-predictions", "off"),
("env-shim", "on"),
("claude-code-fix-tty", "on"),
("claude-code-force-interactive", "on"),
];
pub fn format_vars_lines() -> Vec<String> {
let mut v = Vec::new();
v.push(String::new());
v.push("── format variables (#{...}) ───────────────────────────────".into());
for (group, vars) in FORMAT_GROUPS {
v.push(format!(" {}:", group));
v.push(format!(" {}", vars));
}
v.push(String::new());
v.push(" Modifiers: #{=N:var} truncate, #{T:var} strftime,".into());
v.push(" #{?test,true,false} conditional, #{==:a,b} compare,".into());
v.push(" #{e:var} shell escape, #{b:var} basename,".into());
v.push(" #{d:var} dirname, #{m:pat,str} match, #{s/p/r/:var} sub".into());
v
}
const FORMAT_GROUPS: &[(&str, &str)] = &[
("Session", "session_name session_id session_windows session_attached session_created session_path ..."),
("Window", "window_index window_name window_active window_panes window_flags window_id window_layout window_zoomed_flag ..."),
("Pane", "pane_index pane_id pane_title pane_width pane_height pane_active pane_current_command pane_current_path pane_pid pane_dead ..."),
("Cursor", "cursor_x cursor_y cursor_character cursor_flag"),
("Copy", "copy_cursor_x copy_cursor_y copy_cursor_word copy_cursor_line selection_present search_present scroll_position"),
("Buffer", "buffer_name buffer_size buffer_sample buffer_created"),
("Client", "client_width client_height client_name client_session client_prefix client_pid client_termname ..."),
("Server", "pid version host hostname host_short"),
("Misc", "history_limit history_size alternate_on pane_mode pane_in_mode"),
];
pub fn hooks_lines() -> Vec<String> {
let mut v = Vec::new();
v.push(String::new());
v.push("── hooks (set-hook) ───────────────────────────────────────".into());
v.push(" after-new-session after-new-window after-kill-pane".into());
v.push(" after-split-window after-select-window after-select-pane".into());
v.push(" after-resize-pane after-rename-window after-rename-session".into());
v.push(" after-select-layout after-copy-mode after-set-option".into());
v.push(" after-bind-key after-unbind-key after-source".into());
v.push(" after-swap-pane after-swap-window client-attached".into());
v.push(" client-detached".into());
v
}
pub fn mouse_lines() -> Vec<String> {
let mut v = Vec::new();
v.push(String::new());
v.push("── mouse bindings (when mouse is on) ──────────────────────".into());
v.push(" Left click status tab switch to clicked window".into());
v.push(" Left click pane focus pane (+ forward to child)".into());
v.push(" Left click border begin drag-resize".into());
v.push(" Left drag border resize split interactively".into());
v.push(" Scroll up/down forward wheel to child (or copy mode scroll)".into());
v
}
pub fn build_overlay_lines(
user_bindings: &[(bool, String, String, String)],
_defaults_suppressed: bool,
) -> Vec<String> {
let mut lines: Vec<String> = Vec::new();
lines.push("── prefix table (C-b + key) ───────────────────────────────".into());
let prefix_bindings: Vec<_> = user_bindings.iter()
.filter(|(_, t, _, _)| t == "prefix")
.collect();
for (repeat, table, key, cmd) in &prefix_bindings {
let r = if *repeat { " -r" } else { "" };
lines.push(format!("bind-key{} -T {} {} {}", r, table, key, cmd));
}
let non_prefix: Vec<_> = user_bindings.iter()
.filter(|(_, t, _, _)| t != "prefix")
.collect();
if !non_prefix.is_empty() {
lines.push(String::new());
lines.push("── other table bindings ───────────────────────────────────".into());
for (repeat, table, key, cmd) in &non_prefix {
let r = if *repeat { " -r" } else { "" };
lines.push(format!("bind-key{} -T {} {} {}", r, table, key, cmd));
}
}
lines.extend(copy_mode_vi_lines());
lines.extend(copy_search_lines());
lines.extend(command_prompt_lines());
lines.extend(mouse_lines());
lines.extend(cli_command_lines());
lines.extend(options_lines());
lines.extend(format_vars_lines());
lines.extend(hooks_lines());
lines
}
pub fn build_list_keys_output<'a>(
user_tables: impl Iterator<Item = (&'a str, String, String, bool)>,
_defaults_suppressed: bool,
) -> String {
let mut output = String::new();
let user_entries: Vec<(&str, String, String, bool)> = user_tables.collect();
for (table, key, action, repeat) in &user_entries {
let r = if *repeat { " -r" } else { "" };
output.push_str(&format!("bind-key{} -T {} {} {}\n", r, table, key, action));
}
output
}