
    AHj,-              !          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 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,Z&y)-    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                      y)NT )as    T/root/tools/cai/cai_env/lib/python3.12/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t        d      |	rrt        d      t        t        dg      |g      }t              st        d      t	        |||||      dt
        t        t        t        f      f fd}dt
        t           ffdd	t
        t           dt        ffd
t        j                  |fi |}t               }|j                  t        j                  d      |j                  t        j                   d      d               }|j                  dd      fd       }|j                  rt        j"                  ndd      fd       }|j                  rt        j$                  ndd      fd       }fd}fd}rmfd}t&        j(                  D ].  }|t&        j*                  v r |j                  |d      |       0  |j                  t        j,                  d      |       |rN |j                  t        j.                  d      |        |j                  t        j0                  d      |       |	r2 |j                  dd      |        |j                  dd      |       |
rN |j                  t        j2                  d      |        |j                  t        j4                  d      |       |j                  t        j6                  d      fd       }|j                  t        j                        d        }t9        t;        d|||dt=        j>                  |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.   r0   c            
      >   g } | j                  df       | j                  ddj                        f       j                  rt        j                        }|dk(  r| j                  d       | S |dk(  rt        j                         d   j                  t              rRj                         d   j                  }| j                  ddj                  |D cg c]  }|d   	 c}      f       | S | j                  dd	j                  j                         d   j                        f       | S | j                  dd
j                  |      f       | S | j                  df       | S | j                  ddrdnd drdnd drdnd df       | S c c}w )Nzclass:qmarkzclass:questionz {} r   )class:answerdone   r4    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tokenicr-   r!   r%   r,   s	       r   get_prompt_tokensz#checkbox.<locals>.get_prompt_tokens   s   }e,-'w)?@A>>r223Lq 67F E "b446q9??F//1!4::BMM*GG2$>%U1X$>?> 1 MM*"MM"*@*@*B1*E*K*KL0 # #%;%B%B<%PQ"  &2K@A  +(9HsC D(9HsC;1B-K1	N	 9 %?s   Fc                  ^    j                         D  cg c]  } | j                   c} S c c} w N)r@   value)crH   s    r   r@   z%checkbox.<locals>.get_selected_values   s$    !#!7!7!9:A:::s   *selected_valuesc                      |       }|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)rN   verdictvalid
error_textrR   rH   r$   s        r   perform_validationz$checkbox.<locals>.perform_validation   sv    ?+4%*
 \
),F
+S*TUM "'2+B+BM 	  IM 	 r    T)eagerc                 F    | j                   j                  t        d       y )Nzclass:aborting)	exceptionr'   )appexitKeyboardInterrupt)events    r   _zcheckbox.<locals>._   s     			!2:JKr     c                     j                         j                  }|j                  v rj                  j                  |       nj                  j	                  |                       y rK   )get_pointed_atrL   r>   remover:   )_eventpointed_choicer@   rH   rV   s     r   togglezcheckbox.<locals>.toggle   sY    **,22R000&&~6&&~6.01r    r8   c                     j                   D cg c]B  }t        |t              s0|j                  j                  vr|j
                  s|j                  D }}|_                        y c c}w rK   )r"   r?   r   rL   r>   disabled)rc   rM   inverted_selectionr@   rH   rV   s      r   invertzcheckbox.<locals>.invert   si     ZZ
a+r222JJ	 GG
 
 1.01
s   AA.r   c                    d}j                   D ]`  }t        |t              r|j                  j                  vs-|j
                  r:j                  j                  |j                         d}b |rg _                        y )NTF)r"   r?   r   rL   r>   rg   r:   )rc   all_selectedrM   r@   rH   rV   s      r   allzcheckbox.<locals>.all  sv     	%Aq),GG2#6#66

 ##**1773$	% "$B.01r    c                     j                          j                         s"j                          j                         s!y y rK   )select_nextis_selection_validr]   rH   s    r   move_cursor_downz"checkbox.<locals>.move_cursor_down  s1    
'')NN '')r    c                     j                          j                         s"j                          j                         s!y y rK   )select_previousro   rp   s    r   move_cursor_upz checkbox.<locals>.move_cursor_up  s5    
'')  '')r    c                 V    j                  | j                  d   j                         y )Nr   )add_search_characterkey_sequencekeyrp   s    r   search_filterzcheckbox.<locals>.search_filter  s"    ##E$6$6q$9$=$=>r    jkc                 z            }d_          |      r$d_        | j                  j                  |       y y )NT)result)rQ   r<   rZ   r[   )r]   rN   r@   rH   rV   s     r   
set_answerzcheckbox.<locals>.set_answer3  s9    -/"&o.!BNIINN/N2 /r    c                      y)zDisallow inserting other text.Nr   )rc   s    r   otherzcheckbox.<locals>.other<  r   r    )layoutkey_bindingsr'   r   )!
ValueErrorr   r   callabler   r   r	   rP   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_stylerI   r   bindingsr^   re   ri   rl   rq   rt   ry   	characterr~   r   r@   rH   rV   s    `  ``      ``                @@@r   checkboxr      s@   B k^
 	

 (a
 	
 (
 234	
L H455	%)
B,tE#s(O4 , ,\;c ;DI $ $ **2/@KFKF}H\\$--t\,\\$--t\,L - -L \\#T\"2 #2 \\#4$--#T\J
2 K
2 \\#4$--#T\J2 K2 
!
 	?  )) 	?IF---/HLL$L/>	? 	1T^^40?+TYYd+,<=)TWWD).9%S%&67%S%n5/T]]$/0@A/T]]$/?\\$--t\,3 -3 \\$((- -  	
!	
 (<(<=		
 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   rP   r   r   r   r    r   <module>r      s            2 7 2 $ '  9 : / & - 6 0 ) 3 "8F(5!CG05!%!jjeCc3h789j c]j S	{E$)$445	j
 j c]j E?j U3S#X#>?@j j j j S$_-j #j j j  !jr    