gh-131878: Fix input of unicode characters with two or more code points in new pyrepl on Windows (gh-131901)

Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
This commit is contained in:
Sergey Miryanov 2025-05-05 09:25:00 -07:00 committed by GitHub
parent d6078ed6d0
commit 0c5151bc81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 68 additions and 27 deletions

View file

@ -69,18 +69,14 @@ class BaseEventQueue:
trace('added event {event}', event=event)
self.events.append(event)
def push(self, char: int | bytes | str) -> None:
def push(self, char: int | bytes) -> None:
"""
Processes a character by updating the buffer and handling special key mappings.
"""
assert isinstance(char, (int, bytes))
ord_char = char if isinstance(char, int) else ord(char)
if ord_char > 255:
assert isinstance(char, str)
char = bytes(char.encode(self.encoding, "replace"))
self.buf.extend(char)
else:
char = bytes(bytearray((ord_char,)))
self.buf.append(ord_char)
char = ord_char.to_bytes()
self.buf.append(ord_char)
if char in self.keymap:
if self.keymap is self.compiled_keymap:

View file

@ -485,7 +485,8 @@ class WindowsConsole(Console):
return None
elif self.__vt_support:
# If virtual terminal is enabled, scanning VT sequences
self.event_queue.push(rec.Event.KeyEvent.uChar.UnicodeChar)
for char in raw_key.encode(self.event_queue.encoding, "replace"):
self.event_queue.push(char)
continue
if key_event.dwControlKeyState & ALT_ACTIVE: