| 1 |
""" |
| 2 |
prompt_toolkit input hook for GTK 4. |
| 3 |
""" |
| 4 |
|
| 5 |
from gi.repository import GLib |
| 6 |
|
| 7 |
|
| 8 |
class _InputHook: |
| 9 |
def __init__(self, context): |
| 10 |
self._quit = False |
| 11 |
GLib.io_add_watch( |
| 12 |
context.fileno(), GLib.PRIORITY_DEFAULT, GLib.IO_IN, self.quit |
| 13 |
) |
| 14 |
|
| 15 |
def quit(self, *args, **kwargs): |
| 16 |
self._quit = True |
| 17 |
return False |
| 18 |
|
| 19 |
def run(self): |
| 20 |
context = GLib.MainContext.default() |
| 21 |
while not self._quit: |
| 22 |
context.iteration(True) |
| 23 |
|
| 24 |
|
| 25 |
def inputhook(context): |
| 26 |
hook = _InputHook(context) |
| 27 |
hook.run() |