o
    i,-                  !   @   s  d dl 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 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d eeddddddddfde$dee	e$eee$ef f  dee$ d eee$ ge	e%e$f f d!e$d"ee$ d#ee d$ee	e$eee$ef f  d%e%d&e%d'e%d(e	e$e%df d)ee$ d*e%d+ed,e!f d-d.Z&dS )/    N)Any)Callable)Dict)List)Optional)Sequence)Tuple)Union)Application)FormattedText)KeyBindings)Keys)Style)utils)DEFAULT_QUESTION_PREFIX)DEFAULT_SELECTED_POINTER)INVALID_INPUT)common)Choice)InquirerControl)	Separator)Question)merge_styles_defaultc                 C      dS )NT )ar   r   P/home/ubuntu/.local/lib/python3.10/site-packages/questionary/prompts/checkbox.py<lambda>!       r   TFmessagechoicesdefaultvalidateqmarkpointerstyleinitial_choiceuse_arrow_keysuse_jk_keysuse_emacs_keysuse_search_filterinstructionshow_descriptionkwargsreturnc                    s  |s
|	s
|
s
t d|	rrt dttdg|g}ts#t dt|||||ddttttf  ffdd}dtt ffd	d
 dtt dt	ffddt
j|fi |}t }|jtjdd|jtjdddd }|jddd fdd}|jrtjnddd fdd}|jrtjnddd fdd}fdd}fdd}rfdd }tjD ]}|tjv rq|j|dd| q|jtjdd| |r|jtjdd| |jtjdd| |	r|jd!dd| |jd"dd| |
r%|jtjdd| |jtjdd| |jtjdd fd#d$}|tjd%d& }ttd)|||d't|tj S )*u  Ask the user to select from a list of items.

    This is a multiselect, the user can choose one, none or many of the
    items.

    Example:
        >>> import questionary
        >>> questionary.checkbox(
        ...    'Select toppings',
        ...    choices=[
        ...        "Cheese",
        ...        "Tomato",
        ...        "Pineapple",
        ...    ]).ask()
        ? Select toppings done (2 selections)
        ['Cheese', 'Pineapple']

    .. image:: ../images/checkbox.gif

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


    Args:
        message: Question text

        choices: Items shown in the selection, this can contain :class:`Choice` or
                 or :class:`Separator` objects or simple items as strings. Passing
                 :class:`Choice` objects, allows you to configure the item more
                 (e.g. preselecting it or disabling it).

        default: Default return value (single value). If you want to preselect
                 multiple items, use ``Choice("foo", checked=True)`` instead.

        validate: Require the entered value to pass a validation. The
                  value can not be submitted until the validator accepts
                  it (e.g. to check minimum password length).

                  This should be a function accepting the input and
                  returning a boolean. Alternatively, the return value
                  may be a string (indicating failure), which contains
                  the error message to be displayed.

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

        pointer: Pointer symbol in front of the currently highlighted element.
                 By default this is a ``»``.
                 Use ``None`` to disable it.

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

        initial_choice: A value corresponding to a selectable item in the choices,
                        to initially set the pointer position to.

        use_arrow_keys: Allow the user to select items from the list using
                        arrow keys.

        use_jk_keys: Allow the user to select items from the list using
                     `j` (down) and `k` (up) keys.

        use_emacs_keys: Allow the user to select items from the list using
                        `Ctrl+N` (down) and `Ctrl+P` (up) keys.

        use_search_filter: Flag to enable search filtering. Typing some string will
                           filter the choices to keep only the ones that contain the
                           search string.
                           Note that activating this option disables "vi-like"
                           navigation as "j" and "k" can be part of a prefix and
                           therefore cannot be used for navigation

        instruction: A message describing how to navigate the menu.

        show_description: Display description of current selection if available.

    Returns:
        :class:`Question`: Question instance, ready to be prompted (using ``.ask()``).
    zOSome option to move the selection is required. Arrow keys or j/k or Emacs keys.zSCannot use j/k keys with prefix filter search, since j/k can be part of the prefix.)zbottom-toolbar	noreversezvalidate must be callable)r$   r&   r,   r.   c               
      s*  g } |  df |  ddf  jrit j}|dkr&|  d | S |dkr]t  d jtrL  d j}|  dd	d	d
 |D f | S |  dd  d jf | S |  dd|f | S d urv|  df | S |  ddr~dnd drdnd drdnd df | S )Nzclass:qmarkzclass:questionz {} r   )class:answerdone   r0    c                 S   s   g | ]}|d  qS )r2   r   ).0tokenr   r   r   
<listcomp>   s    z7checkbox.<locals>.get_prompt_tokens.<locals>.<listcomp>z[{}]zdone ({} selections)zclass:instructionz-(Use arrow keys to move, <space> to select, <zctrl-ar   z> to toggle, <iz> to invertz, type to filter))
appendformatis_answeredlenselected_options
isinstanceget_selected_valuestitlelistjoin)tokensnbr_selectedts)icr+   r   r#   r*   r   r   get_prompt_tokens   sT   

#



z#checkbox.<locals>.get_prompt_tokensc                      s   dd    D S )Nc                 S   s   g | ]}|j qS r   )valuer4   cr   r   r   r6      s    z9checkbox.<locals>.get_selected_values.<locals>.<listcomp>)r?   r   rF   r   r   r?      s   z%checkbox.<locals>.get_selected_valuesselected_valuesc                    sV   | }|du }|s|du rt }nt|}td|fg}|s& jr&| _|S d  _|S )NTFzclass:validation-toolbar)r   strr   submission_attemptederror_message)rL   verdictvalid
error_textrO   )rF   r"   r   r   perform_validation   s   z$checkbox.<locals>.perform_validationT)eagerc                 S   s   | j jtdd d S )Nzclass:aborting)	exceptionr%   )appexitKeyboardInterrupteventr   r   r   _   s   zcheckbox.<locals>._ c                    s<     j}|jv rj| nj|    d S N)get_pointed_atrH   r=   remover9   )_eventpointed_choicer?   rF   rS   r   r   toggle   s
   

zcheckbox.<locals>.toggler7   c                    s(   fddj D }|_   d S )Nc                    s.   g | ]}t |ts|j jvr|js|jqS r   )r>   r   rH   r=   disabledrI   rK   r   r   r6      s    z,checkbox.<locals>.invert.<locals>.<listcomp>)r    r=   )r`   inverted_selectionrb   r   r   invert   s
   
zcheckbox.<locals>.invertr   c                    sV   d}j D ]}t|ts|jjvr|jsj|j d}q|r$g _   d S )NTF)r    r>   r   rH   r=   rd   r9   )r`   all_selectedrJ   rb   r   r   all  s   
zcheckbox.<locals>.allc                    (         s      rd S d S r]   )select_nextis_selection_validrY   rK   r   r   move_cursor_down     z"checkbox.<locals>.move_cursor_downc                    ri   r]   )select_previousrk   rY   rK   r   r   move_cursor_up  rm   z checkbox.<locals>.move_cursor_upc                    s     | jd j d S )Nr   )add_search_characterkey_sequencekeyrY   rK   r   r   search_filter  s   zcheckbox.<locals>.search_filterjkc                    s0     }d_ |rd_| jj|d d S d S )NT)result)rN   r;   rV   rW   )rZ   rL   rb   r   r   
set_answer3  s   zcheckbox.<locals>.set_answerc                 S   r   )zDisallow inserting other text.Nr   )r`   r   r   r   other<  r   zcheckbox.<locals>.other)layoutkey_bindingsr%   Nr   )!
ValueErrorr   r   callabler   r   r   rM   r   boolr   create_inquirer_layoutr   addr   ControlQControlCControlIControlAstring	printable
whitespace	BackspaceDownUpControlNControlPControlMr   r
   r   used_kwargs__init__)r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   merged_stylerG   ry   bindingsr[   rc   rf   rh   rl   ro   rs   	characterrw   rx   r   )r?   rF   r+   r   rS   r#   r*   r"   r   checkbox   s   a
&.	



r   )'r   typingr   r   r   r   r   r   r   r	   prompt_toolkit.applicationr
   prompt_toolkit.formatted_textr   prompt_toolkit.key_bindingr   prompt_toolkit.keysr   prompt_toolkit.stylesr   questionaryr   questionary.constantsr   r   r   questionary.promptsr   questionary.prompts.commonr   r   r   questionary.questionr   questionary.stylesr   rM   r}   r   r   r   r   r   <module>   s    	
