Skip to content

gh-131507: Add support for syntax highlighting in PyREPL #133247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Windows: bracketed pasting of 448692 chars done in 2.38s ✊
  • Loading branch information
ambv committed May 1, 2025
commit 656fea32bc4696f8d741aa818a182e1a07c7f7ab
7 changes: 5 additions & 2 deletions Lib/_pyrepl/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,10 @@ def do(self) -> None:
self.reader.console.wait(100)
ev = self.reader.console.getpending()
data += ev.data
trace("len(data) = {d}", d=len(data))
trace("bracketed pasting done in {s:.2f}s", s=time.time() - start)
trace(
"bracketed pasting of {l} chars done in {s:.2f}s",
l=len(data),
s=time.time() - start,
)
self.reader.insert(data.replace(done, ""))
self.reader.last_refresh_cache.invalidated = True
25 changes: 21 additions & 4 deletions Lib/_pyrepl/windows_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,18 @@ def _read_input(self, block: bool = True) -> INPUT_RECORD | None:

return rec

def _read_input_bulk(self, block: bool, n: int) -> tuple[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
Expand Down Expand Up @@ -528,10 +540,15 @@ def getpending(self) -> Event:
if e2:
e.data += e2.data

rec = self._read_input(False)
if rec and rec.EventType == KEY_EVENT:
key_event = rec.Event.KeyEvent
e.data += key_event.uChar.UnicodeChar
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:
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy