o
    i                     @   s   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 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edddfdedededee dedee dedefddZdS )    )Any)Optional)PromptSession)to_formatted_text)KeyBindings)Keys)Style)DEFAULT_QUESTION_PREFIX)NO)	NO_OR_YES)YES)	YES_OR_NO)Question)merge_styles_defaultTNmessagedefaultqmarkstyle
auto_enterinstructionkwargsreturnc                    s  t |g}dddfdd}fddt }	|	jtjdd	|	jtjdd	d
d }
|	d|	d fdd}|	d|	d fdd}|	tjfdd}|	jtjdd	fdd}|	tjdd }t	t
|f|	|d|jS )a:  A yes or no question. The user can either confirm or deny.

    This question type can be used to prompt the user for a confirmation
    of a yes-or-no question. If the user just hits enter, the default
    value will be returned.

    Example:
        >>> import questionary
        >>> questionary.confirm("Are you amazed?").ask()
        ? Are you amazed? Yes
        True

    .. image:: ../images/confirm.gif

    This is just a really basic example, the prompt can be customised using the
    parameters.


    Args:
        message: Question text.

        default: Default value will be returned if the user just hits
                 enter.

        qmark: Question prefix displayed in front of the question.
               By default this is a ``?``.

        style: A custom color and style for the question parts. You can
               configure colors as well as font types for different elements.

        auto_enter: If set to `False`, the user needs to press the 'enter' key to
            accept their answer. If set to `True`, a valid input will be
            accepted without the need to press 'Enter'.

        instruction: A message describing how to proceed through the
                     confirmation prompt.
    Returns:
        :class:`Question`: Question instance, ready to be prompted (using `.ask()`).
    NF)answercompletec                     s   g } |  df |  ddf d ur|  df nd s3 r'tnt}|  dd|f d d urHd r?tnt}|  d|f t| S )	Nzclass:qmarkzclass:questionz {} zclass:instructionr   z{} r   zclass:answer)appendformatr   r   r   r
   r   )tokens_instructionr   )r   r   r   r   status O/home/ubuntu/.local/lib/python3.10/site-packages/questionary/prompts/confirm.pyget_prompt_tokensG   s   z"confirm.<locals>.get_prompt_tokensc                    s   d d< | j j d d d S )NTr   r   )result)appexiteventr   r   r    exit_with_resultY   s   z!confirm.<locals>.exit_with_resultT)eagerc                 S   s   | j jtdd d S )Nzclass:aborting)	exceptionr   )r#   r$   KeyboardInterruptr%   r   r   r    __   s   zconfirm.<locals>._nNc                       dd<  r|  d S d S )NFr   r   r%   r   r(   r   r   r    key_nd      zconfirm.<locals>.key_nyYc                    r/   )NTr   r   r%   r0   r   r    key_yk   r2   zconfirm.<locals>.key_yc                    s   d  d< d S Nr   r   r%   r'   r   r    key_backspacer   s   zconfirm.<locals>.key_backspacec                    s    d d u r
 d< |  d S r6   r   r%   )r   r(   r   r   r    
set_answerv   s   zconfirm.<locals>.set_answerc                 S   s   dS )zDisallow inserting other text.Nr   r%   r   r   r    other}   s    zconfirm.<locals>.other)key_bindingsr   )r   r   addr   ControlQControlCControlHControlMr   r   r   r#   )r   r   r   r   r   r   r   merged_styler!   bindingsr,   r1   r5   r7   r8   r9   r   )r   r   r(   r   r   r   r   r    confirm   s<   
0



rB   )typingr   r   prompt_toolkitr   prompt_toolkit.formatted_textr   prompt_toolkit.key_bindingr   prompt_toolkit.keysr   prompt_toolkit.stylesr   questionary.constantsr	   r
   r   r   r   questionary.questionr   questionary.stylesr   strboolrB   r   r   r   r    <module>   sH    