Repository navigation
feat(tui): keybinding config (#463) - #570
Merged
Merged
Conversation
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: newkeymap.rs(Keymap,KeyAction,KeySpec): closed action set, key-spec parsing, binding rules, clash check.App::with_keymap, defaultedTuiHost::keymap(); the startup note reuses the theme path.KeygainsLeft,Right,F(u8)(they wereKey::Other).y/nat an approval prompt, Esc, Ctrl+C, Enter, Backspace, Tab. A binding needs Ctrl or Alt (or is F1 to F12, orshift+tab); bare Enter and bare arrows are refused (bareup/downonly forhistory_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 inparse.rsandcfmakeraw), but they are refused because a terminal or multiplexer in between may eat them; Ctrl+4..7 arrive as the codes of Ctrl+\ ] ^ _.y,n, Esc and Ctrl+C act. Second layer:Keymap::actionnever maps a bare character, Esc, Tab, Backspace, bare Enter or Ctrl+C, whatever the table says.y/nanswer (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/modeland/thinkingmenu descriptions no longer name a key (COMMANDSlength is unchanged at 13).tole-cli:[tui.keys]parsed (string or list, type-strict) from the user layer only;config::layereddrops a project table (same single startup warning,IGNOREDinconfig 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 checkshows the effective result orINVALID: ..., andnot validated: this build has no TUI ...in the bare profile.[+n lines · Ctrl+O]marker are built from the effective binding; the default renders the same text, includingShift+Tab thinking.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.no-mcpcommands:cargo checkandcargo test -p tole-cli --no-default-features(402 passed),--features shell-toolscheck, clippy and test (510 passed),cargo check -p tole-core --no-default-features --tests: all green. Tests needingtole-tuiare#[cfg(feature = "tui")], each with a bare-profile counterpart.cargo test -p tole-cli --test tui_e2ethree 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 callt.idle()before/quit.y/n/ Esc / Ctrl+C work; a hand-built hostile table cannot take protected keys.corais 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.~/.cargo/registrysource, not quoted from memory.