diff options
| author | Ćukasz Langa <lukasz@langa.pl> | 2024-06-04 19:26:10 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-04 19:26:10 (GMT) |
| commit | eea45ea21306fb04e5c4583889e8356315aa742b (patch) | |
| tree | 15756aa6a3c337da4a09c0caae0dde10e9200782 /Lib/_pyrepl/unix_console.py | |
| parent | 93b95e91faa17520f2042b4f4ae88379df914666 (diff) | |
| download | cpython-eea45ea21306fb04e5c4583889e8356315aa742b.zip cpython-eea45ea21306fb04e5c4583889e8356315aa742b.tar.gz cpython-eea45ea21306fb04e5c4583889e8356315aa742b.tar.bz2 | |
[3.13] gh-119842: Honor PyOS_InputHook in the new REPL (GH-119843) (GH-120066)
(cherry picked from commit d9095194dde27eaabfc0b86a11989cdb9a2acfe1)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
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 4bdb022..2f73a59 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") |
