Skip to content

feat(emulator): Implement keypad handling correctly - #1015

Merged
gdamore merged 2 commits into
mainfrom
keypad
Jan 26, 2026
Merged

gdamore merged 2 commits into
mainfrom
keypad

Conversation

@gdamore

@gdamore gdamore commented Jan 26, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Improved keypad behavior: application vs numeric keypad modes can now be toggled via escape sequences and produce correct key sequences across modes.
  • Tests

    • Added thorough US International keyboard tests covering Caps Lock and Num Lock behavior with keypad/application modes.
  • Chores

    • Standardized the default US keyboard naming; minor test helper annotation added to improve test diagnostics.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 26, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Adds application/numeric keypad mode support to the terminal emulator: tracks keypad state, parses ESC sequences '=' and '>' to toggle application keypad mode, introduces keypad mappings for application vs numeric sequences, and updates legacy key handling and tests accordingly.

Changes

Cohort / File(s) Summary
Keypad implementation
vt/emulate.go
Added appKeyPad bool to emulator; extended inbEsc to handle '=' (enable) and '>' (disable) application keypad mode; added KeyPadEnter to legacyKeys; introduced legacyPadKeys map; updated keyLegacy to emit application or numeric keypad sequences (respecting NumLock).
Layout
vt/layout.go
Clarified Layout.Name comment and renamed KeyboardANSI.Name default from "US English" to "US".
Tests
vt/tests/uslayout_test.go
Added TestUsCapsLock and TestUsNumLock to validate Caps Lock and keypad behavior across application/numeric modes and NumLock precedence.
Test helper
vt/tests/util.go
Marked ReadF as a test helper via t.Helper() for improved test error traces.

Sequence Diagram(s)

(omitted — changes did not introduce multi-component sequential interactions that meet diagram criteria)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Tap-tap, I hop on keys so bright,
ESC flips modes from day to night,
Numbers dance or enter roam,
NumLock tells them which way home,
Hooray — the keypad hums just right! 🎹

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change—implementing keypad handling in the emulator with multiple related additions across input parsing, keyboard mappings, and test coverage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jan 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.30%. Comparing base (6078308) to head (9a2a52b).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1015      +/-   ##
==========================================
+ Coverage   85.09%   85.30%   +0.20%     
==========================================
  Files          46       46              
  Lines        4803     4817      +14     
==========================================
+ Hits         4087     4109      +22     
+ Misses        562      554       -8     
  Partials      154      154              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@vt/emulate.go`:
- Around line 212-213: The appKeyPad flag is not being cleared on reset; add
e.appKeyPad = false to the softReset code path (function softReset) and to the
RIS/reset handler that services the ESC c soft reset so both reset routines
explicitly set appKeyPad=false, ensuring the keypad returns to numeric mode
after a soft/RIS reset.

In `@vt/layout.go`:
- Around line 395-398: The default layout variable KeyboardANSI (type Layout)
was renamed to "US" and will break callers using GetLayout("US English"); fix by
registering the old name as an alias that points to the same Layout
instance—e.g., after the KeyboardANSI declaration call the existing registration
function (e.g., RegisterLayout or add to the layouts map) to associate the key
"US English" with KeyboardANSI so GetLayout("US English") returns the same
Layout object.

Comment thread vt/emulate.go
Comment on lines +212 to 213
appKeyPad bool // use application key pad keys?
name string // name of this emulator (used for extended attributes)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Reset application keypad mode on RIS/soft reset.

ESC c should return the keypad to numeric mode; appKeyPad currently persists across softReset. Please clear it there.

🛠️ Suggested fix
 func (em *emulator) softReset() {
 	// TODO:
 	// Select default character sets
+	em.appKeyPad = false
 	em.tabStops = nil
 	em.autoWrap = false

Also applies to: 356-359

🤖 Prompt for AI Agents
In `@vt/emulate.go` around lines 212 - 213, The appKeyPad flag is not being
cleared on reset; add e.appKeyPad = false to the softReset code path (function
softReset) and to the RIS/reset handler that services the ESC c soft reset so
both reset routines explicitly set appKeyPad=false, ensuring the keypad returns
to numeric mode after a soft/RIS reset.

Comment thread vt/layout.go
@gdamore
gdamore merged commit 9a2a52b into main Jan 26, 2026
11 of 12 checks passed
@gdamore
gdamore deleted the keypad branch January 26, 2026 07:26

This branch was previously deployed

1 inactive deployment
github-pages — 9a2a52b3 Deployed Jan 26, 2026 by gdamore via deploy #340
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.

1 participant