Skip to content

gh-154730: Add timeout in PyREPL to distinguish between bare Esc and multibyte escape sequence#154731

Draft
tanloong wants to merge 4 commits into
python:mainfrom
tanloong:esc-timeout
Draft

gh-154730: Add timeout in PyREPL to distinguish between bare Esc and multibyte escape sequence#154731
tanloong wants to merge 4 commits into
python:mainfrom
tanloong:esc-timeout

Conversation

@tanloong

@tanloong tanloong commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

This adds a timeout to disambiguate bare Esc from the start of a longer escape sequence.

  1. Add pending() to BaseEventQueue: returns True when the queue has consumed a prefix (e.g., \x1b) but is still waiting for more bytes.
  2. Add flush() to BaseEventQueue: finalises a pending prefix as a standalone key (emits \x1b and re-feeds any remaining buffered bytes).
  3. Add esc_timeout parameter to BaseEventQueue (default 0.1 seconds; override via PYREPL_ESC_TIMEOUT env var).

In both unix_console.get_event() and windows_console.get_event(), when event_queue.pending() is True, the next read blocks only for esc_timeout seconds. If the timeout expires, call flush() and deliver the standalone Esc event.

@tanloong tanloong changed the title gh-154730: Add timeout to distinguish between bare Esc and multibyte escape sequence gh-154730: Add timeout in PyREPL to distinguish between bare Esc and multibyte escape sequence Jul 26, 2026
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