Skip to content

feat(tui): keybinding config (#463) - #570

Merged
ajianaz merged 4 commits into
developfrom
feat/463-keybindings
Nov 11, 2026
Merged

ajianaz merged 4 commits into
developfrom
feat/463-keybindings

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What

A keybinding config for the TUI: [tui.keys] in the user config rebinds ten convenience actions (toggle_tools, toggle_reasoning, model_picker, cycle_model, cycle_thinking, newline, queue_follow_up, pop_queue, history_prev, history_next), each to one key spec or a list (ctrl+o, alt+enter, shift+tab, f5, case-insensitive). The default keymap is exactly the keys the TUI always had.

Closes #463. The four parts: #567 fork/tree, #568 export/copy, #569 themes, and this one (keybinding config).

Why

Issue #463 asked for themes and a keybinding config file. Themes shipped in #569; this is the keybinding file. Keys are a safety surface (the approval answer, cancel), so the design makes the sensitive keys structurally non-rebindable and keeps a cloned repository from changing what a key does.

Changes

  • tole-tui: new keymap.rs (Keymap, KeyAction, KeySpec): closed action set, key-spec parsing, binding rules, clash check. App::with_keymap, defaulted TuiHost::keymap(); the startup note reuses the theme path. Key gains Left, Right, F(u8) (they were Key::Other).
  • Never rebindable: typing (any bare character), y / n at an approval prompt, Esc, Ctrl+C, Enter, Backspace, Tab. A binding needs Ctrl or Alt (or is F1 to F12, or shift+tab); bare Enter and bare arrows are refused (bare up / down only for history_prev / history_next, their defaults). Also refused: Ctrl+I/M/H/[ (terminals send Tab/Enter/Backspace/Esc), Ctrl+S/Q/Z/\ and Ctrl+digit. crossterm 0.29 in raw mode does deliver Ctrl+S/Q/Z/\ as ordinary keys (read in parse.rs and cfmakeraw), but they are refused because a terminal or multiplexer in between may eat them; Ctrl+4..7 arrive as the codes of Ctrl+\ ] ^ _.
  • Approval shield: the keymap is consulted only after Ctrl+C, the approval prompt and the picker, so at a prompt only y, n, Esc and Ctrl+C act. Second layer: Keymap::action never maps a bare character, Esc, Tab, Backspace, bare Enter or Ctrl+C, whatever the table says.
  • Behavior changes: at an approval prompt only plain y / n answer (Alt+Y / Ctrl+N used to); Shift+Enter and Alt+Enter never send, even unbound; Ctrl+Alt+letter no longer acts as Ctrl+letter; the /model and /thinking menu descriptions no longer name a key (COMMANDS length is unchanged at 13).
  • tole-cli: [tui.keys] parsed (string or list, type-strict) from the user layer only; config::layered drops a project table (same single startup warning, IGNORED in config check, no env var). Unknown action, bad or protected or ambiguous key, or a clash (message names both actions) gives the whole default keymap plus one startup note, never an abort. config check shows the effective result or INVALID: ..., and not validated: this build has no TUI ... in the bare profile.
  • Hints: the footer hint and the [+n lines · Ctrl+O] marker are built from the effective binding; the default renders the same text, including Shift+Tab thinking.
  • Docs: README status line, docs/epics.md (feat(tui): later polish — fork/tree, export/copy, themes, keybindings #463 done), CHANGELOG, docs/tui.md (keys table, [tui.keys] section), docs/threat-model.md.

An unknown action name is a note-and-fallback, not a hard config parse error (same as an unknown theme role), so a typo can never abort the TUI.

Size: about 1500 added lines (about 640 in keymap.rs, roughly half of that tests, plus docs) across 20 files. That is over the usual Cora line guidance, so watch for a timeout.

Testing

  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings: clean. cargo test --workspace: 1319 passed, 0 failed.
  • CI no-mcp commands: cargo check and cargo test -p tole-cli --no-default-features (402 passed), --features shell-tools check, clippy and test (510 passed), cargo check -p tole-core --no-default-features --tests: all green. Tests needing tole-tui are #[cfg(feature = "tui")], each with a bare-profile counterpart.
  • cargo test -p tole-cli --test tui_e2e three times in a row: 15 passed each. New pty tests: a user rebinding acts on the new key and not the old one (and the hint names it); an invalid keymap starts with the default and shows the note once. Both call t.idle() before /quit.
  • Unit tests (fake host, no crossterm types): default keymap pinned; every rebinding acts on the new key only; two keys per action; protected and bare keys, ambiguous keys and duplicates (both names) rejected; an approval prompt ignores every rebinding while y / n / Esc / Ctrl+C work; a hand-built hostile table cannot take protected keys.
  • Mutation checks (each made a test fail, then restored): project config sets keys; Esc/Backspace parse as bindable; dispatcher guard removed; Ctrl+C bindable; bare character accepted; duplicate accepted; invalid keymap panics instead of falling back; approval prompt dispatching a rebound action.
  • cora is not installed in this environment; I reviewed the staged diff by hand (config precedence, project boundary, approval path, parsing, error paths). The CI Cora Review is the gate.
  • Not verified: no network access to external hosts beyond the proxy; crossterm behavior was read from the local ~/.cargo/registry source, not quoted from memory.

@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 4bce1fe into develop Nov 11, 2026
19 of 20 checks passed
@ajianaz
ajianaz deleted the feat/463-keybindings branch November 20, 2026 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(tui): later polish — fork/tree, export/copy, themes, keybindings

2 participants