|
24 | 24 | from contextlib import contextmanager |
25 | 25 | from dataclasses import dataclass, field, fields |
26 | 26 | import unicodedata |
| 27 | +import ctypes |
27 | 28 | from _colorize import can_colorize, ANSIColors # type: ignore[import-not-found] |
28 | 29 |
|
29 | 30 |
|
@@ -239,6 +240,7 @@ class Reader: |
239 | 240 | lxy: tuple[int, int] = field(init=False) |
240 | 241 | calc_screen: CalcScreen = field(init=False) |
241 | 242 | scheduled_commands: list[str] = field(default_factory=list) |
| 243 | + input_hook_addr: ctypes.c_void_p | None = None |
242 | 244 |
|
243 | 245 | def __post_init__(self) -> None: |
244 | 246 | # Enable the use of `insert` without a `prepare` call - necessary to |
@@ -643,6 +645,7 @@ def handle1(self, block: bool = True) -> bool: |
643 | 645 | self.dirty = True |
644 | 646 |
|
645 | 647 | while True: |
| 648 | + self.call_PyOS_InputHook() |
646 | 649 | event = self.console.get_event(block) |
647 | 650 | if not event: # can only happen if we're not blocking |
648 | 651 | return False |
@@ -701,3 +704,10 @@ def bind(self, spec: KeySpec, command: CommandName) -> None: |
701 | 704 | def get_unicode(self) -> str: |
702 | 705 | """Return the current buffer as a unicode string.""" |
703 | 706 | return "".join(self.buffer) |
| 707 | + |
| 708 | + def call_PyOS_InputHook(self): |
| 709 | + if self.input_hook_addr is None: |
| 710 | + self.input_hook_addr = ctypes.c_void_p.in_dll(ctypes.pythonapi, 'PyOS_InputHook').value |
| 711 | + if not self.input_hook_addr: |
| 712 | + return |
| 713 | + ctypes.PYFUNCTYPE(ctypes.c_int)(self.input_hook_addr)() |
0 commit comments