o
    iF#                     @  s   d dl mZ d dlZd dlmZ d dl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 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 d dlmZ d dl m!Z!m"Z" 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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8 g dZ9					dVdWd#d$Z:ed%Z;ddg dfdXd)d*Z<			+	,			-		dYdZd8d9Z=			:	d[d\d<d=Z>			:	,			d]d^dAdBZ?			:	,			d]d_dFdGZ@dddHdI dfd`dLdMZAdadQdRZBdbdTdUZCdS )c    )annotationsN)get_running_loop)AnyCallableListOptionalSequenceTupleTypeVar)Application)get_app)Buffer)	Completerrun_in_executor_with_context)FilterOrBool)AnyFormattedText)
focus_nextfocus_previous)load_key_bindings)KeyBindingsmerge_key_bindings)Layout)AnyContainerHSplit)	Dimension)	BaseStyle)	Validator)	BoxButtonCheckboxListDialogLabelProgressBar	RadioListTextAreaValidationToolbar)yes_no_dialogbutton_dialoginput_dialogmessage_dialogradiolist_dialogcheckboxlist_dialogprogress_dialog YesNotitler   textyes_textstrno_textstyleBaseStyle | NonereturnApplication[bool]c                 C  sJ   ddd}ddd}t | t|ddt||d	t||d	gdd
}t||S )z8
    Display a Yes/No dialog.
    Return a boolean.
    r8   Nonec                   S     t  jdd d S )NTresultr   exit r@   r@   [/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/prompt_toolkit/shortcuts/dialogs.pyyes_handler9      z"yes_no_dialog.<locals>.yes_handlerc                   S  r;   )NFr<   r>   r@   r@   r@   rA   
no_handler<   rC   z!yes_no_dialog.<locals>.no_handlerTr2   dont_extend_heightr2   handlerr1   bodybuttonswith_backgroundNr8   r:   )r!   r"   r   _create_app)r1   r2   r3   r5   r6   rB   rD   dialogr@   r@   rA   r'   -   s   






r'   _TrK   list[tuple[str, _T]]Application[_T]c                   s:   ddd t | t|dd fd	d
|D dd}t||S )zx
    Display a dialog with button choices (given as a list of tuples).
    Return the value associated with button.
    vrP   r8   r:   c                 S  s   t  j| d d S Nr<   r>   )rS   r@   r@   rA   button_handlerZ   rC   z%button_dialog.<locals>.button_handlerTrE   c                   s$   g | ]\}}t |t |d qS )rG   )r   	functoolspartial).0trS   rU   r@   rA   
<listcomp>`   s    z!button_dialog.<locals>.<listcomp>rI   N)rS   rP   r8   r:   )r!   r"   rN   )r1   r2   rK   r6   rO   r@   rZ   rA   r(   O   s   




r(   OKCancelFok_textcancel_text	completerCompleter | None	validatorValidator | Nonepasswordr   defaultApplication[str]c	                   s   d fdd}	dfdd	}
t ||
d
 t |td
}t|d||||	dt| tt|ddt gtdddd |gdd}t||S )zV
    Display a text input box.
    Return the given text, or None when cancelled.
    bufr   r8   boolc                   s   t  j  dS )NT)r   layoutfocus)rg   )	ok_buttonr@   rA   acceptz   s   zinput_dialog.<locals>.acceptr:   c                        t  j jd d S rT   )r   r?   r2   r@   )	textfieldr@   rA   
ok_handler~      z input_dialog.<locals>.ok_handlerrG   F)r2   	multilinerd   r`   rb   accept_handlerTrE      )	preferredmaxpaddingrI   N)rg   r   r8   rh   rM   )	r   _return_noner%   r!   r   r"   r&   DrN   )r1   r2   r^   r_   r`   rb   rd   r6   re   rl   ro   cancel_buttonrO   r@   )rk   rn   rA   r)   j   s2   	


r)   OkApplication[None]c                 C  s,   t | t|ddt|tdgdd}t||S )zM
    Display a simple message box and wait until the user presses enter.
    TrE   rG   rI   )r!   r"   r   rx   rN   )r1   r2   r^   r6   rO   r@   r@   rA   r*      s   	

r*   values,Sequence[tuple[_T, AnyFormattedText]] | None	_T | Nonec           	        h   |du rg }d fdd}t ||d t| tt|dd gd	d
t||dt|tdgdd}t||S )z
    Display a simple list of element the user can choose amongst.

    Only one element can be selected at a time using Arrow keys and Enter.
    The focus can be moved between the list and the Ok/Cancel button with tab.
    Nr8   r:   c                     rm   rT   )r   r?   current_valuer@   
radio_listr@   rA   ro      rp   z$radiolist_dialog.<locals>.ok_handler)r}   re   TrE   rs   rv   rG   rI   rM   )r$   r!   r   r"   r   rx   rN   )	r1   r2   r^   r_   r}   re   r6   ro   rO   r@   r   rA   r+          


r+   default_valuesSequence[_T] | NoneApplication[list[_T]]c           	        r   )z
    Display a simple list of element the user can choose multiple values amongst.

    Several elements can be selected at a time using Arrow keys and Enter.
    The focus can be moved between the list and the Ok/Cancel button with tab.
    Nr8   r:   c                     rm   rT   )r   r?   current_valuesr@   cb_listr@   rA   ro      rp   z'checkboxlist_dialog.<locals>.ok_handler)r}   r   TrE   rs   rv   rG   rI   rM   )r    r!   r   r"   r   rx   rN   )	r1   r2   r^   r_   r}   r   r6   ro   rO   r@   r   rA   r,      r   r,   c                  G  s   d S Nr@   )ar@   r@   rA   <lambda>  s    r   run_callback>Callable[[Callable[[int], None], Callable[[str], None]], None]c                   s   t  t tdtdddtttt|dttddg| dd	}t	|| d fddd fddd fdddfdd} j
|  S )zz
    :param run_callback: A function that receives as input a `set_percentage`
        function and it does the work.
    Fl    d(	 )rt   )	focusableheightr2   rs   rv   T)rJ   r1   rL   valueintr8   r:   c                   s   t | _   d S r   )r   
percentage
invalidate)r   )appprogressbarr@   rA   set_percentage!  s   
z'progress_dialog.<locals>.set_percentager2   r4   c                   s    jj|     d S r   )call_soon_threadsafebufferinsert_textr   r   )r   loop	text_arear@   rA   log_text%  s   z!progress_dialog.<locals>.log_textc                     s$   z W     d S     w r   )r?   r@   )r   r   r   r   r@   rA   start+  s   zprogress_dialog.<locals>.startc                     s   t   d S r   r   r@   )r   r@   rA   pre_run1  s   z progress_dialog.<locals>.pre_runN)r   r   r8   r:   )r2   r4   r8   r:   rM   )r   r#   r%   ry   r!   r   r   r"   exactrN   pre_run_callablesappend)r1   r2   r   r6   rO   r   r@   )r   r   r   r   r   r   r   r   rA   r-      s.   
r-   rO   r   Application[Any]c                 C  sB   t  }|dt |dt tt| tt |gd|ddS )Ntabzs-tabT)ri   key_bindingsmouse_supportr6   full_screen)r   addr   r   r   r   r   r   )rO   r6   bindingsr@   r@   rA   rN   9  s   rN   r:   c                   C  s   t    dS )z!Button handler that returns None.Nr>   r@   r@   r@   rA   rx   H  s   rx   )r.   r.   r/   r0   N)r1   r   r2   r   r3   r4   r5   r4   r6   r7   r8   r9   )
r1   r   r2   r   rK   rQ   r6   r7   r8   rR   )	r.   r.   r\   r]   NNFNr.   )r1   r   r2   r   r^   r4   r_   r4   r`   ra   rb   rc   rd   r   r6   r7   re   r4   r8   rf   )r.   r.   r{   N)
r1   r   r2   r   r^   r4   r6   r7   r8   r|   )r.   r.   r{   r]   NNN)r1   r   r2   r   r^   r4   r_   r4   r}   r~   re   r   r6   r7   r8   rR   )r1   r   r2   r   r^   r4   r_   r4   r}   r~   r   r   r6   r7   r8   r   )
r1   r   r2   r   r   r   r6   r7   r8   r|   )rO   r   r6   r7   r8   r   rM   )D
__future__r   rV   asyncior   typingr   r   r   r   r   r	   r
   prompt_toolkit.applicationr   "prompt_toolkit.application.currentr   prompt_toolkit.bufferr   prompt_toolkit.completionr   prompt_toolkit.eventloopr   prompt_toolkit.filtersr   prompt_toolkit.formatted_textr   )prompt_toolkit.key_binding.bindings.focusr   r   #prompt_toolkit.key_binding.defaultsr   'prompt_toolkit.key_binding.key_bindingsr   r   prompt_toolkit.layoutr    prompt_toolkit.layout.containersr   r   prompt_toolkit.layout.dimensionr   ry   prompt_toolkit.stylesr   prompt_toolkit.validationr   prompt_toolkit.widgetsr   r   r    r!   r"   r#   r$   r%   r&   __all__r'   rP   r(   r)   r*   r+   r,   r-   rN   rx   r@   r@   r@   rA   <module>   s    $,5((
: