Skip to content

terminal: customizable keybindings and terminal collision fixes (#104) - #294

Merged
bbondy merged 14 commits into
brave:mainfrom
winshaurya:fix-issue-104
Sep 15, 2026
Merged

bbondy merged 14 commits into
brave:mainfrom
winshaurya:fix-issue-104

Conversation

@winshaurya

Copy link
Copy Markdown
Contributor

Resolves #104

Summary of Changes

This change adds support for customizable keybindings in settings, resolving terminal collisions where default chords collided with terminal conventions (specifically ctrl-s XOFF flow control and ctrl-o discard output / flush).

  1. Configurable Keybindings in Settings (crates/config):

    • Added keybindings: BTreeMap<String, String> to Settings.
    • Supports keybindings in configuration files via:
      • Standard settings map: "keybindings": { "stash": "ctrl-x", "scroller": "ctrl-u" }
      • Claude Code compatible array format: "bindings": [ { "chord": "ctrl-x", "action": "stash" } ]
      • Dedicated layered keybindings.json file in ~/.bravebot/keybindings.json and .bravebot/keybindings.json.
  2. Validation and Safety Invariants (crates/tui):

    • Added KeyChord parser in crates/tui/src/keybindings.rs supporting both - and + delimiters (e.g. ctrl-s and ctrl+s).
    • Configurable actions: editor, watch, scroller, history, stash, trail, paste.
    • Safety invariants: Non-remappable terminal control keys (ctrl-c, esc, bare enter, bare typing keys) are protected against remapping. Any conflicting, malformed, or reserved binding falls back safely to its default chord.
  3. Dynamic Routing and Rendering (crates/tui):

    • Event routing across idle input, running turns, scroller, and navigation matches dynamically configured chords.
    • The ? shortcut modal dynamically renders the configured chord names.
    • The stashed_lines row beneath the input box dynamically names the active stash chord (e.g. ctrl-x to bring it back).
    • The hint line dynamically reflects the active trail toggle chord.
  4. Specifications and Automated Tests (docs/specs):

    • Added specification clause INPUT-28 to docs/specs/terminal-input.md.
    • Added comprehensive unit tests for parser robustness, collision handling, reserved chord rejection, and TUI dynamic rendering.

cc @bbondy

winshaurya and others added 12 commits September 14, 2026 19:16
The clause said bare typing characters were reserved and nothing checked for one.
`is_reserved` answered for Ctrl-C, bare Enter and bare Escape only, so a settings
file could hand an action a letter, and the arms that read a configured chord sit
above the arm that types: under `"stash": "x"` the letter x stashed the line
instead of being written, and there was then no way to type it at all.

Refuse the whole unmodified half of the keyboard rather than list the keys that
happen to be taken today, since every one of them is answered already: a character
is typed into the line, Enter sends, Escape clears it, Tab takes what is offered,
and the arrows walk the caret and the history. Shift over a character goes too,
for a different reason: a terminal reports Shift-A as `A` with Shift held, so a
chord written `shift-a` names an event that never arrives, and taking it would
leave the action quietly dead rather than on a key that works. Ctrl-J, Shift-Enter
and Ctrl-D join Ctrl-C as the rest of what INPUT-2 and INPUT-4 fix.

Ctrl-S and Ctrl-O, the two chords the issue is about, are reachable under the rule.

Part of brave#104
Resolving the chords one action at a time left two of them on one key. Each request
was checked against the chords already taken, but an action reached later kept its
default whether or not that default had just been given away, and the check meant
to catch it could only decline to write a value already in the slot. So
`"stash": "ctrl-o"` put stash on the scroller's chord and left the scroller there
too: Ctrl-O opened the scroller, stash could not be reached by any key, and the
list `?` puts up named Ctrl-O twice. That is the dead key the issue asks a fallback
to avoid, arrived at by way of the fallback.

Read every request first, then let an action keep its chord only where no other
action still stands on it. Where one is contested both give it up, since neither
asked with more right than the other and letting the first win would turn on the
order the code reads them in. Giving one up puts an action back on a default a
third may have been handed, so this settles rather than deciding once; with no
requests left the defaults stand, and those differ.

Trading two chords still works, which is what weighing a request against where the
others end up rather than against the defaults is for.

Part of brave#104
Three of the four shapes the parser accepted were in no clause, and one of them
could not be read reliably at all. `is_chord` decided whether a JSON pair was
action-to-chord or chord-to-action by looking for a hyphen, so an action a later
release spells with one would be read as the chord and its chord as the action
name. A `bindings` array in Claude Code's shape was accepted as well, keyed on a
nested object the pull request describing it did not match, and against no fixture
taken from that tool.

A second file, `keybindings.json`, was read after all three settings layers, so a
person's own `~/.bravebot/keybindings.json` overrode a project's
`settings.local.json` and inverted the precedence every other key follows. It was
also merged without being pushed onto `layers` or weighed for `contested`, so the
file that decided a chord would have been reported nowhere.

Keep the `keybindings` block in `settings.json` and drop the rest. brave#104 offers the
separate file only as an alternative to whatever settings clause came out of brave#89,
and brave#89 landed, so the block is the answer and a second file adds a precedence
question for no capability. An entry that is not a string is dropped the way a
malformed permission rule is, and a spelling nothing can read is still carried this
far and left on its default in the interface.

Restore the note on why `attribution` merges per name, which is a decision a reader
cannot recover from the code, and say the chords merge that way for the same
reason.

Part of brave#104
The list `?` puts up was left duplicated: a static table for the tests and a
second one built from the bindings for the screen. They had already drifted, so
the copy on screen no longer said that Ctrl-S searches as well as stashes. One
table now, taking the seven movable chords from the bindings, and the tests read
the same one at their defaults.

The scroller's way out named Ctrl-C among the keys while the meaning beside them
already said "also ctrl-c", so the row listed one press as two. The keys name
what opened the scroller and the meaning keeps Ctrl-C.

Part of brave#104
Six messages had a chord written into the sentence, so a session that moved one
went on being told to press the key it had moved away from: the border while an
older prompt is walked back to, the keys under the prompt search, the hint that
there is something to watch, the note about a picture on the clipboard, and the
line saying an aside can be opened again. Each takes the chord as an argument
now, in en-US and fr both, and the clipboard hint takes it from the bindings.

Part of brave#104
Inside the prompt search and the delegate view the chords were still matched off
the keyboard, so a moved one was read as the letter it carries: bound to alt-s,
the chord that narrows the search typed an `s` into the needle instead, and bound
to alt-j the chord that leaves the delegate view walked the list. Both now ask
the bindings, and ahead of the arms that take a character, since those match
whatever is held with it.

Also drops a comment the same paragraph twice in the scroller's search keys.

Part of brave#104
The rebase left it sharing an id with the clause about searching this workspace,
and its count was never added to the table check-spec holds the file to. Nothing
about what it says changes; the title now reads as what the clause is for.

Closes brave#104
@winshaurya

Copy link
Copy Markdown
Contributor Author

did another pass over the keybinding flow and found two more edge cases: configured bindings could still be consumed by readline editing, and vi-mode history search was still using a hard-coded shortcut. fixed both and added regression tests. also rechecked the existing collision, precedence, and alternate-mode cases.

bbondy
bbondy previously approved these changes Sep 15, 2026

@bbondy bbondy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great addition!

@bbondy
bbondy merged commit 9bc9a0e into brave:main Sep 15, 2026
16 checks passed
@winshaurya
winshaurya deleted the fix-issue-104 branch October 10, 2026 20:11
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.

terminal input: keybindings are fixed, and two of them collide with long-standing terminal conventions

3 participants