diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2024-06-04 19:32:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-04 20:32:43 +0200 |
commit | d9095194dde27eaabfc0b86a11989cdb9a2acfe1 (patch) | |
tree | 5e06d170d8bb14998dc326c1fa6719631764478b /Lib/_pyrepl/unix_console.py | |
parent | bf5e1065f4ec2077c6ca352fc1ad940a76d1f6c9 (diff) | |
download | cpython-d9095194dde27eaabfc0b86a11989cdb9a2acfe1.tar.gz cpython-d9095194dde27eaabfc0b86a11989cdb9a2acfe1.zip |
gh-119842: Honor PyOS_InputHook in the new REPL (GH-119843)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Ćukasz Langa <lukasz@langa.pl>
Co-authored-by: Michael Droettboom <mdboom@gmail.com>
Diffstat (limited to 'Lib/_pyrepl/unix_console.py')
-rw-r--r-- | Lib/_pyrepl/unix_console.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/Lib/_pyrepl/unix_console.py b/Lib/_pyrepl/unix_console.py index 4bdb0226198..2f73a59dd1f 100644 --- a/Lib/_pyrepl/unix_console.py +++ b/Lib/_pyrepl/unix_console.py @@ -118,9 +118,12 @@ except AttributeError: def register(self, fd, flag): self.fd = fd - - def poll(self): # note: a 'timeout' argument would be *milliseconds* - r, w, e = select.select([self.fd], [], []) + # note: The 'timeout' argument is received as *milliseconds* + def poll(self, timeout: float | None = None) -> list[int]: + if timeout is None: + r, w, e = select.select([self.fd], [], []) + else: + r, w, e = select.select([self.fd], [], [], timeout/1000) return r poll = MinimalPoll # type: ignore[assignment] @@ -385,11 +388,11 @@ class UnixConsole(Console): break return self.event_queue.get() - def wait(self): + def wait(self, timeout: float | None = None) -> bool: """ Wait for events on the console. """ - self.pollob.poll() + return bool(self.pollob.poll(timeout)) def set_cursor_vis(self, visible): """ @@ -527,6 +530,15 @@ class UnixConsole(Console): self.__posxy = 0, 0 self.screen = [] + @property + def input_hook(self): + try: + import posix + except ImportError: + return None + if posix._is_inputhook_installed(): + return posix._inputhook + def __enable_bracketed_paste(self) -> None: os.write(self.output_fd, b"\x1b[?2004h") |