
                         V    S r SSKJr  SSKrSSKrSSKJr  SSKJr  Sr	 " S S	\
5      rg)
a5  
Similar to `PyOS_InputHook` of the Python API. Some eventloops can have an
inputhook to allow easy integration with other event loops.

When the eventloop of prompt-toolkit is idle, it can call such a hook. This
hook can call another eventloop that runs for a short while, for instance to
keep a graphical user interface responsive.

It's the responsibility of this hook to exit when there is input ready.
There are two ways to detect when input is ready:

- 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.

An alternative to using input hooks, is to create a custom `EventLoop` class that
controls everything.
    )unicode_literalsN)
is_windows   )
select_fds)InputHookContextc                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
r   $   z(
Given as a parameter to the inputhook.
c                     [        U5      (       d   eXl        S U l        [        R                  " 5       u  U l        U l        g )N)callable	inputhook_input_is_readyospipe_r_w)selfr   s     5lib/third_party/prompt_toolkit/eventloop/inputhook.py__init__InputHookContext.__init__(   s4    	"""""#779    c                      U R                  SS9$ )z&
Return True when the input is ready.
Fwait)r   r   s    r   input_is_readyInputHookContext.input_is_ready0   s     ###//r   c                     U R                   $ )zL
File descriptor that will become ready when the event loop needs to go on.
)r   r   s    r   filenoInputHookContext.fileno6   s     wwr   c                 D  ^ ^ TT l         UU 4S jn[        R                  " US9R                  5         T R	                  T 5         [        5       (       d  [        T R                  /SS9  [        R                  " T R                  S5        ST l         g! [         a     Nf = f)z=
Call the inputhook. (Called by a prompt-toolkit eventloop.)
c                  T   > T " SS9  [         R                  " TR                  S5        g )NTr      x)r   writer   )input_is_ready_funcr   s   r   thread/InputHookContext.call_inputhook.<locals>.threadC   s    T*HHTWWd#r   )targetN)timeouti   )r   	threadingThreadstartr   r   r   r   r   readOSError)r   r$   r%   s   `` r   call_inputhookInputHookContext.call_inputhook<   s      3	$ 	'--/ 	t	 <<DGG9d3GGDGGT"  $  	 		s   AB 
BBc                     U R                   (       a@  [        R                  " U R                   5        [        R                  " U R                  5        S=U l         U l        g)z
Clean up resources.
N)r   r   closer   r   s    r   r1   InputHookContext.closec   s9     77HHTWWHHTWW  $'r   )r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   r   r.   r1   __static_attributes__ r   r   r   r   $   s!    %0%$N!r   r   )r7   
__future__r   r   r)   prompt_toolkit.utilsr   selectr   __all__objectr   r9   r   r   <module>r?      s0   0 ( 	  + 
G!v G!r   