
    f=                       U d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	 erd dl
mZ d dlmZ ddlmZ g d	Z G d
 d      Z ed e             Zded<   ddZddZddZedd       Ze	 d	 	 	 	 	 dd       Zedd       Zy)    )annotations)contextmanager)
ContextVar)TYPE_CHECKINGAny	Generator)Input)Output   )Application)
AppSessionget_app_sessionget_appget_app_or_noneset_appcreate_app_sessioncreate_app_session_from_ttyc                  R    e Zd ZdZ	 d	 	 	 	 	 ddZd	dZed
d       Zedd       Zy)r   aY  
    An AppSession is an interactive session, usually connected to one terminal.
    Within one such session, interaction with many applications can happen, one
    after the other.

    The input/output device is not supposed to change during one session.

    Warning: Always use the `create_app_session` function to create an
    instance, so that it gets activated correctly.

    :param input: Use this as a default input for all applications
        running in this session, unless an input is passed to the `Application`
        explicitly.
    :param output: Use this as a default output.
    Nc                .    || _         || _        d | _        y N)_input_outputapp)selfinputoutputs      ]/var/www/cvtools/html/venv/lib/python3.12/site-packages/prompt_toolkit/application/current.py__init__zAppSession.__init__)   s      -1    c                "    d| j                   dS )NzAppSession(app=))r   )r   s    r   __repr__zAppSession.__repr__3   s     A..r   c                V    | j                   ddlm}  |       | _         | j                   S )Nr   create_input)r   prompt_toolkit.input.defaultsr%   )r   r%   s     r   r   zAppSession.input6   s"    ;;B&.DK{{r   c                V    | j                   ddlm}  |       | _         | j                   S )Nr   create_output)r   prompt_toolkit.output.defaultsr)   )r   r)   s     r   r   zAppSession.output>   s"    <<D(?DL||r   NN)r   Input | Noner   Output | NonereturnNone)r.   str)r.   r	   )r.   r
   )	__name__
__module____qualname____doc__r   r"   propertyr   r    r   r   r   r      sX    " CG1!12?1	1/    r   r   _current_app_session)defaultzContextVar[AppSession]c                 *    t         j                         S r   )r7   getr6   r   r   r   r   L   s    ##%%r   c                 t    t         j                         } | j                  | j                  S ddlm}  |       S )a'  
    Get the current active (running) Application.
    An :class:`.Application` is active during the
    :meth:`.Application.run_async` call.

    We assume that there can only be one :class:`.Application` active at the
    same time. There is only one terminal window, with only one stdin and
    stdout. This makes the code significantly easier than passing around the
    :class:`.Application` everywhere.

    If no :class:`.Application` is running, then return by default a
    :class:`.DummyApplication`. For practical reasons, we prefer to not raise
    an exception. This way, we don't have to check all over the place whether
    an actual `Application` was returned.

    (For applications like pymux where we can have more than one `Application`,
    we'll use a work-around to handle that.)
    r   )DummyApplication)r7   r:   r   dummyr<   )sessionr<   s     r   r   r   P   s2    & #&&(G{{{{'r   c                 B    t         j                         } | j                  S )zj
    Get the current active (running) Application, or return `None` if no
    application is running.
    r7   r:   r   )r>   s    r   r   r   l   s    
 #&&(G;;r   c              #     K   t         j                         }|j                  }| |_        	 d ||_        y# ||_        w xY ww)a  
    Context manager that sets the given :class:`.Application` active in an
    `AppSession`.

    This should only be called by the `Application` itself.
    The application will automatically be active while its running. If you want
    the application to be active in other threads/coroutines, where that's not
    the case, use `contextvars.copy_context()`, or use `Application.context` to
    run it in the appropriate context.
    Nr@   )r   r>   previous_apps      r   r   r   u   s<      #&&(G;;LGK#"ls   (A7 A	A  ANc              #    K   | t               j                  } |t               j                  }t        | |      }t        j                  |      }	 | t        j                  |       y# t        j                  |       w xY ww)z
    Create a separate AppSession.

    This is useful if there can be multiple individual `AppSession`s going on.
    Like in the case of an Telnet/SSH server.
    Nr   r   )r   r   r   r   r7   setreset)r   r   r>   tokens       r   r   r      ss     $ }!((~ "** uV4G $$W-E*""5)""5)s   ABA, B,BBc               #     K   ddl m}  ddlm}  | d      } |d      }t	        ||      5 }| ddd       y# 1 sw Y   yxY ww)a  
    Create `AppSession` that always prefers the TTY input/output.

    Even if `sys.stdin` and `sys.stdout` are connected to input/output pipes,
    this will still use the terminal for interaction (because `sys.stderr` is
    still connected to the terminal).

    Usage::

        from prompt_toolkit.shortcuts import prompt

        with create_app_session_from_tty():
            prompt('>')
    r   r$   r(   T)always_prefer_ttyrD   N)r&   r%   r*   r)   r   )r%   r)   r   r   app_sessions        r   r   r      sH       ;<40ET2F	%	7 ;  s   ,A<	AAA)r.   r   )r.   Application[Any])r.   zApplication[Any] | None)r   rK   r.   zGenerator[None, None, None]r+   )r   r,   r   r-   r.   !Generator[AppSession, None, None])r.   rL   )
__future__r   
contextlibr   contextvarsr   typingr   r   r   prompt_toolkit.input.baser	   prompt_toolkit.output.baser
   applicationr   __all__r   r7   __annotations__r   r   r   r   r   r   r6   r   r   <module>rV      s    " % " 0 0/1(, ,^ 0:JL0 , 
&8 # #* 8<**(5*&* *@  r   