Skip to content

Commit 7d74972

Browse files
Added new_eventloop_with_inputhook.
1 parent bd078af commit 7d74972

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

prompt_toolkit/eventloop/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from .inputhook import (
33
InputHookContext,
44
InputHookSelector,
5+
new_eventloop_with_inputhook,
56
set_eventloop_with_inputhook,
67
)
78
from .utils import (
@@ -20,6 +21,7 @@
2021
'get_traceback_from_context',
2122

2223
# Inputhooks.
24+
'new_eventloop_with_inputhook',
2325
'set_eventloop_with_inputhook',
2426
'InputHookSelector',
2527
'InputHookContext',

prompt_toolkit/eventloop/inputhook.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,29 @@
3434
from prompt_toolkit.utils import is_windows
3535

3636
__all__ = [
37+
'new_eventloop_with_inputhook',
3738
'set_eventloop_with_inputhook',
3839
'InputHookSelector',
3940
'InputHookContext',
4041
]
4142

4243

43-
def set_eventloop_with_inputhook(
44+
def new_eventloop_with_inputhook(
4445
inputhook: Callable[['InputHookContext'], None]) -> AbstractEventLoop:
4546
"""
46-
Create a new event loop with the given inputhook, and activate it.
47+
Create a new event loop with the given inputhook.
4748
"""
4849
selector = InputHookSelector(selectors.DefaultSelector(), inputhook)
4950
loop = asyncio.SelectorEventLoop(selector) # type: ignore
51+
return loop
52+
53+
54+
def set_eventloop_with_inputhook(
55+
inputhook: Callable[['InputHookContext'], None]) -> AbstractEventLoop:
56+
"""
57+
Create a new event loop with the given inputhook, and activate it.
58+
"""
59+
loop = new_eventloop_with_inputhook(inputhook)
5060
asyncio.set_event_loop(loop)
5161
return loop
5262

0 commit comments

Comments
 (0)