)L iAUddlmZddlmZddlmZddlmZmZm Z erddl m Z ddl m Z ddlmZgd ZGd d Zed e Zded <ddZddZddZeddZe d ddZeddZy)) annotations)contextmanager) ContextVar) TYPE_CHECKINGAny Generator)Input)Output) Application) AppSessionget_app_sessionget_appget_app_or_noneset_appcreate_app_sessioncreate_app_session_from_ttycReZdZdZ d ddZd dZed dZed dZy) 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|_yN)_input_outputapp)selfinputoutputs h/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/prompt_toolkit/application/current.py__init__zAppSession.__init__)s  -1c"d|jdS)NzAppSession(app=))r)rs r__repr__zAppSession.__repr__3s  A..rcV|jddlm}||_|jS)Nr create_input)rprompt_toolkit.input.defaultsr%)rr%s rrzAppSession.input6s" ;;  B&.DK{{rcV|jddlm}||_|jS)Nr create_output)rprompt_toolkit.output.defaultsr))rr)s rrzAppSession.output>s" <<  D(?DL||rNN)r Input | Noner Output | NonereturnNone)r.str)r.r )r.r ) __name__ __module__ __qualname____doc__rr"propertyrrrrr r sX"CG1!12?1 1/rr _current_app_session)defaultzContextVar[AppSession]c*tjSr)r7getr6rrrrLs  # # %%rcttj}|j |jSddlm}|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)r7r:rdummyr<)sessionr<s rrrPs2&#&&(G{{{{'  rcBtj}|jS)zj Get the current active (running) Application, or return `None` if no application is running. r7r:r)r>s rrrls #&&(G ;;rc#Ktj}|j}||_ d||_y#||_wxYww)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@)rr> previous_apps rrrus<#&&(G;;LGK# " l s(A7A AANc#K|tj}|tj}t||}tj |} |tj |y#tj |wxYww)z Create a separate AppSession. This is useful if there can be multiple individual ``AppSession``'s going on. Like in the case of a Telnet/SSH server. Nrr)rrrr r7setreset)rrr>tokens rrrss$ }!(( ~ "**uV4G $ $W -E* ""5)""5)sABA,B,BBc#Kddlm}ddlm}|d}|d}t ||5}|dddy#1swYyxYww)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('>') rr$r(T)always_prefer_ttyrDN)r&r%r*r)r)r%r)rr app_sessions rrrsH ;< 4 0E T 2F % 7;s,A< AAA)r.r )r.Application[Any])r.zApplication[Any] | None)rrKr.zGenerator[None, None, None]r+)rr,rr-r.!Generator[AppSession, None, None])r.rL) __future__r contextlibr contextvarsrtypingrrrprompt_toolkit.input.baser prompt_toolkit.output.baser applicationr __all__r r7__annotations__rrrrrrr6rrrVs"%"00/1( ,,^0:JL0, &8##*8<* *(5*&**@r