fix: Enter key works in amplifier reset on Windows - #273
Merged
Conversation
The interactive reset checklist ignored Enter on Windows -- pressing it just
re-rendered the menu ("flash"), and the reset never confirmed. Only [q]
worked.
Root cause: the Windows branch of `_get_key()` compared `msvcrt.getch()`
bytes against DOUBLE-escaped byte literals:
if ch in (b"\\r", b"\\n"): # two chars: backslash + r
if ch == b"\\xe0": # four chars: backslash x e 0
if ch == b"\\x03": # backslash x 0 3
`msvcrt.getch()` returns the real byte `b"\r"` (0x0D) for Enter, which never
equals the two-character sequence `b"\\r"`. So Enter fell through to the
`ch.decode()` catch-all, returned "\r", matched no branch in the checklist
loop, and the menu simply re-rendered. `[q]` worked only because "q" is a
plain byte needing no escape.
The POSIX branch was already correct (single-escaped `"\r"`, `"\x1b"`), so
this was Windows-only -- POSIX users were never affected.
Fix: single-escape the four literals. Also accept both `0x00` and `0xe0` as
the arrow/function-key prefix (Windows uses either) and return "ESC" on an
unrecognized prefix, mirroring the POSIX branch. Change is entirely within
the `sys.platform == "win32"` branch; the POSIX path is byte-identical.
Proven on native Windows 11: Enter confirms, space toggles, arrows navigate,
q quits.
🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier)
Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
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.
The bug
In
amplifier reset, the interactive checklist ignored Enter on Windows — pressing it just re-rendered the menu ("flash") and the reset never confirmed. Only[q]worked. Reported from a real Windows install.Root cause
amplifier_app_cli/commands/reset_interactive.py, the Windows branch of_get_key(), comparedmsvcrt.getch()bytes against double-escaped byte literals:msvcrt.getch()returns the real byteb"\r"(0x0D) for Enter, which never equals the two-character sequenceb"\\r". So Enter fell through to thech.decode()catch-all, returned"\r", matched no branch in the checklist loop, and the menu simply re-rendered.[q]worked only because"q"is a plain byte needing no escape.The POSIX branch was already correct (single-escaped
"\r","\x1b"), so POSIX users were never affected — this is Windows-only.The fix
Single-escape the four literals. Also accept both
0x00and0xe0as the arrow/function-key prefix (Windows uses either) and return"ESC"on an unrecognized prefix, mirroring the POSIX branch. Entirely within thesys.platform == "win32"branch — the POSIX path is byte-identical.Evidence — native Windows 11, Python 3.14.3
Deterministic teeth test feeding
_get_key()the real bytesmsvcrt.getch()returns, baseline (main) vs fixed:The baseline reproduces the exact symptom (
qworks, Enter doesn't) and also reveals arrow-key navigation was broken by the same double-escape — invisible because the menu redrew identically.Limits
One Windows machine, one Python version (3.14.3). No Windows CI leg on this repo yet.