
    f/                       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?y!)"    )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+   c                T    t         |   t        |fi ||dt        d             y )NT   )min)styledont_extend_heightheight)super__init__r!   r%   )selftextr3   kw	__class__s       Z/var/www/cvtools/html/venv/lib/python3.12/site-packages/prompt_toolkit/widgets/toolbars.pyr7   zFormattedTextToolbar.__init__=   s2     	 ,,##	 	 	
    ) )r9   r   r3   strr:   r   returnNone)__name__
__module____qualname__r7   __classcell__)r;   s   @r<   r+   r+   <   s    
 
r=   r+   c                  @    e Zd ZdZ	 	 d	 	 	 	 	 ddZd	dZd
dZddZy)r-   z^
    Toolbar for a system prompt.

    :param prompt: Prompt to be displayed to the user.
    c                    | _         t        |       _        t        t               _         j                          _        t         j
                  t        d      t         fdd      g j                         _        t         j                  dd       _        t         j                  t         j
                        	       _        y )
N)nameclass:system-toolbar.textr3   c                      j                   S N)promptr8   s   r<   <lambda>z(SystemToolbar.__init__.<locals>.<lambda>_   s    DKK r=   class:system-toolbar)bufferlexerinput_processorskey_bindingsr1   r5   r3   contentfilter)rM   r   enable_global_bindingsr   r   system_buffer_build_key_bindings	_bindingsr    r'   r&   buffer_controlr   windowr   r   	container)r8   rM   rY   s   `  r<   r7   zSystemToolbar.__init__O   s    
 &/0F&G##7113+%%$?@/7MN 
 1G
 .KK	$2D2D(E
r=   c                8    dd| j                   j                  fdgS )N)rP   Shell command: rI   )r>   
)rZ   r9   rN   s    r<   _get_display_before_textz&SystemToolbar._get_display_before_textl   s&    7($*<*<*A*AB
 	
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)rX   zc-gzc-cc                    j                   j                          | j                  j                  j	                          yzHide system prompt.N)rZ   resetapplayout
focus_lasteventr8   s    r<   _cancelz2SystemToolbar._build_key_bindings.<locals>._cancelz   s-    
 $$&II'')r=   enterc                   K   | j                   j                  j                  j                  j	                                d{    j                  j                  d       | j                   j                  j                          y7 EwzRun system command.)display_before_textNT)append_to_history)ri   run_system_commandrZ   r9   rc   rh   rj   rk   rl   s    r<   _acceptz2SystemToolbar._build_key_bindings.<locals>._accept   sy      ))..""''$($A$A$C /    $$t$<II'')s   ABBABc                    t         j                  | j                  j                  _        j
                  j                          | j                  j                  j                          yrg   )	r   
NAVIGATIONri   vi_state
input_moderZ   rh   rj   rk   rl   s    r<   
_cancel_viz5SystemToolbar._build_key_bindings.<locals>._cancel_vi   sE     -6,@,@EII)$$&II'')r=   c                r  K   t         j                  | j                  j                  _        | j                  j                  j                  j                  j                                d{    j                  j                  d       | j                  j                  j                          y7 Ewrq   )r   rw   ri   rx   ry   rt   rZ   r9   rc   rh   rj   rk   rl   s    r<   
_accept_viz5SystemToolbar._build_key_bindings.<locals>._accept_vi   s      -6,@,@EII)))..""''$($A$A$C /    $$t$<II'')s   A,B7/B50AB7!T)rX   	is_globalc                d    | j                   j                  j                  j                         y)z#M-'!' will focus this user control.N)ri   rj   focusr^   rl   s    r<   	_focus_mez4SystemToolbar._build_key_bindings.<locals>._focus_me   s!     II""4;;/r=   c                    t         j                  | j                  j                  _        | j                  j
                  j                  j                         y)zFocus.N)r   INSERTri   rx   ry   rj   r   r^   rl   s    r<   _focus_me_viz7SystemToolbar._build_key_bindings.<locals>._focus_me_vi   s9     -6,<,<EII)II""4;;/r=   )rm   Er@   rA   )r   rZ   r   addr   Escaper
   r   r   r   r   rY   )r8   focusedemacs_bindingshandlern   ru   vi_bindingsrz   r|   global_bindingsr   r   s   `           r<   r[   z!SystemToolbar._build_key_bindingss   sn   D../ %##		)	g	&	g	&	* 
' 
' 
*	*
 
	(	* 
)	* "m		)	g	&	* 
' 
*	* 
	(	* 
)	* &- $$	S'J)>$	O	0 
P	0 
WHw.1CCt	T	0 
U	0
 "&~zB&{G<&8S8ST
 	
r=   c                    | j                   S rL   r_   rN   s    r<   __pt_container__zSystemToolbar.__pt_container__       ~~r=   N)ra   T)rM   r   rY   r	   r@   rA   r@   r   )r@   r   r@   r   )rB   rC   rD   __doc__r7   rc   r[   r    r=   r<   r-   r-   H   sA     $5/3
 
 !-
 
	
:
F
Pr=   r-   c                      e Zd ZddZddZy)r)   c                    dd}t        t        |      d      | _        t        | j                  t              | _        y )Nc                 `    t               j                  j                  xs d} | dk(  rd} dd| fgS )Nr>   -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cz 2)3/ r=   r1   r5   rV   r   )r   r!   r^   r   r   r_   )r8   r   s     r<   r7   zArgToolbar.__init__   s0    	 12DEaP-dkk'Rr=   c                    | j                   S rL   r   rN   s    r<   r   zArgToolbar.__pt_container__   r   r=   Nr@   rA   r   rB   rC   rD   r7   r   r   r=   r<   r)   r)      s    Sr=   r)   c                  H    e Zd ZdZ	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZy)r,   zs
    :param vi_mode: Display '/' and '?' instead of I-search.
    :param ignore_case: Search case insensitive.
    Nc                    |
t               }t        d fd       d fd}| _        t        |t	        |d      gt        d      |       _        t        t         j                  dd	      
       _	        y )Nc                 X     j                   t               j                  j                  v S rL   )controlr   rj   search_linksrN   s   r<   is_searchingz,SearchToolbar.__init__.<locals>.is_searching   s     <<79#3#3#@#@@@r=   c                             sS j                   j                  j                  t        j                  k(  rrdS  S rdS S )N?/)r   searcher_search_state	directionr(   BACKWARD)backward_search_promptforward_search_promptr   r8   text_if_not_searchingr   s   r<   get_before_inputz0SearchToolbar.__init__.<locals>.get_before_input   sH    >,,22<<@X@XX%sA+AA%s@+@@r=   zclass:search-toolbar.promptrJ   zclass:search-toolbar.text)rQ   rS   rR   ignore_caser1   zclass:search-toolbarrU   rV   )r@   bool)r@   r   )
r   r   search_bufferr"   r&   r'   r   r   r   r_   )	r8   r   r   r   r   r   r   r   r   s	   ` ````  @r<   r7   zSearchToolbar.__init__   s      "HM		A 
	A	A 	A +* ,4QR $?@#
 .4<<9OP
r=   c                    | j                   S rL   r   rN   s    r<   r   zSearchToolbar.__pt_container__  r   r=   )NFr>   z
I-search: zI-search backward: F)r   zBuffer | Noner   r   r   r   r   r   r   r   r   r	   r@   rA   r   )rB   rC   rD   r   r7   r   r   r=   r<   r,   r,      sj     (,242>3H$)(
$(
 (
  0	(

  0(
 !1(
 "(
 
(
Tr=   r,   c                      e Zd ZddZy)_CompletionsToolbarControlc                   g t               j                  j                  }|rT|j                  }|j                  }|dz
  }d}d}g }	t        |      D ]y  \  }
}t        |	      t        |j                        z   |k\  r|
|xs dk  rg }	d}nd} n@|	j                  t        |j                  |
|k(  rdnd             |	j                  d       { |	j                  d	d
|t        |	      z
  z  f       |	d | }	j                  d       j                  d|rdnd
f       j                  d       j                  |	       j                  d       j                  d|rdnd
f       j                  d       dfd}t        |d      S )N   Fr   Tz+class:completion-toolbar.completion.currentz#class:completion-toolbar.completionrJ   )r>    r>   r   zclass:completion-toolbar.arrow<>c                    S rL   r   )iall_fragmentss    r<   get_linez;_CompletionsToolbarControl.create_content.<locals>.get_lineE  s	      r=   r1   )r   
line_count)r   intr@   r   )r   current_buffercomplete_statecompletionscomplete_index	enumerater   lendisplay_textextendr   appendr#   )r8   widthr5   r   r   indexcontent_widthcut_left	cut_right	fragmentsr   cr   r   s                @r<   create_contentz)_CompletionsToolbarControl.create_content  s   ,. 11@@(44K"11E "AIM HI -/I!+. ,1$Y/#ann2EEVUZa($&	#' %)	  %  !Ez J!F	   +-,2 b#9J99U)U"VWX!.=1I   +  1(3L   +  +  +  1)3M   +	! (q99r=   N)r   r   r5   r   r@   r#   )rB   rC   rD   r   r   r=   r<   r   r     s    @:r=   r   c                      e Zd ZddZddZy)r*   c                X    t        t        t               dd      t              | _        y )Nr1   zclass:completion-toolbarrU   rV   )r   r   r   r   r_   rN   s    r<   r7   zCompletionsToolbar.__init__L  s&    -*,Q>X #	
r=   c                    | j                   S rL   r   rN   s    r<   r   z#CompletionsToolbar.__pt_container__T  r   r=   Nr   r   r   r   r=   r<   r*   r*   K  s    
r=   r*   c                      e Zd ZdddZddZy)r.   c                    dfd}t        |      | _        t        t        | j                  d      t              | _        y )Nc                 2   t               j                  } | j                  ru| j                  j	                  | j                  j
                        \  }}r&| j                  j                   d|dz    d|dz    d}n| j                  j                  }d|fgS g S )Nz (line=r1   z column=)zclass:validation-toolbar)r   r   validation_errordocumenttranslate_index_to_positioncursor_positionmessage)buffrowcolumnr9   show_positions       r<   r   z6ValidationToolbar.__init__.<locals>.get_formatted_textZ  s    9++D$$"mmGG))99V !"33;;<GC!G9HU[^_U_T``abD0088D3T:;;	r=   r1   r   rV   r   )r!   r   r   r   r   r_   )r8   r   r   s    ` r<   r7   zValidationToolbar.__init__Y  s4    	" ,,>?-4<<2;O
r=   c                    | j                   S rL   r   rN   s    r<   r   z"ValidationToolbar.__pt_container__q  r   r=   N)F)r   r   r@   rA   r   r   r   r=   r<   r.   r.   X  s    
0r=   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__r   r+   r-   r)   r,   r   r*   r.   r   r=   r<   <module>r      s    "  6 ( .     C 9 $ T T  6 8 - 1 	
6 	
t tn (1 1hA: A:H
 
 r=   