2424from contextlib import contextmanager
2525from dataclasses import dataclass , field , fields
2626import unicodedata
27+ import ctypes
2728from _colorize import can_colorize , ANSIColors # type: ignore[import-not-found]
2829
2930
@@ -239,6 +240,7 @@ class Reader:
239240 lxy : tuple [int , int ] = field (init = False )
240241 calc_screen : CalcScreen = field (init = False )
241242 scheduled_commands : list [str ] = field (default_factory = list )
243+ input_hook_addr : ctypes .c_void_p | None = None
242244
243245 def __post_init__ (self ) -> None :
244246 # Enable the use of `insert` without a `prepare` call - necessary to
@@ -643,6 +645,7 @@ def handle1(self, block: bool = True) -> bool:
643645 self .dirty = True
644646
645647 while True :
648+ self .call_PyOS_InputHook ()
646649 event = self .console .get_event (block )
647650 if not event : # can only happen if we're not blocking
648651 return False
@@ -701,3 +704,10 @@ def bind(self, spec: KeySpec, command: CommandName) -> None:
701704 def get_unicode (self ) -> str :
702705 """Return the current buffer as a unicode string."""
703706 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