PyREPL: ESC key in isearch mode has ambiguous prefix delay
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
This issue was noted from #145398. A bare Esc press in isearch mode (Ctrl-R) does not exit search. Instead, the first Esc appears to do nothing, only after pressing Esc a second time does isearch end.
To reproduce:
- Press
Ctrl-Rin PyREPL to enter isearch. - Press
Esconce to exit isearch.
- Expected: isearch ends immediately.
- Actual: nothing happens. Press
Escagain, isearch ends.
This is because BaseEventQueue.push() treats \x1b (ESC) as a prefix of longer escape sequences (arrows, function keys, etc.). When a single Esc is received, the event queue holds it and waits for the next byte to decide whether it’s a standalone Esc or the start of a longer sequence. If no further byte arrives, the Esc event is never delivered, and isearch remains active.
Apart from isearch mode, this behavior affects normal mode as well, where Esc also has a delay before it is recognized.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Windows
Linked PRs
- gh-154731
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with BaseEventQueue.push() and the escape-sequence definitions in Lib/_pyrepl/unix_eventqueue.py and Lib/_pyrepl/windows_eventqueue.py. Review linked PR gh-154731 and the existing PyREPL event handling before making changes. Done means a bare Esc exits isearch immediately and is recognized without the current delay in normal mode.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100