
                             d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
 ddlZddlZddlZ e       r	ddlmZmZ nddlmZmZ d	Z G d
 d e
ee            Z G d de      Z G d de      Zy)z
Abstraction of CLI Input.
    )unicode_literals   )DummyContext
is_windows)ABCMetaabstractmethod)with_metaclassN)raw_modecooked_mode)Input
StdinInput	PipeInputc                   P    e Zd ZdZed        Zed        Zed        Zed        Zy)r   z
    Abstraction for any input.

    An instance of this class can be given to the constructor of a
    :class:`~prompt_toolkit.interface.CommandLineInterface` and will also be
    passed to the :class:`~prompt_toolkit.eventloop.base.EventLoop`.
    c                      y)z;
        Fileno for putting this in an event loop.
        N selfs    'lib/third_party/prompt_toolkit/input.pyfilenozInput.fileno"           c                      y)z-
        Return text from the input.
        Nr   r   s    r   readz
Input.read(   r   r   c                      y)zE
        Context manager that turns the input into raw mode.
        Nr   r   s    r   r
   zInput.raw_mode.   r   r   c                      y)zH
        Context manager that turns the input into cooked mode.
        Nr   r   s    r   r   zInput.cooked_mode4   r   r   N)	__name__
__module____qualname____doc__r   r   r   r
   r   r   r   r   r   r      sW      
  
  
  r   r   c                   6    e Zd ZdZd	dZd Zd Zd Zd Zd Z	y)
r   z&
    Simple wrapper around stdin.
    Nc                 J   |xs t         j                  | _        | j                  j                         sJ 	 | j                  j                          y # t        j
                  $ r= dt         j                  v rt	        j
                  d      t	        j
                  d      w xY w)Nzidlelib.runz<Stdin is not a terminal. Running from Idle is not supported.zStdin is not a terminal.)sysstdinisattyr   ioUnsupportedOperationmodules)r   r#   s     r   __init__zStdinInput.__init__?   s    'cii
 zz  """	JJJ&& 	J+--RT T --.HII	Js   A AB"c                 "    d| j                   dS )NzStdinInput(stdin=))r#   r   s    r   __repr__zStdinInput.__repr__Q   s    )-55r   c                 H    t        | j                  j                               S N)r
   r#   r   r   s    r   r
   zStdinInput.raw_modeT   s    

))+,,r   c                 H    t        | j                  j                               S r-   )r   r#   r   r   s    r   r   zStdinInput.cooked_modeW   s    4::,,.//r   c                 6    | j                   j                         S r-   )r#   r   r   s    r   r   zStdinInput.filenoZ   s    zz  ""r   c                 6    | j                   j                         S r-   )r#   r   r   s    r   r   zStdinInput.read]   s    zz  r   r-   )
r   r   r   r   r(   r+   r
   r   r   r   r   r   r   r   r   ;   s&    J$6-0#!r   r   c                   >    e Zd ZdZd Zd Zd Zd ZeZd Z	d Z
d Zy	)
r   z
    Input that is send through a pipe.
    This is useful if we want to send the input programatically into the
    interface, but still use the eventloop.

    Usage::

        input = PipeInput()
        input.send('inputdata')
    c                 F    t        j                         \  | _        | _        y r-   )ospipe_r_wr   s    r   r(   zPipeInput.__init__l   s    779r   c                     | j                   S r-   )r5   r   s    r   r   zPipeInput.filenoo   s    wwr   c                 @    t        j                  | j                        S r-   )r3   r   r5   r   s    r   r   zPipeInput.readr   s    wwtwwr   c                 b    t        j                  | j                  |j                  d             y)z Send text to the input. zutf-8N)r3   writer6   encode)r   datas     r   	send_textzPipeInput.send_textu   s    
$++g./r   c                     t               S r-   r   r   s    r   r
   zPipeInput.raw_mode|   
    ~r   c                     t               S r-   r?   r   s    r   r   zPipeInput.cooked_mode   r@   r   c                     t        j                  | j                         t        j                  | j                         d| _        d| _        y)z Close pipe fds. N)r3   closer5   r6   r   s    r   rC   zPipeInput.close   s0    

r   N)r   r   r   r   r(   r   r   r=   sendr
   r   rC   r   r   r   r   r   a   s1    	% 0
 Dr   r   )r   
__future__r   utilsr   r   abcr   r   sixr	   r%   r3   r"   terminal.win32_inputr
   r   terminal.vt100_input__all__objectr   r   r   r   r   r   <module>rM      sc    ( + '  	 	 
<;;;N7F+ B#! #!L& &r   