mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-131507: Add support for syntax highlighting in PyREPL (GH-133247)
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
parent
bfcbb28223
commit
fac41f56d4
21 changed files with 654 additions and 99 deletions
|
@ -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."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue