mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
[3.13] gh-119842: Honor PyOS_InputHook in the new REPL (GH-119843) (GH-120066)
(cherry picked from commit d9095194dd
)
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>
This commit is contained in:
parent
93b95e91fa
commit
eea45ea213
8 changed files with 144 additions and 11 deletions
|
@ -23,6 +23,8 @@ import io
|
|||
from multiprocessing import Value
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import msvcrt
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from collections import deque
|
||||
|
@ -202,6 +204,15 @@ class WindowsConsole(Console):
|
|||
self.screen = screen
|
||||
self.move_cursor(cx, cy)
|
||||
|
||||
@property
|
||||
def input_hook(self):
|
||||
try:
|
||||
import nt
|
||||
except ImportError:
|
||||
return None
|
||||
if nt._is_inputhook_installed():
|
||||
return nt._inputhook
|
||||
|
||||
def __write_changed_line(
|
||||
self, y: int, oldline: str, newline: str, px_coord: int
|
||||
) -> None:
|
||||
|
@ -460,9 +471,16 @@ class WindowsConsole(Console):
|
|||
processed."""
|
||||
return Event("key", "", b"")
|
||||
|
||||
def wait(self) -> None:
|
||||
def wait(self, timeout: float | None) -> bool:
|
||||
"""Wait for an event."""
|
||||
raise NotImplementedError("No wait support")
|
||||
# Poor man's Windows select loop
|
||||
start_time = time.time()
|
||||
while True:
|
||||
if msvcrt.kbhit(): # type: ignore[attr-defined]
|
||||
return True
|
||||
if timeout and time.time() - start_time > timeout:
|
||||
return False
|
||||
time.sleep(0.01)
|
||||
|
||||
def repaint(self) -> None:
|
||||
raise NotImplementedError("No repaint support")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue