Skip to content

Commit 420863b

Browse files
committed
Add esc_timeout parameter to BaseEventQueue
1 parent e36cb0e commit 420863b

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

Lib/_pyrepl/base_eventqueue.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,26 @@
2424
See unix_eventqueue and windows_eventqueue for subclasses.
2525
"""
2626

27+
import os
2728
from collections import deque
2829

2930
from . import keymap
3031
from .console import Event
3132
from .trace import trace
3233

34+
ESC_TIMEOUT_DEFAULT = 0.1
35+
3336
class BaseEventQueue:
34-
def __init__(self, encoding: str, keymap_dict: dict[bytes, str]) -> None:
37+
def __init__(self, encoding: str, keymap_dict: dict[bytes, str],
38+
esc_timeout: float | None = None) -> None:
3539
self.compiled_keymap = keymap.compile_keymap(keymap_dict)
3640
self.keymap = self.compiled_keymap
3741
trace("keymap {k!r}", k=self.keymap)
3842
self.encoding = encoding
3943
self.events: deque[Event] = deque()
4044
self.buf = bytearray()
45+
default = float(os.environ.get("PYREPL_ESC_TIMEOUT", ESC_TIMEOUT_DEFAULT))
46+
self.esc_timeout = esc_timeout if esc_timeout is not None else default
4147

4248
def get(self) -> Event | None:
4349
"""

Lib/_pyrepl/unix_eventqueue.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ def get_terminal_keycodes(ti: TermInfo) -> dict[bytes, str]:
6969

7070

7171
class EventQueue(BaseEventQueue):
72-
def __init__(self, fd: int, encoding: str, ti: TermInfo) -> None:
72+
def __init__(self, fd: int, encoding: str, ti: TermInfo,
73+
esc_timeout: float | None = None) -> None:
7374
keycodes = get_terminal_keycodes(ti)
7475
if os.isatty(fd):
7576
backspace = tcgetattr(fd)[6][VERASE]
7677
keycodes[backspace] = "backspace"
77-
BaseEventQueue.__init__(self, encoding, keycodes)
78+
BaseEventQueue.__init__(self, encoding, keycodes, esc_timeout)

Lib/_pyrepl/windows_eventqueue.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@
3838
}
3939

4040
class EventQueue(BaseEventQueue):
41-
def __init__(self, encoding: str) -> None:
42-
BaseEventQueue.__init__(self, encoding, VT_MAP)
41+
def __init__(self, encoding: str, esc_timeout: float | None = None) -> None:
42+
BaseEventQueue.__init__(self, encoding, VT_MAP, esc_timeout)

0 commit comments

Comments
 (0)