feat(input): negotiate keyboard enhancement protocol when supported#124
Open
laurigates wants to merge 1 commit into
Open
feat(input): negotiate keyboard enhancement protocol when supported#124laurigates wants to merge 1 commit into
laurigates wants to merge 1 commit into
Conversation
jnv enabled raw mode but never requested the keyboard enhancement (kitty) protocol, so terminals fell back to legacy encoding. There, Ctrl+J is indistinguishable from Enter (both 0x0A) and Ctrl+I from Tab, so bindings like the JSON viewer's `down = Ctrl+J` could never fire, and modified/bracket keys were reported inconsistently. Push `DISAMBIGUATE_ESCAPE_CODES` at startup when `supports_keyboard_enhancement()` reports support, and pop it on teardown. Terminals without support keep the prior legacy behavior. Because keybinds are matched by exact `Event` equality, enabling the protocol requires canonicalizing incoming events: drop non-`Press` kinds (releases/repeats become possible under the protocol) and strip `KeyEventState` lock bits (Caps/Num Lock) so a binding matches regardless of lock state. This is done once at the event-dispatch chokepoint via a pure `normalize_event` helper, covering every downstream matcher, with unit tests.
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
Negotiate the keyboard enhancement ("kitty") protocol at startup when the
terminal advertises support, and pop it on teardown.
jnv enables raw mode but never requests the protocol, so supporting terminals
fall back to legacy encoding. In legacy mode
Ctrl+Jis indistinguishable fromEnter(both0x0A) andCtrl+IfromTab, so the JSON viewer's defaultdown = ["Down", "Ctrl+J", "ScrollDown"]binding can never fire viaCtrl+J(it lands on
Enter/toggle instead), and modified/bracket keys are reportedinconsistently across terminals.
How
main.rs: whensupports_keyboard_enhancement()reports support, pushKeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES;TerminalCleanupGuardpops it on drop. Terminals without support keep the exact prior behavior.
event_dispatcher.rs: keybinds are matched by exactEventequality, soenabling the protocol requires canonicalizing incoming events. Added a pure
normalize_eventhelper at the single event-dispatch chokepoint (covers everydownstream matcher) that drops non-
Pressevents (releases/repeats becomepossible under the protocol) and strips
KeyEventStatelock bits (Caps/NumLock) so a binding matches regardless of lock state. The existing scroll
position-zeroing moved into the same helper. Unit-tested.
Deliberately requests only
DISAMBIGUATE_ESCAPE_CODES— notREPORT_EVENT_TYPES/REPORT_ALL_KEYS— to keep the event stream close to legacy(no release-event noise) while fixing the ambiguous-control-key class.
Verification
cargo fmt --all -- --check,cargo clippy, andcargo testall pass.Manually verified on kitty (macOS):
Ctrl+J/Ctrl+Know scroll the JSON vieweras bound; bracket entry on a Finnish layout is unaffected.
Notes / open questions
This is offered as "here's what made jnv work better for me on kitty" — happy to
adjust or drop it if it doesn't fit the roadmap.
where
supports_keyboard_enhancement()and protocol passthrough arehistorically finicky. If you have tmux users, that path may warrant a look.
terminals (
Ctrl+J≠Enter,Ctrl+I≠Tab). That's the intended fix, butflagging it explicitly.
normalize_eventapproach keeps the existing exact-Eventmatching; ifyou'd prefer a different matching strategy, glad to rework.