Enable arrow-key editing of quiz answers by importing readline #15

Merged
nessar merged 1 commits from fix-quiz-arrow-keys into main 2026-10-27 19:24:24 +01:00
Owner

In awslings quiz and awslings mock, the arrow keys did not edit the answer: the terminal's escape sequence went straight to the program.

Cause. input() only gets line editing (arrows, Home/End, history) when the readline module is loaded. Nothing in the project imported it. Worse, ^[[D was parsed as answer letters ([ ignored, D read as option D).

Fix. import readline in awslings/quiz.py, which holds every input() of the quizzes and mock exams. It is optional (try/except ImportError) because Windows has no readline.

Checked. In a pseudo-terminal, typing a, b, left arrow, c gives 'ab\x1b[Dc' before the change and 'acb' after, with the project's .venv Python 3.13.5 (GNU readline).

Not done. No automated test (only a pseudo-terminal can check it). The colored prompt is not wrapped for readline, which would only misredraw a line typed close to the terminal width.

🤖 Generated with Claude Code

In `awslings quiz` and `awslings mock`, the arrow keys did not edit the answer: the terminal's escape sequence went straight to the program. **Cause.** `input()` only gets line editing (arrows, Home/End, history) when the `readline` module is loaded. Nothing in the project imported it. Worse, `^[[D` was parsed as answer letters (`[` ignored, `D` read as option D). **Fix.** `import readline` in `awslings/quiz.py`, which holds every `input()` of the quizzes and mock exams. It is optional (`try/except ImportError`) because Windows has no `readline`. **Checked.** In a pseudo-terminal, typing `a`, `b`, left arrow, `c` gives `'ab\x1b[Dc'` before the change and `'acb'` after, with the project's `.venv` Python 3.13.5 (GNU readline). **Not done.** No automated test (only a pseudo-terminal can check it). The colored prompt is not wrapped for `readline`, which would only misredraw a line typed close to the terminal width. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
nessar added 1 commit 2026-10-27 19:24:01 +01:00
input() only gets line editing (arrows, Home/End, history) when the readline
module is loaded, and nothing in the project imported it. Pressing an arrow key
sent the raw escape sequence ("\x1b[D") to the program, where "[" and "D" were
parsed as answer letters. Importing it in awslings/quiz.py, which holds every
input() of the quizzes and mock exams, fixes it. The import is optional because
Windows has no readline.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
nessar merged commit fc6584b47e into main 2026-10-27 19:24:24 +01:00
nessar deleted branch fix-quiz-arrow-keys 2026-10-27 19:24:35 +01:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: nessar/awslings#15