
    MhF                       d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dlm
Z
mZmZmZmZmZ d dlmZmZ d dlmZ d dlmZ d dlmZmZmZmZmZmZmZmZm Z m!Z!m"Z" d dl#m$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/m0Z0 d dl1m2Z2m3Z3m4Z4m5Z5 d dl6m7Z7 d dl8m9Z9m:Z:m;Z;m<Z< d dl=m>Z> d dl?m@Z@ d dlAmBZBmCZC d dlDmEZE d dlFmGZG d dlHmIZI d dlJmKZKmLZLmMZMmNZNmOZOmPZPmQZQ d dlRmSZSmTZT d dlUmVZV d dlWmXZX d dlYmZZZm[Z[ d dl\m]Z]m^Z^ d dl_m`Z` d dlambZbmcZc d dldmeZemfZf d d lgmhZhmiZi d d!ljmkZk d d"llmmZmmnZnmoZompZpmqZqmrZrmsZsmtZt d d#lumvZvmwZw d$d%lxmyZymzZz d$d&l{m|Z|m{Z{ d'gZ}eSZ~ e d(          Zed)gdf         Z eed*d          Z eed+d          Z G d, d'ee                   Z G d- d.eO          Zd9d3Zed:d7            Zed;d8            ZdS )<    )annotationsN)AbstractEventLoopFutureTaskensure_futureget_running_loopsleep)	ExitStackcontextmanager)Popen)	format_tb)AnyCallable	Coroutine	GeneratorGenericHashableIterableIteratorTypeVarcastoverload)Buffer)SimpleCache)	ClipboardInMemoryClipboard)AnyCursorShapeConfigto_cursor_shape_config)Size)EditingMode)	InputHookget_traceback_from_contextnew_eventloop_with_inputhookrun_in_executor_with_context)call_soon_threadsafe)	ConditionFilterFilterOrBool	to_filter)AnyFormattedText)Input)get_typeaheadstore_typeahead)load_page_navigation_bindings)load_key_bindings)
EmacsState)BindingConditionalKeyBindingsGlobalOnlyKeyBindingsKeyBindingsKeyBindingsBase	KeysTuplemerge_key_bindings)KeyPressEventKeyProcessor)ViState)Keys)	ContainerWindow)BufferControl	UIControl)create_dummy_layout)Layoutwalk)
ColorDepthOutput)Rendererprint_formatted_text)SearchState)	BaseStyle
DummyStyleDummyStyleTransformationDynamicStyleStyleTransformationdefault_pygments_styledefault_ui_stylemerge_styles)Eventin_main_thread   )get_app_sessionset_app)in_terminalrun_in_terminalApplication
_AppResultApplication[_AppResult]SIGWINCHSIGTSTPc                  D   e Zd ZdZdddddddddddej        dddddddddddddfdd2Zdd5Zedd7            Z	edd9            Z
edd;            Zdd<Zdd=Zedd>            Zddd@ZddAZddBZddEZddFZdddIZ	 	 	 	 dddOZ	 	 	 	 	 dddSZddXZeddZ            Zdd]ZddaZddcZdddZddeZddfZe ddg            Z!e dhdiddl            Z!e dhdiddo            Z!	 	 	 dddrZ!ddsZ"	 	 	 dddzZ#ddd|Z$	 ddd~Z%edd            Z&edd            Z'ddZ(dS )rW   a'  
    The main Application class!
    This glues everything together.

    :param layout: A :class:`~prompt_toolkit.layout.Layout` instance.
    :param key_bindings:
        :class:`~prompt_toolkit.key_binding.KeyBindingsBase` instance for
        the key bindings.
    :param clipboard: :class:`~prompt_toolkit.clipboard.Clipboard` to use.
    :param full_screen: When True, run the application on the alternate screen buffer.
    :param color_depth: Any :class:`~.ColorDepth` value, a callable that
        returns a :class:`~.ColorDepth` or `None` for default.
    :param erase_when_done: (bool) Clear the application output when it finishes.
    :param reverse_vi_search_direction: Normally, in Vi mode, a '/' searches
        forward and a '?' searches backward. In Readline mode, this is usually
        reversed.
    :param min_redraw_interval: Number of seconds to wait between redraws. Use
        this for applications where `invalidate` is called a lot. This could cause
        a lot of terminal output, which some terminals are not able to process.

        `None` means that every `invalidate` will be scheduled right away
        (which is usually fine).

        When one `invalidate` is called, but a scheduled redraw of a previous
        `invalidate` call has not been executed yet, nothing will happen in any
        case.

    :param max_render_postpone_time: When there is high CPU (a lot of other
        scheduled calls), postpone the rendering max x seconds.  '0' means:
        don't postpone. '.5' means: try to draw at least twice a second.

    :param refresh_interval: Automatically invalidate the UI every so many
        seconds. When `None` (the default), only invalidate when `invalidate`
        has been called.

    :param terminal_size_polling_interval: Poll the terminal size every so many
        seconds. Useful if the applications runs in a thread other then then
        main thread where SIGWINCH can't be handled, or on Windows.

    Filters:

    :param mouse_support: (:class:`~prompt_toolkit.filters.Filter` or
        boolean). When True, enable mouse support.
    :param paste_mode: :class:`~prompt_toolkit.filters.Filter` or boolean.
    :param editing_mode: :class:`~prompt_toolkit.enums.EditingMode`.

    :param enable_page_navigation_bindings: When `True`, enable the page
        navigation key bindings. These include both Emacs and Vi bindings like
        page-up, page-down and so on to scroll through pages. Mostly useful for
        creating an editor or other full screen applications. Probably, you
        don't want this for the implementation of a REPL. By default, this is
        enabled if `full_screen` is set.

    Callbacks (all of these should accept an
    :class:`~prompt_toolkit.application.Application` object as input.)

    :param on_reset: Called during reset.
    :param on_invalidate: Called when the UI has been invalidated.
    :param before_render: Called right before rendering.
    :param after_render: Called right after rendering.

    I/O:
    (Note that the preferred way to change the input/output is by creating an
    `AppSession` with the required input/output objects. If you need multiple
    applications running at the same time, you have to create a separate
    `AppSession` using a `with create_app_session():` block.

    :param input: :class:`~prompt_toolkit.input.Input` instance.
    :param output: :class:`~prompt_toolkit.output.Output` instance. (Probably
                   Vt100_Output or Win32Output.)

    Usage:

        app = Application(...)
        app.run()

        # Or
        await app.run_async()
    NTFg{Gz?      ?layoutLayout | NonestyleBaseStyle | Noneinclude_default_pygments_styler(   style_transformationStyleTransformation | Nonekey_bindingsKeyBindingsBase | None	clipboardClipboard | Nonefull_screenboolcolor_depth3ColorDepth | Callable[[], ColorDepth | None] | Nonemouse_supportenable_page_navigation_bindingsNone | FilterOrBool
paste_modeediting_moder    erase_when_donereverse_vi_search_directionmin_redraw_intervalfloat | int | Nonemax_render_postpone_timerefresh_intervalfloat | Noneterminal_size_polling_intervalcursorr   on_reset*ApplicationEventHandler[_AppResult] | Noneon_invalidatebefore_renderafter_renderinputInput | NoneoutputOutput | NonereturnNonec                    |
t           fd          }
t          |          }t          |	          }	t          |          }t          |
          }
t          |          }|t                      }|t                      }| _        | _        | _        t                       _        t                       _
        | _        |pt                       _        | _        | _        |	 _        | _        | _        | _        | _        |
 _        | _        | _        | _        | _        t5          |           _        t9           |           _        t9           |           _        t9           |           _        t9           |           _         tC                      }|p|j"         _"        |p|j#         _#        g  _$        d _%        d  _&        d  _'        d  _(        d  _)        d _*        tW                       _,        t[                       _.        d _/        d _0         1                    |           _2        tg           j2         j"        ||	 j4                   _5        d _6        d _7        g  _8        d _9        tu          tw                                _<        d _=        d  _>         ?                                 d S )Nc                      j         S N)ri   selfs   f/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prompt_toolkit/application/application.py<lambda>z&Application.__init__.<locals>.<lambda>   s
    @P     Fr]   g      ?)ri   rm   cpr_not_supported_callbackr   g        )@r&   r)   r@   rJ   r`   rc   re   r/   _default_bindingsr.   _page_navigation_bindingsr^   r   rg   ri   _color_depthrm   rp   rq   rr   rs   rn   rt   rv   rw   ry   r   rz   rP   r}   r{   r~   r   rS   r   r   pre_run_callables_is_runningfutureloop_loop_threadcontextquoted_insertr:   vi_stater0   emacs_statettimeoutlen
timeoutlen_create_merged_style_merged_stylerE   r   rendererrender_counter_invalidated_invalidate_events_last_redraw_timer9   _CombinedRegistrykey_processor_running_in_terminal_running_in_terminal_freset)r   r^   r`   rb   rc   re   rg   ri   rk   rm   rn   rp   rq   rr   rs   rt   rv   rw   ry   rz   r{   r}   r~   r   r   r   sessions   `                          r   __init__zApplication.__init__   s   @ +2.78P8P8P8P.Q.Q+z**
!-00&/0K&L&L#*34S*T*T')23Q)R)R&>(**F'#;#=#= 
$8! )!2!4!4)F)H)H&"9&7&9&9!,'*$(.+F(/N,#6 (@% 0.L+,V44 #477dH--"477!$55 "##.+gm
 <> 15.2	5937 #  		%<<   "667UVV K#''+'F
 
 
   "  	 "% **;D*A*ABB %*!;?# 	

r   r'   rH   c                     t                      t                      t          dfd            }t          t	                      |t           fd          g          S )z
        Create a `Style` object that merges the default UI style, the default
        pygments style, and the custom user style.
        r   rH   c                                   rS  S r    )dummy_stylerb   pygments_styles   r   conditional_pygments_stylezDApplication._create_merged_style.<locals>.conditional_pygments_style[  s     --// #%%""r   c                      j         S r   r`   r   s   r   r   z2Application._create_merged_style.<locals>.<lambda>f  s	    TZ r   )r   rH   )rI   rM   rK   rO   rN   )r   rb   r   r   r   s   `` @@r   r   z Application._create_merged_styleS  s    
 !ll/11		# 	# 	# 	# 	# 	# 	# 
	#  ""*////00
 
 	
r   rC   c                |    | j         }t          |          r
 |            }|| j                                        }|S )a  
        The active :class:`.ColorDepth`.

        The current value is determined as follows:

        - If a color depth was given explicitly to this application, use that
          value.
        - Otherwise, fall back to the color depth that is reported by the
          :class:`.Output` implementation. If the :class:`.Output` class was
          created using `output.defaults.create_output`, then this value is
          coming from the $PROMPT_TOOLKIT_COLOR_DEPTH environment variable.
        )r   callabler   get_default_color_depth)r   depths     r   rk   zApplication.color_depthj  sB     !E?? 	EGGE=K7799Er   r   c                :    | j         j        pt          d          S )a  
        The currently focused :class:`~.Buffer`.

        (This returns a dummy :class:`.Buffer` when none of the actual buffers
        has the focus. In this case, it's really not practical to check for
        `None` values or catch exceptions every time.)
        zdummy-buffer)name)r^   current_bufferr   r   s    r   r   zApplication.current_buffer  s*     {) 
V.
 .
 .
 	
r   rG   c                n    | j         j        }t          |t                    r|j        S t                      S )zv
        Return the current :class:`.SearchState`. (The one for the focused
        :class:`.BufferControl`.)
        )r^   current_control
isinstancer>   search_staterG   )r   
ui_controls     r   current_search_statez Application.current_search_state  s3     [0
j-00 	!**== r   c                   d| _         t                      | _        | j                                         | j                                         | j                                         | j                                         | j                                         | j	        
                                 | j        }|j                                        s:|                                D ]'}|j                                        r
||_         dS &dS dS )z?
        Reset everything, for reading the next input.
         N)
exit_styleset_background_tasksr   r   r   r^   r   r   r{   firer   is_focusablefind_all_windowscontentcurrent_window)r   r^   ws      r   r   zApplication.reset  s    25%%  """    	 %2244 	,,..  9))++ ,-F)EE	 	 r   c                     j         sdS  j         j                                        rdS  j        rdS d _         j                             j        j                   d	 fdd	 fd j        rZt          j                     j	        z
   j        k     r(d	 fd j                             fd           dS               dS               dS )
zW
        Thread safe way of sending a repaint trigger to the input event loop.
        NTr   r   c                 >    d _                                           d S NF)r   _redrawr   s   r   redrawz&Application.invalidate.<locals>.redraw  s     %DLLNNNNNr   c                 @    t           j        j                   d S )N)max_postpone_timer   )r%   rv   r   )r   r   s   r   schedule_redrawz/Application.invalidate.<locals>.schedule_redraw  s0     $*Gdi     r   c                    K   t          t          t          j                   z
             d {V                d S r   )r	   r   floatrt   )diffr   r   s   r   redraw_in_futurez0Application.invalidate.<locals>.redraw_in_future  sM      UD,D E E LMMMMMMMMM#O%%%%%r   c                 >                                                 S r   )create_background_task)r   r   s   r   r   z(Application.invalidate.<locals>.<lambda>  s    D778H8H8J8JKK r   r   r   )
r   r   	is_closedr   r%   r}   r   rt   timer   )r   r   r   r   r   s   `@@@@r   
invalidatezApplication.invalidate  sm     	 F 9	 3 3 5 5F
  	%F $D 		&&t'9'>???	 	 	 	 	 		 	 	 	 	 	 	
 # 	 9;;!77Dd...& & & & & & & & 	..KKKKK      !!!!!Or   c                    | j         S )z0True when a redraw operation has been scheduled.)r   r   s    r   invalidatedzApplication.invalidated  s       r   render_as_donec                     d fd} j         . j                                                             |           dS dS )z
        Render the command line again. (Not thread safe!) (From other threads,
        or if unsure, use :meth:`.Application.invalidate`.)

        :param render_as_done: make sure to put the cursor after the UI.
        r   r   c                    j         rj        sj        rt          j                    _        xj        dz  c_        j                                          rDj        rj	        
                                 nCj	                            j                    n j	                            j                   j                                         j                                                                          d S d S d S )NrR   )is_done)r   r   rt   r   r   r   r~   r   rr   r   eraserenderr^   update_parents_relationsr   _update_invalidate_events)r   r   s   r   run_in_contextz+Application._redraw.<locals>.run_in_context  s    1(A 1+ 9-1Y[[D* ##q(##"'')))! <+ X++---- ,,T4;,WWWWM((t{;;;44666 !&&(((..00000-1 1 1 1r   Nr   )r   copyrun)r   r   r   s   `` r   r   zApplication._redraw  sb    	1 	1 	1 	1 	1 	1 	1B <#L##N33333 $#r   c                      j         6 j         dk    r-d fd}                      | j                              dS dS dS )	zi
        Start a while/true loop in the background for automatic invalidation of
        the UI.
        Nr   rw   r   r   r   c                ^   K   	 t          |            d {V                                   *r   )r	   r   )rw   r   s    r   auto_refreshz:Application._start_auto_refresh_task.<locals>.auto_refresh(  sB      & 0111111111OO%%%&r   )rw   r   r   r   )rw   r   )r   r   s   ` r   _start_auto_refresh_taskz$Application._start_auto_refresh_task!  sp    
  ,1F!1K1K& & & & & &
 ''T5J(K(KLLLLL -,1K1Kr   c                      j         D ]}| j        z  }d fd}t           |                       _          j         D ]}| j        z  }dS )zg
        Make sure to attach 'invalidate' handlers to all invalidate events in
        the UI.
        r   Iterable[Event[object]]c               3  x   K   j                                         D ]} |                                 E d {V  d S r   )r^   find_all_controlsget_invalidate_events)cr   s    r   gather_eventsz<Application._update_invalidate_events.<locals>.gather_events;  sU      [2244 5 52244444444445 5r   N)r   r   )r   _invalidate_handlerlist)r   evr   s   `  r   r   z%Application._update_invalidate_events/  s     ) 	+ 	+B$**BB	5 	5 	5 	5 	5 	5 #'}}"7"7) 	+ 	+B$**BB	+ 	+r   senderobjectc                .    |                                   dS )a  
        Handler for invalidate events coming from UIControls.

        (This handles the difference in signature between event handler and
        `self.invalidate`. It also needs to be a method -not a nested
        function-, so that we can remove it again .)
        N)r   )r   r   s     r   r   zApplication._invalidate_handlerD  s     	r   c                    | j                             d           |                                  |                                  dS )z
        When the window size changes, we erase the current output and request
        again the cursor position. When the CPR answer arrives, the output is
        drawn again.
        F)leave_alternate_screenN)r   r   !_request_absolute_cursor_positionr   r   s    r   
_on_resizezApplication._on_resizeN  s@     	5999..000r   pre_runCallable[[], None] | Nonec                Z    |r
 |             | j         D ]} |             | j         dd= dS )a  
        Called during `run`.

        `self.future` should be set to the new future at the point where this
        is called in order to avoid data races. `pre_run` can be used to set a
        `threading.Event` to synchronize with UI termination code, running in
        another thread that would call `Application.exit`. (See the progress
        bar code for an example.)
        N)r   )r   r   r   s      r   _pre_runzApplication._pre_runZ  sM      	GIII ' 	 	AACCCC"111%%%r   set_exception_handlerhandle_sigintslow_callback_durationr   rX   c                d   K    j         r
J d            t                      rt          j        dk    rdd fd}t          d fd
            }t          d fd            }t          d fd            }t          d fd            }	t          dfd            }
t          d fd            }t                      5 }|                     |                       d _        |                     |                      }|                     ||                     |                     |	|                     |                     |
|                     |                    t                                |                     	                                           |                     ||                    }	  ||           d{V 	  
                                 d{V  cddd           S #  
                                 d{V  w xY w# 1 swxY w Y   J d            )aY  
        Run the prompt_toolkit :class:`~prompt_toolkit.application.Application`
        until :meth:`~prompt_toolkit.application.Application.exit` has been
        called. Return the value that was passed to
        :meth:`~prompt_toolkit.application.Application.exit`.

        This is the main entry point for a prompt_toolkit
        :class:`~prompt_toolkit.application.Application` and usually the only
        place where the event loop is actually running.

        :param pre_run: Optional callable, which is called right after the
            "reset" of the application.
        :param set_exception_handler: When set, in case of an exception, go out
            of the alternate screen and hide the application, display the
            exception, and wait for the user to press ENTER.
        :param handle_sigint: Handle SIGINT signal if possible. This will call
            the `<sigint>` key binding when a SIGINT is received. (This only
            works in the main thread.)
        :param slow_callback_duration: Display warnings if code scheduled in
            the asyncio event loop takes more time than this. The asyncio
            default of `0.1` is sometimes not sufficient on a slow system,
            because exceptionally, the drawing of the app, which happens in the
            event loop, can take a bit longer from time to time.
        zApplication is already running.win32Ffasyncio.Future[_AppResult]r   rX   c                *	   	K   t          j                    _        d                                                      
           j                            t          j                             j        	                                 d
 fd	d
	fd}d
fdd
 fdj        
                                5  j                            |          5  t          j                  5                                                                                                                                                                    	   d {V }	                     d           j                                         d	_        j        D ]}|j        z  }g _        j        j        rj                                         d {V  j        }|r| d {V  t7          j        j                                                   n# j                                         d	_        j        D ]}|j        z  }g _        j        j        rj                                         d {V  j        }|r| d {V  t7          j        j                                                   w xY w# 	                     d           j                                         d	_        j        D ]}|j        z  }g _        j        j        rj                                         d {V  j        }|r| d {V  t7          j        j                                                   w # j                                         d	_        j        D ]}|j        z  }g _        j        j        rj                                         d {V  j        }|r| d {V  t7          j        j                                                   w xY wxY w|cd d d            cd d d            cd d d            S # 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr   r   c                    j         sj        j        sd S j                                        } j                            |            j                                         j        j        r2	                                s
                    t                     d S d S r                                                                            d S r   )r   r   waiting_for_cprr   	read_keysr   feed_multipleprocess_keyscloseddoneset_exceptionEOFErrorcancelr   )keysauto_flush_inputr  
flush_taskr   s    r   read_from_inputzBApplication.run_async.<locals>._run_async.<locals>.read_from_input  s     ' 0M F z++-- "00666"//111 :$ Q6688 2111112 2 " ,"))+++!%!<!<=M=M=O=O!P!PJJJr   c                 V                                                                     d S r   )r   r   )r   r  s   r   read_from_input_in_contextzMApplication.run_async.<locals>._run_async.<locals>.read_from_input_in_context  s'     ""?33333r   c                 T   K   t          j                   d {V                 d S r   )r	   r   )flush_inputr   s   r   r  zCApplication.run_async.<locals>._run_async.<locals>.auto_flush_input  s;       D,---------r   c                    j         stj                                        } j                            |            j                                         j        j        r                    t                     d S d S d S r   )	r   r   
flush_keysr   r  r  r  r  r  )r  r  r   s    r   r  z>Application.run_async.<locals>._run_async.<locals>.flush_input  s    | 2:0022D&44T:::&33555z( 2111112 22 2r   T)r   Fr   )contextvarscopy_contextr   r   r  r   r  r,   r   r  raw_modeattachattach_winch_signal_handlerr   r   r   r   r   _poll_output_sizer   r   r   r   r   responds_to_cprwait_for_cpr_responsesr   r-   empty_queue)r  r  resultr   previous_run_in_terminal_fr  r   r  r  r  r   r   s   `    @@@@@r   
_run_asyncz)Application.run_async.<locals>._run_async  s     !.00G"DL 59J JJLLLMM'""" ,,]4:-F-FGGG++---Q Q Q Q Q Q Q Q Q64 4 4 4 4 4 4      2 2 2 2 2 2 2 $$&& 3 3
(9(9*) ) 3 3*4?;;3 3 66888--///++D,B,B,D,DEEE&V#$WWWWWWF!VD999
 ++---
 ,1( #'"9 ; ;B$"::BB24/  ;6 I"&-"F"F"H"HHHHHHHH 6:5P25 ="<<<<<<<< (
D4F4R4R4T4TUUUU7 ++---
 ,1( #'"9 ; ;B$"::BB24/  ;6 I"&-"F"F"H"HHHHHHHH 6:5P25 ="<<<<<<<< (
D4F4R4R4T4TUUUUC!VD999
 ++---
 ,1( #'"9 ; ;B$"::BB24/  ;6 I"&-"F"F"H"HHHHHHHH 6:5P25 ="<<<<<<<< (
D4F4R4R4T4TUUUU7 ++---
 ,1( #'"9 ; ;B$"::BB24/  ;6 I"&-"F"F"H"HHHHHHHH 6:5P25 ="<<<<<<<< (
D4F4R4R4T4TUUUUg3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3s   R&Q0;A$Q K)H$?B%Q$B%K			QP0	N
$B$P0	B%P--P0	0Q4Q0 RQQ0 Q!Q0$R0Q4	4R7Q4	8RRRIterator[AbstractEventLoop]c               3     K   t                      } | _        t          j                    _        	 | V  d _        d _        d S # d _        d _        w xY wr   )r   r   	threadingcurrent_threadr   )r   r   s    r   set_loopz'Application.run_async.<locals>.set_loop  sk      #%%DDI ) 8 : :D)


 	$(!!! !	$(!((((s   A AIterator[None]c               3  J   K   d _         	 d V  d _         d S # d _         w xY w)NTFr   r   s   r   set_is_runningz-Application.run_async.<locals>.set_is_running  s?      #D)#(   5 ((((s    	"r   r   c              3  H   K   rt                      5                       t          j         fd           	 d V                       t          j                   n$#                      t          j                   w xY w	 d d d            d S # 1 swxY w Y   d S d V  d S )Nc                 B                         j        j                  S r   )r%   r   send_sigint)_r   r   s    r   r   zBApplication.run_async.<locals>.set_handle_sigint.<locals>.<lambda>/  s     4#<#< .:$ $ r   )_restore_sigint_from_ctypesadd_signal_handlersignalSIGINTremove_signal_handler)r   r  r   s   `r   set_handle_sigintz0Application.run_async.<locals>.set_handle_sigint'  s"      022 B B ++      B226=AAAA226=AAAAAB B B B B B B B B B B B B B B B B B s'   %BA B!B  BBBc              3     K   rd|                                  }|                     j                   	 d V  |                     |           d S # |                     |           w xY wd V  d S r   )get_exception_handlerr  _handle_exception)r   previous_exc_handlerr   r  s     r   set_exception_handler_ctxz8Application.run_async.<locals>.set_exception_handler_ctx:  s      $ 	'+'A'A'C'C$**4+ABBBEEEE../CDDDDDD../CDDDD s   A A'c              3  X   K   | j         }| _         	 d V  || _         d S # || _         w xY wr   )r  )r   original_slow_callback_durationr  s     r   set_callback_durationz4Application.run_async.<locals>.set_callback_durationG  sO       /3.I+*@D'N /N+++.M+MMMMs     	)$Iterator[asyncio.Future[_AppResult]]c              3  r   K   |                                  }|_        	 |V  d _        d S # d _        w xY wr   )create_futurer   )r   r  r   s     r   rH  z,Application.run_async.<locals>.create_futureR  sO       ""$$ADK#
 #d""""s   - 	6Nunreachable)r  r	  r   rX   )r   r+  )r   r0  )r   r   r   r0  )r   r   r   rF  )r   rQ   sysplatformr   r
   enter_contextr   rT   _enable_breakpointhook$cancel_and_wait_for_background_tasks)r   r   r  r  r  r*  r/  r3  r=  rB  rE  rH  stackr   r  s   `````          r   	run_asynczApplication.run_asyncl  sq     > #FF%FFFF 	"3<7#:#:
 "M}	 }	 }	 }	 }	 }	 }	~ 
		) 		) 		) 		) 		) 
		) 
	) 	) 	) 	) 	) 
	) 
	 	 	 	 	 	 
	$ 

	 
	 
	 
	 
	 
	 

	 
	N 	N 	N 	N 	N 
	N 
	# 	# 	# 	# 	# 
	# [[ 	BE 0 0111 !&D&&xxzz22D 1 1$ 7 7888 9 9$ ? ?@@@ 5 5d ; ;<<<... ; ; = =>>>##MM$$7$788AB'Z]]******* ??AAAAAAAAA7	B 	B 	B 	B 	B 	B 	B 	B6 ??AAAAAAAAAA7	B 	B 	B 	B 	B 	B 	B 	BB 	$m###s+   DHG>H>HHH!$H!	in_thread	inputhookInputHook | Nonec                    |rPdd	 fd}t          j        |          }|                                 |                                 S                      |          }d
d}	at                    }
|
                    |          |
                    |
                                           |
                                 S  |	            rM	 t          j
                    }
|
                    |          S # t          $ r t          j        |          cY S w xY wt          j        |          S )a  
        A blocking 'run' call that waits until the UI is finished.

        This will run the application in a fresh asyncio event loop.

        :param pre_run: Optional callable, which is called right after the
            "reset" of the application.
        :param set_exception_handler: When set, in case of an exception, go out
            of the alternate screen and hide the application, display the
            exception, and wait for the user to press ENTER.
        :param in_thread: When true, run the application in a background
            thread, and block the current thread until the application
            terminates. This is useful if we need to be sure the application
            won't use the current event loop (asyncio does not support nested
            event loops). A new event loop will be created in this background
            thread, and that loop will also be closed when the background
            thread terminates. When this is used, it's especially important to
            make sure that all asyncio background tasks are managed through
            `get_appp().create_background_task()`, so that unfinished tasks are
            properly cancelled before the event loop is closed. This is used
            for instance in ptpython.
        :param handle_sigint: Handle SIGINT signal. Call the key binding for
            `Keys.SIGINT`. (This only works in the main thread.)
        Nr   r   c                 p    	                      d          d S # t          $ r} | Y d } ~ d S d } ~ ww xY w)NF)r   r  r  rR  )r   BaseException)e	exceptionrR  r   r(  r   r  s    r   run_in_threadz&Application.run.<locals>.run_in_thread  sb    	"!XX '.C&+"+ &  FFF % " " " !IIIIIII"s    
505)target)r   r  r  rj   c                     	 t           j        d         j        dk     odt          j        d          j        j        v S # t          $ r Y dS w xY w)NIPython)      r   r   z$IPython/terminal/interactiveshell.py   F)rJ  modulesversion_info	_getframef_codeco_filenamerV  r   r   r   _called_from_ipythonz-Application.run.<locals>._called_from_ipython  sb    K	*7.H ;>}Q''.:;
 !   uus   := 
A
Ar   r   rj   )r-  ThreadstartjoinrP  r#   run_until_completeshutdown_asyncgenscloseasyncioget_event_loopRuntimeErrorr   )r   r   r  r  rQ  rR  rY  threadcorore  r   rX  r(  s   ```  `     @@r   r   zApplication.run  s   @  	.2I" " " " " " " " " " " %];;;FLLNNNKKMMM$M~~"7'  
 
	 	 	 	   0	::D,,T22F##D$;$;$=$=>>>JJLLLM!!## 	%

5 -// ..t444   ) ) ){4((((() ;t$$$s   #D D,+D,r   r   r   dict[str, Any]c                    t                    }d                    t          |                    dfd}t           |                       dS )zr
        Handler for event loop exceptions.
        This will print the exception, using run_in_terminal.
        r   r   r   c                 N  K   t                      4 d {V  t          d           t                     t          d                                         d                               t	          d           d {V  d d d           d {V  d S # 1 d {V swxY w Y   d S )Nz#
Unhandled exception in event loop:zException {}rX  Press ENTER to continue...)rU   printformatget_do_wait_for_enter)r   formatted_tbs   r   in_termz.Application._handle_exception.<locals>.in_term  s]     "}} G G G G G G G G <===l###n++GKK,D,DEEFFF()EFFFFFFFFFG G G G G G G G G G G G G G G G G G G G G G G G G G G G G Gs   A)B
B!BNr   )r"   ri  r   r   )r   r   r   tbr{  rz  s     `  @r   r@  zApplication._handle_exception  sp     (00wwy}}--	G 	G 	G 	G 	G 	G 	G 	ggii     r   Generator[None, None, None]c              #     K   t           j        t           j        k    rI| j        t           _        	 dV  t           j        t           _        dS # t           j        t           _        w xY wdV  dS )z
        Install our custom breakpointhook for the duration of this context
        manager. (We will only install the hook if no other custom hook was
        set.)
        N)rJ  breakpointhook__breakpointhook___breakpointhookr   s    r   rM  z"Application._enable_breakpointhook  sg       !777!%!5C<%(%;"""S%;";;;;EEEEEs   A A#akwc                f   	
  ddl }ddlm} t          |t          t
          gt
          f         }t          dfd            	t          d fd            
 G 	
fdd	|j                  }t          j	                    j
        } |t          j        
                              |           dS )am  
        Breakpointhook which uses PDB, but ensures that the application is
        hidden and input echoing is restored during each debugger dispatch.

        This can be called from any thread. In any case, the application's
        event loop will be blocked while the PDB input is displayed. The event
        will continue after leaving the debugger.
        r   N)	FrameTyper   r}  c               3    K    j                                           j                                        5   j                                        5  dV  ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )z`Stop application if `__breakpointhook__` is called from within
            the App's event loop.N)r   r   r   detachcooked_mode)apps   r   hide_app_from_eventloop_threadzCApplication._breakpointhook.<locals>.hide_app_from_eventloop_thread'  s	     
 L    !!##  Y**,,  EEE                               s5   A9A!A9!A%	%A9(A%	)A99A= A=c               3  2  K   t          j                    t          j                    dfd}                      |                                                         	 dV                                   dS #                                  w xY w)zmStop application if `__breakpointhook__` is called from a
            thread other than the App's event loop.r   r   c                 T  K    j                                           j                                        5   j                                        5                                                                    d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S r   )r   r   r   r  r  r   wait)r  r  readys   r   in_loopzPApplication._breakpointhook.<locals>.hide_app_from_other_thread.<locals>.in_loop?  s      ""$$$ Y%%'' $ $..00 $ $		 		$ $ $ $ $ $ $ $ $ $ $ $ $ $ $$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s5   B)B9BB			BB		BB!$B!Nr   )r-  rP   r   r  r   )r  r  r  r  r   s    @@r   hide_app_from_other_threadz?Application._breakpointhook.<locals>.hide_app_from_other_thread8  s       O%%E?$$D$ $ $ $ $ $ $ $* ''		222JJLLL








s   &B   Bc                  (     e Zd Zd
 fd	Z xZS ).Application._breakpointhook.<locals>.CustomPdbframer  eventstrargr   r   TraceDispatchc                   j         #t                                          |||          S j         t          j                    k    rE             5  t                                          |||          cd d d            S # 1 swxY w Y                5  t                                          |||          cd d d            S # 1 swxY w Y   d S r   )r   supertrace_dispatchr-  r.  )r   r  r  r  	__class__r  r  r  s       r   r  z=Application._breakpointhook.<locals>.CustomPdb.trace_dispatch\  sw    #+ 7711%DDD#y'?'A'AAA7799 I I$ww55eUCHHI I I I I I I I I I I I I I I I 0/11 E E 7711%DDE E E E E E E E E E E E E E E E E Es$   #BB	B#CCC)r  r  r  r  r  r   r   r  )__name__
__module____qualname__r  __classcell__)r  r  r  r  s   @r   	CustomPdbr  [  sZ        E E E E E E E E E E E E Er   r  )stdoutr   r}  )pdbtypesr  r   r  r   r   PdbrJ  rb  f_back
__stdout__	set_trace)r   r  r  r  r  r  r  r  r  r  r  s   `       @@@r   r  zApplication._breakpointhook  s    


###### )S#!6!;<			 		 		 		 		 
		  
 	  	  	  	  	  	 
 	D	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E &	(((22599999r   	coroutineCoroutine[Any, Any, None]asyncio.Task[None]c                    | j         pt                      }|                    |          }| j                            |           |                    | j                   |S )a  
        Start a background task (coroutine) for the running application. When
        the `Application` terminates, unfinished background tasks will be
        cancelled.

        Given that we still support Python versions before 3.11, we can't use
        task groups (and exception groups), because of that, these background
        tasks are not allowed to raise exceptions. If they do, we'll call the
        default exception handler from the event loop.

        If at some point, we have Python 3.11 as the minimum supported Python
        version, then we can use a `TaskGroup` (with the lifetime of
        `Application.run_async()`, and run run the background tasks in there.

        This is not threadsafe.
        )r   r   create_taskr   addadd_done_callback_on_background_task_done)r   r  r   tasks       r   r   z"Application.create_background_taskl  s]    & y.,..#'#3#3I#>#>""4(((t<===r   r  c                    | j                             |           |                                rdS |                                }|+t	                                          d|d||d           dS dS )z
        Called when a background task completes. Remove it from
        `_background_tasks`, and handle exceptions if any.
        Nz+prompt_toolkit.Application background task z  raised an unexpected exception.)messagerX  r  )r   discard	cancelledrX  r   call_exception_handler)r   r  excs      r   r  z$Application._on_background_task_done  s    
 	&&t,,,>> 	Fnn?55 6T  6  6  6!$ 	      ?r   c                   K   | j         D ]}|                                 t          | j                   dk    r.t          j        | j         dt          j                   d{V  dS dS )a#  
        Cancel all background tasks, and wait for the cancellation to complete.
        If any of the background tasks raised an exception, this will also
        propagate the exception.

        (If we had nurseries like Trio, this would be the `__aexit__` of a
        nursery.)
        r   N)timeoutreturn_when)r   r  lenrm  r  ALL_COMPLETED)r   r  s     r   rN  z0Application.cancel_and_wait_for_background_tasks  s       * 	 	DKKMMMM" t%&&**,&'BW            +*r   c                   K   d}| j         }|dS 	 t          j        |           d{V  | j                                        }|||k    r|                                  |}R)z
        Coroutine for polling the terminal dimensions.

        Useful for situations where `attach_winch_signal_handler` is not sufficient:
        - If we are not running in the main thread.
        - On Windows.
        N)ry   rm  r	   r   get_sizer   )r   sizeintervalnew_sizes       r   r$  zApplication._poll_output_size  s       !6F	-))))))))){++--HH$4$4!!!D	r   c                N      j         j        sdS d fd}t          |           dS )zT
        Called when we don't receive the cursor position response in time.
        Nr   r   c                 n     j                             d            j                                          d S )NzHWARNING: your terminal doesn't support cursor position requests (CPR).
)r   writeflushr   s   r   rU   z;Application.cpr_not_supported_callback.<locals>.in_terminal  s<    K\   Kr   r   )r   r%  rV   )r   rU   s   ` r   r   z&Application.cpr_not_supported_callback  sK     {* 	F	  	  	  	  	  	  	$$$$$r   c                    dS )zExit without arguments.Nr   r   s    r   exitzApplication.exit        r   r   r   r(  r  c                   dS )zExit with `_AppResult`.Nr   )r   r(  r`   s      r   r  zApplication.exit  r  r   rX  #BaseException | type[BaseException]c                   dS )zExit with exception.Nr   )r   rX  r`   s      r   r  zApplication.exit  r  r   _AppResult | None*BaseException | type[BaseException] | Nonec                2   ||J | j         t          d          | j                                         rt          d          || _        || j                             |           dS | j                             t          t          |                     dS )a  
        Exit application.

        .. note::

            If `Application.exit` is called before `Application.run()` is
            called, then the `Application` won't exit (because the
            `Application.future` doesn't correspond to the current run). Use a
            `pre_run` hook and an event to synchronize the closing if there's a
            chance this can happen.

        :param result: Set this result for the application.
        :param exception: Set this exception as the result for an application. For
            a prompt, this is often `EOFError` or `KeyboardInterrupt`.
        :param style: Apply this style on the whole content when quitting,
            often this is 'class:exiting' for a prompt. (Used when
            `erase_when_done` is not set.)
        Nz6Application is not running. Application.exit() failed.z4Return value already set. Application.exit() failed.)r   	Exceptionr  r   r  
set_resultr   rX   )r   r(  rX  r`   s       r   r  zApplication.exit  s    0 ~!2!2!2;TUUU; 	TRSSS K%%i00000K""4
F#;#;<<<<<r   c                f    | j         j        s"| j        s| j                                         dS dS dS )z#
        Send CPR request.
        N)r   input_queuer   r    request_absolute_cursor_positionr   s    r   r   z-Application._request_absolute_cursor_position  sI     !- 	=dl 	=M::<<<<<	= 	= 	= 	=r   ru  commandwait_for_enterdisplay_before_textr*   	wait_textc                   K   t                      4 d{V  	  j                                        n.# t          $ r! t          j                                        Y nw xY w	  j                                        n.# t          $ r! t          j                                        Y nw xY wd fd}t          |           d{V  |rt          |           d{V  ddd          d{V  dS # 1 d{V swxY w Y   dS )a  
        Run system command (While hiding the prompt. When finished, all the
        output will scroll above the prompt.)

        :param command: Shell command to be executed.
        :param wait_for_enter: FWait for the user to press enter, when the
            command is finished.
        :param display_before_text: If given, text to be displayed before the
            command executes.
        :return: A `Future` object.
        Nr   r   c                                                     t          d          } |                                  d S )NT)shellstdinr  )
print_textr   r  )pr  r  input_fd	output_fdr   s    r   run_commandz3Application.run_system_command.<locals>.run_command>  s=     3444'XiPPPr   r   )
rU   r   filenoAttributeErrorrJ  r  r   r  r$   ry  )r   r  r  r  r  r  r  r  s   `` `  @@r   run_system_commandzApplication.run_system_command  s     $ == 	4 	4 	4 	4 	4 	4 	4 	4.:,,..! . . .9++--.0 K..00		! 0 0 0J--//			0         
 /{;;;;;;;;;  4(333333333-	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4sU   C88C8(A# C8"A##C8'B C8(B,)C8+B,,9C88
DDsuspend_groupc                D    t           dfd}t          |           dS dS )z
        (Not thread safe -- to be called from inside the key bindings.)
        Suspend process.

        :param suspend_group: When true, suspend the whole process group.
            (This is the default, and probably what you want.)
        Nr   r   c                     t          t          t                    } rt          j        d|            d S t          j        t          j                    |            d S )Nr   )r   int_SIGTSTPoskillgetpid)r:  r  s    r   r   z.Application.suspend_to_background.<locals>.runU  sR    c8,, ! 1GAv&&&&&GBIKK00000r   r   )r  rV   )r   r  r   s    ` r   suspend_to_backgroundz!Application.suspend_to_backgroundI  sG     
1 
1 
1 
1 
1 
1 C       r   textc                Z    t          | j        ||p| j        | j        | j                   dS )a\  
        Print a list of (style_str, text) tuples to the output.
        (When the UI is running, this method has to be called through
        `run_in_terminal`, otherwise it will destroy the UI.)

        :param text: List of ``(style_str, text)`` tuples.
        :param style: Style class to use. Defaults to the active style in the CLI.
        )r   formatted_textr`   rk   rc   N)rF   r   r   rk   rc   )r   r  r`   s      r   r  zApplication.print_textc  sD     	;-4-(!%!:	
 	
 	
 	
 	
 	
r   c                    | j         S )z8`True` when the application is currently active/running.r2  r   s    r   
is_runningzApplication.is_runningv  s     r   c                F    | j         r| j                                         S dS r   )r   r  r   s    r   r   zApplication.is_done{  s%    ; 	&;##%%%ur   	list[str]c                x    | j         j        }|r+t          d |                                D                       S g S )z|
        Return a list of used style strings. This is helpful for debugging, and
        for writing a new `Style`.
        c              3  f   K   | ],}t          j        d d|                                          V  -dS )z\s+ N)resubstrip).0	style_strs     r   	<genexpr>z5Application.get_used_style_strings.<locals>.<genexpr>  sP         vsI..4466     r   )r   _attrs_for_stylesortedr  )r   attrs_for_styles     r   get_used_style_stringsz"Application.get_used_style_strings  sW    
 -8 	  !0!5!5!7!7     
 	r   )4r^   r_   r`   ra   rb   r(   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   r(   rn   ro   rp   r(   rq   r    rr   rj   rs   r(   rt   ru   rv   ru   rw   rx   ry   rx   rz   r   r{   r|   r}   r|   r~   r|   r   r|   r   r   r   r   r   r   )rb   r'   r   rH   )r   rC   )r   r   )r   rG   r   rf  )F)r   rj   r   r   )r   r   r   r   r   )r   r   r   r   )NTTr]   )
r   r   r  rj   r  rj   r  r   r   rX   )NTTFN)r   r   r  rj   r  rj   rQ  rj   rR  rS  r   rX   )r   r   r   rr  r   r   r  )r  r   r  r   r   r   )r  r  r   r  )r  r  r   r   )r(  rX   r`   r  r   r   )rX  r  r`   r  r   r   )NNr   )r(  r  rX  r  r`   r  r   r   )Tr   ru  )
r  r  r  rj   r  r*   r  r  r   r   )T)r  rj   r   r   )r  r*   r`   ra   r   r   )r   r  ))r  r  r  __doc__r    EMACSr   r   propertyrk   r   r   r   r   r   r   r   r   r   r   r  rP  r   r@  r   rM  r  r   r  rN  r$  r   r   r  r   r  r  r  r  r   r   r   r   r   rW   rW   i   sI       N Nd !%"&7;;?/3&*!MQ&+#($/$5 %49267;)-7:'+?CDHDHCG" $9W W W W Wr
 
 
 
.    X. 

 

 

 X

 	! 	! 	! X	!   @3 3 3 3j ! ! ! X!*4 *4 *4 *4 *4XM M M M+ + + +*   
 
 
 
& & & & &( .2&*"(+V$ V$ V$ V$ V$t .2&*"&*f% f% f% f% f%P! ! ! !4    ^ S: S: S: S:j   4   *   @   ,% % % % " " " X" 79 " " " " " X" NP     X %)@D	%= %= %= %= %=N= = = =  $025(4 (4 (4 (4 (4T! ! ! ! !6 AE
 
 
 
 
&       X     X
     r   c                  z    e Zd ZdZddZedd            Zedd
            ZddZedd            Z	ddZ
ddZdS )r   z
    The `KeyBindings` of key bindings for a `Application`.
    This merges the global key bindings with the one of the current user
    control.
    r  rY   r   r   c                :    || _         t                      | _        d S r   )r  r   _cache)r   r  s     r   r   z_CombinedRegistry.__init__  s     MM 	r   r   c                    t           zZNot needed - this object is not going to be wrapped in another
        KeyBindings object.NotImplementedErrorr   s    r   _versionz_CombinedRegistry._version  
     "!r   list[Binding]c                    t           r  r	  r   s    r   bindingsz_CombinedRegistry.bindings  r  r   r   r=   other_controlslist[UIControl]r5   c                   g }t                      }|}	 |                    |           |                                }||                    |           |                                rn%| j        j                            |          }|n|}zt          |          D ]>}||vr8|                                }|"|                    t          |                     ?| j        j
        r|                    | j        j
                   |                    t          | j        j        | j        j                             |                    | j        j                   |ddd         }t          |          S )z
        Create a `KeyBindings` object that merges the `KeyBindings` from the
        `UIControl` with all the parent controls and the global key bindings.
        TN)r   r  get_key_bindingsappendis_modalr  r^   
get_parentrB   r3   re   r2   r   rn   r   r7   )	r   r   r  re   collected_containers	containerkbparentr   s	            r   _create_key_bindingsz&_CombinedRegistry._create_key_bindings  s    "uu  .		# $$Y///++--B~##B'''!!## X_//	::F~"		#  i 	C 	CA,,,''))> ''(=b(A(ABBB 8  	7 5666 	"28 	
 	
 	
 	DH6777 $DDbD)!,///r   c                      j         j        j        t           j         j                                                  t                    f} j                            | fd          S )Nc                 0                                    S r   )r  )r   r  r   s   r   r   z1_CombinedRegistry._key_bindings.<locals>.<lambda>  s    22>>RR r   )r  r^   r   r   r   	frozensetr  rx  )r   keyr   r  s   ` @@r   _key_bindingsz_CombinedRegistry._key_bindings  sm    7dho??AABBi777{RRRRRR
 
 	
r   r  r6   c                6    | j                             |          S r   )r!  get_bindings_for_keysr   r  s     r   r#  z'_CombinedRegistry.get_bindings_for_keys  s    !77===r   c                6    | j                             |          S r   )r!  get_bindings_starting_with_keysr$  s     r   r&  z1_CombinedRegistry.get_bindings_starting_with_keys  s    !AA$GGGr   N)r  rY   r   r   )r   r   )r   r  )r   r=   r  r  r   r5   )r   r5   )r  r6   r   r  )r  r  r  r  r   r  r  r  r  r!  r#  r&  r   r   r   r   r     s             " " " X"
 " " " X"
40 40 40 40l 
 
 
 X
> > > >H H H H H Hr   r   r  r*   r   r   c                >  K   ddl m} t                      }|                    d          dd            }|                    t          j                  dd	            } || |
          }	 |j                                         d{V  dS # t          $ r Y dS w xY w)z
    Create a sub application to wait for the enter key press.
    This has two advantages over using 'input'/'raw_input':
    - This will share the same input/output I/O.
    - This doesn't block the event loop.
    r   )PromptSessionenterr  Er   r   c                8    | j                                          d S r   )r  r  r  s    r   _okz_do_wait_for_enter.<locals>._ok  s    	r   c                    dS )zDisallow typing.Nr   r,  s    r   _ignorez#_do_wait_for_enter.<locals>._ignore   s	     	r   )r  re   N)r  r*  r   r   )	prompt_toolkit.shortcutsr(  r4   r  r;   r   r  rP  KeyboardInterrupt)r  r(  re   r-  r/  r   s         r   ry  ry    s       766666==Lg    dh     $1=$ $ $Gk##%%%%%%%%%%%   s   -B 
BBhandlerCallable[[], None]r}  c              #    K   t          t          dd          }|t                      sdV  dS t                      }t          |di                               |          }	 |                    ||            dV  |                    |           | |j        ||j        g|j        R   dS dS # |                    |           | |j        ||j        g|j        R   w w xY w)a  
    Attach the given callback as a WINCH signal handler within the context
    manager. Restore the original signal handler when done.

    The `Application.run` method will register SIGWINCH, so that it will
    properly repaint when the terminal window resizes. However, using
    `run_in_terminal`, we can temporarily send an application to the
    background, and run an other app in between, which will then overwrite the
    SIGWINCH. This is why it's important to restore the handler when the app
    terminates.
    rZ   N_signal_handlers)	getattrr:  rQ   r   rx  r9  r<  	_callback_args)r2  sigwinchr   previous_winch_handlers       r   r#  r#    sF     * vz400H~// D$T+=rBBFFxPP'222 	""8,,,!-#D#&0 (-      .- 	""8,,,!-#D#&0 (-     .s   "B0 03C#c               #  D  K   	 ddl m} m}m} n# t          $ r d V  Y d S w xY w||j        _        | f|j        _        ||j        _        | |f|j        _        t          j
        t          j                  }|                    t          j                  }	 d V  |t          j	        t          j        |           |                    t          j        |           d S # |t          j	        t          j        |           |                    t          j        |           w xY w)Nr   )c_intc_void_p	pythonapi)ctypesr<  r=  r>  ImportErrorPyOS_getsigrestypeargtypesPyOS_setsigr:  	getsignalr;  )r<  r=  r>  sigint	sigint_oss        r   r8  r8  ;  s;     
55555555555    %-I!&+XI" %-I!&I"
 fm,,F%%fm44I8M&-000fmY77777 M&-000fmY7777s   
 !!C AD)r  r*   r   r   )r2  r3  r   r}  r  )
__future__r   rm  r  r  r  r:  rJ  r-  r   r   r   r   r   r   r	   
contextlibr
   r   
subprocessr   	tracebackr   typingr   r   r   r   r   r   r   r   r   r   r   prompt_toolkit.bufferr   prompt_toolkit.cacher   prompt_toolkit.clipboardr   r   prompt_toolkit.cursor_shapesr   r   prompt_toolkit.data_structuresr   prompt_toolkit.enumsr    prompt_toolkit.eventloopr!   r"   r#   r$   prompt_toolkit.eventloop.utilsr%   prompt_toolkit.filtersr&   r'   r(   r)   prompt_toolkit.formatted_textr*   prompt_toolkit.input.baser+   prompt_toolkit.input.typeaheadr,   r-   3prompt_toolkit.key_binding.bindings.page_navigationr.   #prompt_toolkit.key_binding.defaultsr/   &prompt_toolkit.key_binding.emacs_stater0   'prompt_toolkit.key_binding.key_bindingsr1   r2   r3   r4   r5   r6   r7   (prompt_toolkit.key_binding.key_processorr8   r9   #prompt_toolkit.key_binding.vi_stater:   prompt_toolkit.keysr;    prompt_toolkit.layout.containersr<   r=   prompt_toolkit.layout.controlsr>   r?   prompt_toolkit.layout.dummyr@   prompt_toolkit.layout.layoutrA   rB   prompt_toolkit.outputrC   rD   prompt_toolkit.rendererrE   rF   prompt_toolkit.searchrG   prompt_toolkit.stylesrH   rI   rJ   rK   rL   rM   rN   rO   prompt_toolkit.utilsrP   rQ   currentrS   rT   rV   rU   __all__r*  rX   ApplicationEventHandlerr6  	_SIGWINCHr  rW   r   ry  r#  r8  r   r   r   <module>rm     s   " " " " " "      				 				  



                     1 0 0 0 0 0 0 0                                      ) ( ( ( ( ( , , , , , , A A A A A A A A U U U U U U U U / / / / / / , , , , , ,            @ ? ? ? ? ? M M M M M M M M M M M M : : : : : : + + + + + + I I I I I I I I      B A A A A A = = = = = =                  Q P P P P P P P 7 7 7 7 7 7 $ $ $ $ $ $ > > > > > > > > C C C C C C C C ; ; ; ; ; ; 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 B B B B B B B B - - - - - -	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 7 6 6 6 6 6 6 6 - - - - - - - - 9 9 9 9 9 9 9 9 
 W\""
"$=#>#DE GFJ--	769d++e e e e e'*% e e eP)]H ]H ]H ]H ]H ]H ]H ]H@   : ) ) ) )X 8 8 8 8 8 8r   