aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/_pyrepl/windows_console.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/_pyrepl/windows_console.py')
-rw-r--r--Lib/_pyrepl/windows_console.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/Lib/_pyrepl/windows_console.py b/Lib/_pyrepl/windows_console.py
index 17942c8df07..77985e59a93 100644
--- a/Lib/_pyrepl/windows_console.py
+++ b/Lib/_pyrepl/windows_console.py
@@ -426,6 +426,20 @@ class WindowsConsole(Console):
return rec
+ def _read_input_bulk(
+ self, block: bool, n: int
+ ) -> tuple[ctypes.Array[INPUT_RECORD], int]:
+ rec = (n * INPUT_RECORD)()
+ read = DWORD()
+
+ if not block and not self.wait(timeout=0):
+ return rec, 0
+
+ if not ReadConsoleInput(InHandle, rec, n, read):
+ raise WinError(GetLastError())
+
+ return rec, read.value
+
def get_event(self, block: bool = True) -> Event | None:
"""Return an Event instance. Returns None if |block| is false
and there is no event pending, otherwise waits for the
@@ -521,7 +535,23 @@ class WindowsConsole(Console):
def getpending(self) -> Event:
"""Return the characters that have been typed but not yet
processed."""
- return Event("key", "", b"")
+ e = Event("key", "", b"")
+
+ while not self.event_queue.empty():
+ e2 = self.event_queue.get()
+ if e2:
+ e.data += e2.data
+
+ recs, rec_count = self._read_input_bulk(False, 1024)
+ for i in range(rec_count):
+ rec = recs[i]
+ if rec and rec.EventType == KEY_EVENT:
+ key_event = rec.Event.KeyEvent
+ ch = key_event.uChar.UnicodeChar
+ if ch == "\r":
+ ch += "\n"
+ e.data += ch
+ return e
def wait(self, timeout: float | None) -> bool:
"""Wait for an event."""