← Back
Editing: inputhook.cpython-311.pyc
� �Ïc� � � � d Z ddlZddlZddlZddlZddlZddlZddlmZ ddlmZm Z ddl mZmZm Z mZmZmZmZ ddlmZ g d�Zerdd lmZ eZd e dgdf defd �Zd e dgdf defd�Z G d� de� � Z G d� d� � ZdS )a8 Similar to `PyOS_InputHook` of the Python API, we can plug in an input hook in the asyncio event loop. The way this works is by using a custom 'selector' that runs the other event loop until the real selector is ready. It's the responsibility of this event hook to return when there is input ready. There are two ways to detect when input is ready: The inputhook itself is a callable that receives an `InputHookContext`. This callable should run the other event loop, and return when the main loop has stuff to do. There are two ways to detect when to return: - Call the `input_is_ready` method periodically. Quit when this returns `True`. - Add the `fileno` as a watch to the external eventloop. Quit when file descriptor becomes readable. (But don't read from it.) Note that this is not the same as checking for `sys.stdin.fileno()`. The eventloop of prompt-toolkit allows thread-based executors, for example for asynchronous autocompletion. When the completion for instance is ready, we also want prompt-toolkit to gain control again in order to display that. � N)�AbstractEventLoop)�BaseSelector�SelectorKey)� TYPE_CHECKING�Any�Callable�List�Mapping�Optional�Tuple� )�get_event_loop)�new_eventloop_with_inputhook�set_eventloop_with_inputhook�InputHookSelector�InputHookContext)�FileDescriptorLike� inputhookr �returnc �p � t t j � � | � � }t j |� � }|S )z; Create a new event loop with the given inputhook. )r � selectors�DefaultSelector�asyncio�SelectorEventLoop)r �selector�loops �D/usr/lib/python3/dist-packages/prompt_toolkit/eventloop/inputhook.pyr r 2 s1 � � !��!:�!<�!<�i�H�H�H��$�X�.�.�D��K� c �L � t | � � }t j |� � |S )zL Create a new event loop with the given inputhook, and activate it. )r r �set_event_loop)r r s r r r = s'