
    Mh/                       d dl mZ d dlmZ d dl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 d dlmZmZmZmZ d dlmZmZmZmZ d d	lm Z  d d
l!m"Z" d dl#m$Z$ d dl%m&Z&m'Z'm(Z( d dl)m*Z*m+Z+m,Z,m-Z-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 g dZ7e Z8 G d de(          Z9 G d d          Z: G d d          Z; G d d          Z< G d de.          Z= G d d          Z> G d d           Z?d!S )"    )annotations)Any)get_app)Buffer)SYSTEM_BUFFER)
	ConditionFilterOrBool
emacs_modehas_arghas_completions	has_focushas_validation_error	to_filtervi_modevi_navigation_mode)AnyFormattedTextStyleAndTextTuplesfragment_list_lento_formatted_text)ConditionalKeyBindingsKeyBindingsKeyBindingsBasemerge_key_bindings)KeyPressEvent)	InputMode)Keys)ConditionalContainer	ContainerWindow)BufferControlFormattedTextControlSearchBufferControl	UIContent	UIControl)	Dimension)BeforeInput)SimpleLexer)SearchDirection)
ArgToolbarCompletionsToolbarFormattedTextToolbarSearchToolbarSystemToolbarValidationToolbarc                  "     e Zd Zdd fd
Z xZS )r+    textr   stylestrkwr   returnNonec                    t                                          t          |fi ||dt          d                     d S )NT   )min)r2   dont_extend_heightheight)super__init__r!   r%   )selfr1   r2   r4   	__class__s       _/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prompt_toolkit/widgets/toolbars.pyr=   zFormattedTextToolbar.__init__=   sW     	 ,,,,####	 	 	
 	
 	
 	
 	
    )r0   )r1   r   r2   r3   r4   r   r5   r6   )__name__
__module____qualname__r=   __classcell__)r?   s   @r@   r+   r+   <   sB        
 
 
 
 
 
 
 
 
 
 
rA   r+   c                  8    e Zd ZdZ	 	 ddd
ZddZddZddZdS )r-   z^
    Toolbar for a system prompt.

    :param prompt: Prompt to be displayed to the user.
    Shell command: Tpromptr   enable_global_bindingsr	   r5   r6   c                    | _         t          |           _        t          t                     _                                          _        t           j        t          d          t           fdd          g j                   _        t           j        dd           _        t           j        t           j                  	           _        d S )
N)nameclass:system-toolbar.textr2   c                      j         S N)rH   r>   s   r@   <lambda>z(SystemToolbar.__init__.<locals>.<lambda>_   s	    DK rA   class:system-toolbar)bufferlexerinput_processorskey_bindingsr8   r;   r2   contentfilter)rH   r   rI   r   r   system_buffer_build_key_bindings	_bindingsr    r'   r&   buffer_controlr   windowr   r   	container)r>   rH   rI   s   `  r@   r=   zSystemToolbar.__init__O   s    
 &/0F&G&G##7771133+%$?@@@////7MNNN 
 
 
 1G
 
 
 .K	$2D(E(E
 
 
rA   r   c                $    dd| j         j        fdgS )N)rR   rG   rL   )r0   
)r[   r1   rP   s    r@   _get_display_before_textz&SystemToolbar._get_display_before_textl   s     7($*<*AB
 	
rA   r   c                ,    t           j                  }t                      }|j        } |d|           |d|           |d|          d fd	                                    } |d
|          d fd            }t                      }|j        } |d|           |d|          d fd                        } |d
|          d fd            }t                      }	|	j        } |t          j        d| t          z  d          d fd            }
 |d| t          z  t          z  d          d fd            }t          t          |t                    t          |t                    t          |	 j                  g          S )Nescape)rZ   zc-gzc-ceventEr5   r6   c                v    j                                          | j        j                                         dS zHide system prompt.N)r[   resetapplayout
focus_lastrf   r>   s    r@   _cancelz2SystemToolbar._build_key_bindings.<locals>._cancelz   s7    
 $$&&&I'')))))rA   enterc                   K   | j                             j        j                                                   d{V  j                            d           | j         j                                         dS zRun system command.)display_before_textNT)append_to_history)rk   run_system_commandr[   r1   rc   rj   rl   rm   rn   s    r@   _acceptz2SystemToolbar._build_key_bindings.<locals>._accept   s       ).."'$($A$A$C$C /          $$t$<<<I'')))))rA   c                    t           j        | j        j        _        j                                         | j        j                                         dS ri   )	r   
NAVIGATIONrk   vi_state
input_moder[   rj   rl   rm   rn   s    r@   
_cancel_viz5SystemToolbar._build_key_bindings.<locals>._cancel_vi   sG     -6,@EI)$$&&&I'')))))rA   c                0  K   t           j        | j        j        _        | j                            j        j                                                   d{V  j        	                    d           | j        j
                                         dS rr   )r   rx   rk   ry   rz   ru   r[   r1   rc   rj   rl   rm   rn   s    r@   
_accept_viz5SystemToolbar._build_key_bindings.<locals>._accept_vi   s       -6,@EI)).."'$($A$A$C$C /          $$t$<<<I'')))))rA   !T)rZ   	is_globalc                P    | j         j                            j                   dS )z#M-'!' will focus this user control.N)rk   rl   focusr_   rn   s    r@   	_focus_mez4SystemToolbar._build_key_bindings.<locals>._focus_me   s&     I""4;/////rA   c                    t           j        | j        j        _        | j        j                            j                   dS )zFocus.N)r   INSERTrk   ry   rz   rl   r   r_   rn   s    r@   _focus_me_viz7SystemToolbar._build_key_bindings.<locals>._focus_me_vi   s6     -6,<EI)I""4;/////rA   )rf   rg   r5   r6   )r   r[   r   addr   Escaper
   r   r   r   r   rI   )r>   focusedemacs_bindingshandlero   rv   vi_bindingsr{   r}   global_bindingsr   r   s   `           r@   r\   z!SystemToolbar._build_key_bindingss   sP   D.// %#		)	)	)	g	&	&	&	g	&	&	&	* 	* 	* 	* 	* 
'	& 
'	& 
*	)	*
 
	(	(	(	* 	* 	* 	* 	* 
)	(	* "mm		)	)	)	g	&	&	&	* 	* 	* 	* 	* 
'	& 
*	)	* 
	(	(	(	* 	* 	* 	* 	* 
)	(	* &-- $	S'J)>$	O	O	O	0 	0 	0 	0 	0 
P	O	0 
WHw.1CCt	T	T	T	0 	0 	0 	0 	0 
U	T	0
 "&~zBB&{G<<&8STT
 
 	
rA   r   c                    | j         S rO   r`   rP   s    r@   __pt_container__zSystemToolbar.__pt_container__   
    ~rA   N)rG   T)rH   r   rI   r	   r5   r6   r5   r   )r5   r   r5   r   )rB   rC   rD   __doc__r=   rc   r\   r    rA   r@   r-   r-   H   s          $5/3
 
 
 
 
:
 
 
 
F
 F
 F
 F
P     rA   r-   c                      e Zd ZddZddZdS )	r)   r5   r6   c                    dd}t          t          |          d          | _        t          | j        t                    | _        d S )Nr5   r   c                 R    t                      j        j        pd} | dk    rd} dd| fgS )Nr0   -z-1)zclass:arg-toolbarzRepeat: zclass:arg-toolbar.text)r   key_processorarg)r   s    r@   get_formatted_textz/ArgToolbar.__init__.<locals>.get_formatted_text   s;    )))-3Cczz 2)3/ rA   r8   r;   rX   r   )r   r!   r_   r   r   r`   )r>   r   s     r@   r=   zArgToolbar.__init__   sP    	 	 	 	 12DEEaPPP-dk'RRRrA   r   c                    | j         S rO   r   rP   s    r@   r   zArgToolbar.__pt_container__   r   rA   Nr5   r6   r   rB   rC   rD   r=   r   r   rA   r@   r)   r)      s@        S S S S     rA   r)   c                  0    e Zd ZdZ	 	 	 	 	 	 dddZddZdS )r,   zs
    :param vi_mode: Display '/' and '?' instead of I-search.
    :param ignore_case: Search case insensitive.
    NFr0   
I-search: I-search backward: search_bufferBuffer | Noner   booltext_if_not_searchingr   forward_search_promptbackward_search_promptignore_caser	   r5   r6   c                >    |t                      }t          d fd            d fd}| _        t          |t	          |d          gt          d          |	           _        t          t           j        d
d                     _	        d S )Nr5   r   c                 B     j         t                      j        j        v S rO   )controlr   rl   search_linksrP   s   r@   is_searchingz,SearchToolbar.__init__.<locals>.is_searching   s    <799#3#@@@rA   r   c                 r                 sS j         j        j        t          j        k    rrdn S rdnS )N?/)r   searcher_search_state	directionr(   BACKWARD)r   r   r   r>   r   r   s   r@   get_before_inputz0SearchToolbar.__init__.<locals>.get_before_input   sN    <>> A,,2<@XXX%Ass+AA%@ss+@@rA   zclass:search-toolbar.promptrM   zclass:search-toolbar.text)rS   rU   rT   r   r8   zclass:search-toolbarrW   rX   )r5   r   )r5   r   )
r   r   r   r"   r&   r'   r   r   r   r`   )	r>   r   r   r   r   r   r   r   r   s	   ` ````  @r@   r=   zSearchToolbar.__init__   s     "HHM		A 	A 	A 	A 	A 
	A	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A +* ,4QRRR $?@@@#
 
 
 .4<9OPPP
 
 
rA   r   c                    | j         S rO   r   rP   s    r@   r   zSearchToolbar.__pt_container__  r   rA   )NFr0   r   r   F)r   r   r   r   r   r   r   r   r   r   r   r	   r5   r6   r   )rB   rC   rD   r   r=   r   r   rA   r@   r,   r,      s`          (,242>3H$)(
 (
 (
 (
 (
T     rA   r,   c                      e Zd ZddZdS )	_CompletionsToolbarControlwidthintr;   r5   r#   c                l   g t                      j        j        }|r|j        }|j        }|dz
  }d}d}g }	t          |          D ]\  }
}t          |	          t          |j                  z   |k    r|
|pdk    rg }	d}nd} nG|		                    t          |j        |
|k    rdnd                     |	                    d           |	                    d	d
|t          |	          z
  z  f           |	d |         }	                    d                               d|rdnd
f                               d           	                    |	                               d                               d|rdnd
f                               d           dfd}t          |d          S )N   Fr   Tz+class:completion-toolbar.completion.currentz#class:completion-toolbar.completionrM   )r0    r0   r   zclass:completion-toolbar.arrow<>ir   r5   r   c                    S rO   r   )r   all_fragmentss    r@   get_linez;_CompletionsToolbarControl.create_content.<locals>.get_lineE  s	      rA   r8   )r   
line_count)r   r   r5   r   )r   current_buffercomplete_statecompletionscomplete_index	enumerater   lendisplay_textextendr   appendr#   )r>   r   r;   r   r   indexcontent_widthcut_left	cut_right	fragmentsr   cr   r   s                @r@   create_contentz)_CompletionsToolbarControl.create_content  s;   ,. 1@ 7	,(4K"1E "AIM HI -/I!+.. , ,1$Y//#an2E2EEVVUZa(($&	#' %)	  %  !Ezz JI!F  	 	 	   ++++ b#9J99U9U)U"VWXXX!.=.1I   +++  1(3K33L     +++  +++  +++  1)3L33M     +++	! 	! 	! 	! 	! 	! (q9999rA   N)r   r   r;   r   r5   r#   )rB   rC   rD   r   r   rA   r@   r   r     s.        @: @: @: @: @: @:rA   r   c                      e Zd ZddZddZdS )	r*   r5   r6   c                t    t          t          t                      dd          t                    | _        d S )Nr8   zclass:completion-toolbarrW   rX   )r   r   r   r   r`   rP   s    r@   r=   zCompletionsToolbar.__init__L  sA    -*,,Q>X   #	
 
 
rA   r   c                    | j         S rO   r   rP   s    r@   r   z#CompletionsToolbar.__pt_container__T  r   rA   Nr   r   r   r   rA   r@   r*   r*   K  s<        
 
 
 
     rA   r*   c                       e Zd Zd
ddZddZd	S )r.   Fshow_positionr   r5   r6   c                    dfd}t          |          | _        t          t          | j        d          t                    | _        d S )Nr5   r   c                     t                      j        } | j        rV| j                            | j        j                  \  }}r| j        j         d|dz    d|dz    d}n| j        j        }d|fgS g S )Nz (line=r8   z column=)zclass:validation-toolbar)r   r   validation_errordocumenttranslate_index_to_positioncursor_positionmessage)buffrowcolumnr1   r   s       r@   r   z6ValidationToolbar.__init__.<locals>.get_formatted_textZ  s    99+D$ "mGG)9 V ! 9"3;bbC!GbbU[^_U_bbbDD08D3T:;;	rA   r8   r   rX   r   )r!   r   r   r   r   r`   )r>   r   r   s    ` r@   r=   zValidationToolbar.__init__Y  sb    	 	 	 	 	 	" ,,>??-4<222;O
 
 
rA   r   c                    | j         S rO   r   rP   s    r@   r   z"ValidationToolbar.__pt_container__q  r   rA   N)F)r   r   r5   r6   r   r   r   rA   r@   r.   r.   X  sA        
 
 
 
 
0     rA   r.   N)@
__future__r   typingr   "prompt_toolkit.application.currentr   prompt_toolkit.bufferr   prompt_toolkit.enumsr   prompt_toolkit.filtersr   r	   r
   r   r   r   r   r   r   r   prompt_toolkit.formatted_textr   r   r   r   'prompt_toolkit.key_binding.key_bindingsr   r   r   r   (prompt_toolkit.key_binding.key_processorr   #prompt_toolkit.key_binding.vi_stater   prompt_toolkit.keysr    prompt_toolkit.layout.containersr   r   r   prompt_toolkit.layout.controlsr    r!   r"   r#   r$   prompt_toolkit.layout.dimensionr%    prompt_toolkit.layout.processorsr&   prompt_toolkit.lexersr'   prompt_toolkit.searchr(   __all__rg   r+   r-   r)   r,   r   r*   r.   r   rA   r@   <module>r      s   " " " " " "       6 6 6 6 6 6 ( ( ( ( ( ( . . . . . .                                              C B B B B B 9 9 9 9 9 9 $ $ $ $ $ $ T T T T T T T T T T              6 5 5 5 5 5 8 8 8 8 8 8 - - - - - - 1 1 1 1 1 1   	
 	
 	
 	
 	
6 	
 	
 	
t t t t t t t tn       (1 1 1 1 1 1 1 1hA: A: A: A: A: A: A: A:H
 
 
 
 
 
 
 
         rA   