feat: Complete legacy keyboard protocol for extra keys#943
Conversation
📝 WalkthroughWalkthroughRefactors terminal keyboard event handling by introducing a centralized Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🔇 Additional comments (5)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #943 +/- ##
==========================================
+ Coverage 60.62% 61.00% +0.38%
==========================================
Files 37 37
Lines 3256 3293 +37
==========================================
+ Hits 1974 2009 +35
- Misses 1124 1125 +1
- Partials 158 159 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
mock/term_test.go (1)
481-502: Good coverage for special keys.The test correctly validates the legacyKeys mappings for Tab, Backspace, Space, and Return with various modifiers.
Consider adding a test case for Alt+Ctrl+letter (e.g.,
Alt+Ctrl+a) to verify the fallback path handles the Alt prefix correctly — this would also catch the dead code issue mentioned in the emulate.go review.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
mock/term_test.govt/emulate.go
🧰 Additional context used
🧬 Code graph analysis (2)
mock/term_test.go (1)
vt/kbd.go (11)
KbdEvent(17-24)KcF1(193-193)ModShift(30-30)KcF2(194-194)ModCtrl(31-31)KcF3(195-195)ModAlt(32-32)KcReturn(62-62)KcTab(61-61)KcBackspace(60-60)KcSpace(64-64)
vt/emulate.go (2)
vt/kbd.go (36)
KeyCode(56-56)KcF1(193-193)KcF2(194-194)KcF3(195-195)KcF4(196-196)KcF5(197-197)KcF6(198-198)KcF7(199-199)KcF8(200-200)KcF9(201-201)KcF10(202-202)KcF11(203-203)KcF12(204-204)KcUp(80-80)KcDown(81-81)KcRight(83-83)KcLeft(82-82)KcHome(91-91)KcEnd(92-92)KcPgUp(89-89)KcPgDn(90-90)KcDel(94-94)KcIns(93-93)KcMenu(70-70)KcTab(61-61)KcBackspace(60-60)KcDelete(65-65)KcSpace(64-64)KcReturn(62-62)KcEsc(63-63)KbdEvent(17-24)ModMeta(33-33)ModShift(30-30)ModCtrl(31-31)ModNone(29-29)ModAlt(32-32)input.go (1)
P(887-887)
🔇 Additional comments (5)
vt/emulate.go (3)
916-952: Well-structured legacy key mapping table.The centralized
legacyKeysmap is a good approach for maintainability. A few observations:
The
Pfield for keypad mode is defined for arrow/navigation keys but the TODO at line 967 indicates it's not yet implemented.Consider documenting the modifier encoding convention (e.g., that CSI sequences use
mod+1where shift=1, ctrl=4).
983-1006: Modifier sequence construction looks correct.The logic properly handles:
- SS3-to-CSI conversion for modified F1-F4 keys
- Modifier encoding using xterm conventions (shift=+1, ctrl=+4)
- ESC prefix for Alt key
One minor note: Line 999 assumes
v.Khas length ≥ 1. This is safe given the current map entries, but you might want defensive checks if the map could be extended externally.
1018-1024: LGTM!The fallback for printable ASCII keys correctly handles the Alt modifier using bitwise check, unlike the control-key fallback above.
mock/term_test.go (2)
436-457: Good test coverage for SS3-based F-keys.The tests correctly validate:
- Unmodified SS3 sequences
- SS3-to-CSI conversion with modifiers
- Alt prefix handling with combined modifiers
- Key release events (Down: false) producing no output
459-479: LGTM!CSI-based F-key tests correctly validate the modifier insertion format (
;{mod}before the final~).
a76cafe to
9034b90
Compare
Summary by CodeRabbit
Tests
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.