o
    i0                     @  s  d dl mZ d dl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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l0m1Z1 d dl2m3Z3 d dl4m5Z5 d dl6m7Z7 g dZ8e!Z9G dd de)Z:G dd dZ;G dd dZ<G dd dZ=G dd de/Z>G dd dZ?G dd  d Z@d!S )"    )annotations)AnyOptional)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                      s    e Zd Zdd fd
dZ  ZS )r+    textr   stylestrkwr   returnNonec                   s*   t  jt|fi ||dtddd d S )NT   )min)r1   dont_extend_heightheight)super__init__r!   r%   )selfr0   r1   r3   	__class__ Z/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/prompt_toolkit/widgets/toolbars.pyr;   =   s   
zFormattedTextToolbar.__init__)r/   )r0   r   r1   r2   r3   r   r4   r5   )__name__
__module____qualname__r;   __classcell__r?   r?   r=   r@   r+   <   s    r+   c                   @  s>   e Zd ZdZ		ddd
dZdddZdddZd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	   r4   r5   c                   s   | _ t| _ttd _   _t jt	ddt
 fddddg jd _t jddd	 _t jt jd
 _d S )N)nameclass:system-toolbar.textr1   c                     s    j S N)rF   r?   r<   r?   r@   <lambda>_   s    z(SystemToolbar.__init__.<locals>.<lambda>class:system-toolbar)bufferlexerinput_processorskey_bindingsr6   r9   r1   contentfilter)rF   r   rG   r   r   system_buffer_build_key_bindings	_bindingsr    r'   r&   buffer_controlr   windowr   r   	container)r<   rF   rG   r?   rL   r@   r;   O   s"   

	zSystemToolbar.__init__r   c                 C  s   dd| j jfdgS )N)rN   rE   rI   )r/   
)rW   r0   rL   r?   r?   r@   _get_display_before_textl   s   
z&SystemToolbar._get_display_before_textr   c                   s(  t  j}t }|j}|d|d|d|d|d|dd fd	d
}|d|dd fdd}t }|j}|d|d|d|dd fdd}|d|dd fdd}t }	|	j}|tjd| t@ ddd fdd}
|d| t@ t@ ddd fdd}t	t
|tt
|tt
|	 jgS )Nescape)rV   zc-gzc-ceventEr4   r5   c                   s    j   | jj  dS zHide system prompt.N)rW   resetapplayout
focus_lastr`   rL   r?   r@   _cancelz   s   
z2SystemToolbar._build_key_bindings.<locals>._cancelenterc                   s>   | j j jj  dI dH   jjdd | j j  dS zRun system command.)display_before_textNT)append_to_history)rd   run_system_commandrW   r0   r^   rc   re   rf   rg   rL   r?   r@   _accept   s   z2SystemToolbar._build_key_bindings.<locals>._acceptc                   s&   t j| jj_ j  | jj  dS rb   )	r   
NAVIGATIONrd   vi_state
input_moderW   rc   re   rf   rg   rL   r?   r@   
_cancel_vi   s   
z5SystemToolbar._build_key_bindings.<locals>._cancel_vic                   sJ   t j| jj_| jj jj  dI dH   jj	dd | jj
  dS rj   )r   ro   rd   rp   rq   rm   rW   r0   r^   rc   re   rf   rg   rL   r?   r@   
_accept_vi   s   z5SystemToolbar._build_key_bindings.<locals>._accept_vi!T)rV   	is_globalc                   s   | j j j dS )z#M-'!' will focus this user control.N)rd   re   focusr[   rg   rL   r?   r@   	_focus_me   s   z4SystemToolbar._build_key_bindings.<locals>._focus_mec                   s    t j| jj_| jj j dS )zFocus.N)r   INSERTrd   rp   rq   re   rv   r[   rg   rL   r?   r@   _focus_me_vi   s   z7SystemToolbar._build_key_bindings.<locals>._focus_me_vi)r`   ra   r4   r5   )r   rW   r   addr   Escaper
   r   r   r   r   rG   )r<   focusedemacs_bindingshandlerh   rn   vi_bindingsrr   rs   global_bindingsrw   ry   r?   rL   r@   rX   s   s8   









z!SystemToolbar._build_key_bindingsr   c                 C     | j S rK   r\   rL   r?   r?   r@   __pt_container__      zSystemToolbar.__pt_container__N)rE   T)rF   r   rG   r	   r4   r5   r4   r   )r4   r   r4   r   )rA   rB   rC   __doc__r;   r^   rX   r   r?   r?   r?   r@   r-   H   s    

Hr-   c                   @      e Zd Zd	ddZd
ddZdS )r)   r4   r5   c                 C  s0   ddd}t t|dd| _t| jtd| _d S )	Nr4   r   c                  S  s&   t  jjp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   r?   r?   r@   get_formatted_text   s   z/ArgToolbar.__init__.<locals>.get_formatted_textr6   r9   rT   r   )r   r!   r[   r   r   r\   )r<   r   r?   r?   r@   r;      s   

zArgToolbar.__init__r   c                 C  r   rK   r   rL   r?   r?   r@   r      r   zArgToolbar.__pt_container__Nr4   r5   r   rA   rB   rC   r;   r   r?   r?   r?   r@   r)      s    
r)   c                   @  s2   e Zd ZdZ						ddddZdddZdS )r,   zs
    :param vi_mode: Display '/' and '?' instead of I-search.
    :param ignore_case: Search case insensitive.
    NFr/   
I-search: I-search backward: search_bufferBuffer | Noner   booltext_if_not_searchingr   forward_search_promptbackward_search_promptignore_caser	   r4   r5   c                   s~   |d u rt  }tdfddd fdd}|_t|t|dd	gtd
d	|d_ttjdddd_	d S )Nr4   r   c                     s    j t jjv S rK   )controlr   re   search_linksr?   rL   r?   r@   is_searching   s   z,SearchToolbar.__init__.<locals>.is_searchingr   c                     s2    sS j jjtjkrrdS  S rdS S )N?/)r   searcher_search_state	directionr(   BACKWARDr?   r   r   r   r<   r   r   r?   r@   get_before_input   s
   z0SearchToolbar.__init__.<locals>.get_before_inputzclass:search-toolbar.promptrJ   zclass:search-toolbar.text)rO   rQ   rP   r   r6   zclass:search-toolbarrS   rT   )r4   r   )r4   r   )
r   r   r   r"   r&   r'   r   r   r   r\   )r<   r   r   r   r   r   r   r   r?   r   r@   r;      s"   	

	zSearchToolbar.__init__r   c                 C  r   rK   r   rL   r?   r?   r@   r     r   zSearchToolbar.__pt_container__)NFr/   r   r   F)r   r   r   r   r   r   r   r   r   r   r   r	   r4   r5   r   )rA   rB   rC   r   r;   r   r?   r?   r?   r@   r,      s    *r,   c                   @  s   e Zd Zd	ddZdS )
_CompletionsToolbarControlwidthintr9   r4   r#   c                   s@  g  t  jj}|r|j}|j}|d }d}d}g }	t|D ]3\}
}t|	t|j |kr;|
|p0dkr7g }	d}nd} n|		t
|j|
|krFdndd |	d q|	d	d
|t|	  f |	d | }	 d  d|rpdnd
f  d  	|	  d  d|rdnd
f  d d fdd}t|ddS )N   Fr   Tz+class:completion-toolbar.completion.currentz#class:completion-toolbar.completionrJ   )r/    r/   r   zclass:completion-toolbar.arrow<>ir   r4   r   c                   s    S rK   r?   )r   all_fragmentsr?   r@   get_lineE  s   z;_CompletionsToolbarControl.create_content.<locals>.get_liner6   )r   
line_count)r   r   r4   r   )r   current_buffercomplete_statecompletionscomplete_index	enumerater   lendisplay_textextendr   appendr#   )r<   r   r9   r   r   indexcontent_widthcut_left	cut_right	fragmentsr   cr   r?   r   r@   create_content  sP   






z)_CompletionsToolbarControl.create_contentN)r   r   r9   r   r4   r#   )rA   rB   rC   r   r?   r?   r?   r@   r     s    r   c                   @  r   )r*   r4   r5   c                 C  s   t tt dddtd| _d S )Nr6   zclass:completion-toolbarrS   rT   )r   r   r   r   r\   rL   r?   r?   r@   r;   L  s   zCompletionsToolbar.__init__r   c                 C  r   rK   r   rL   r?   r?   r@   r   T  r   z#CompletionsToolbar.__pt_container__Nr   r   r   r?   r?   r?   r@   r*   K  s    
r*   c                   @  s"   e Zd ZddddZdd	d
ZdS )r.   Fshow_positionr   r4   r5   c                   s4   d fdd}t || _tt| jddtd| _d S )	Nr4   r   c                    sX   t  j} | jr*| j| jj\}} r!d| jj|d |d }n| jj}d|fgS g S )Nz{} (line={} column={})r6   zclass:validation-toolbar)r   r   validation_errordocumenttranslate_index_to_positioncursor_positionformatmessage)buffrowcolumnr0   r   r?   r@   r   Z  s   
z6ValidationToolbar.__init__.<locals>.get_formatted_textr6   r   rT   r   )r!   r   r   r   r   r\   )r<   r   r   r?   r   r@   r;   Y  s
   
zValidationToolbar.__init__r   c                 C  r   rK   r   rL   r?   r?   r@   r   u  r   z"ValidationToolbar.__pt_container__N)F)r   r   r4   r5   r   r   r?   r?   r?   r@   r.   X  s    r.   N)A
__future__r   typingr   r   "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__ra   r+   r-   r)   r,   r   r*   r.   r?   r?   r?   r@   <module>   s4    0	w4D