
    AHjp*              #          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eeddddddddddfdedeeeeeeef   f      deeeeeeef   f      dedee   dee   dedededed ed!ed"ed#ed$ee   d%ed&ef"d'Z y)(    N)Any)Dict)Optional)Sequence)Union)Application)KeyBindings)Keys)Style)utils)DEFAULT_QUESTION_PREFIX)DEFAULT_SELECTED_POINTER)common)Choice)InquirerControl)	Separator)Question)merge_styles_defaultFTmessagechoicesdefaultqmarkpointerstyleuse_shortcutsuse_arrow_keysuse_indicatoruse_jk_keysuse_emacs_keysuse_search_filtershow_selectedshow_descriptioninstructionkwargsreturnc                     ss|	s|
st        d      |	rrt        d      r|	rt        d |D              rt        d      |t        |      dk(  rt        d      r`t        d |D              }|t        t        j
                        kD  r2t        dj                  t        t        j
                        |            t        |g      }t	        |||||||		       fd
}t        j                  |fi |}t               j                  t        j                  d      j                  t        j                  d      d               }rt        j                         D ]  \  }}|j"                  2|j$                  s&s$t'        dj                  |j(                              t+        |t,              s|j"                  |j$                  rmfd} |||j"                          fd}fd}rZfd}t.        j0                  D ]  } j                  |d      |         j                  t        j2                  d      |       rN j                  t        j4                  d      |        j                  t        j6                  d      |       |	r2 j                  dd      |        j                  dd      |       |
rN j                  t        j8                  d      |        j                  t        j:                  d      |       j                  t        j<                  d      fd       }j                  t        j>                        d        }tA        tC        d||dtE        jF                  |tB        jH                              S )u  A list of items to select **one** option from.

    The user can pick one option and confirm it (if you want to allow
    the user to select multiple options, use :meth:`questionary.checkbox` instead).

    Example:
        >>> import questionary
        >>> questionary.select(
        ...     "What do you want to do?",
        ...     choices=[
        ...         "Order a pizza",
        ...         "Make a reservation",
        ...         "Ask for opening hours"
        ...     ]).ask()
        ? What do you want to do? Order a pizza
        'Order a pizza'

    .. image:: ../images/select.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: A value corresponding to a selectable item in the choices,
                 to initially set the pointer position to.

        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.

        instruction: A hint on how to navigate the menu.
                     It's ``(Use shortcuts)`` if only ``use_shortcuts`` is set
                     to True, ``(Use arrow keys or shortcuts)`` if ``use_arrow_keys``
                     & ``use_shortcuts`` are set and ``(Use arrow keys)`` by default.

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

        use_indicator: Flag to enable the small indicator in front of the
                       list highlighting the current location of the selection
                       cursor.

        use_shortcuts: Allow the user to select items from the list using
                       shortcuts. The shortcuts will be displayed in front of
                       the list items. Arrow keys, j/k keys and shortcuts are
                       not mutually exclusive.

        use_arrow_keys: Allow the user to select items from the list using
                        arrow keys. Arrow keys, j/k keys and shortcuts are not
                        mutually exclusive.

        use_jk_keys: Allow the user to select items from the list using
                     `j` (down) and `k` (up) keys. Arrow keys, j/k keys and
                     shortcuts are not mutually exclusive.

        use_emacs_keys: Allow the user to select items from the list using
                        `Ctrl+N` (down) and `Ctrl+P` (up) keys. Arrow keys, j/k keys,
                        emacs keys and shortcuts are not mutually exclusive.

        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

        show_selected: Display current selection choice at the bottom of list.

        show_description: Display description of current selection if available.

    Returns:
        :class:`Question`: Question instance, ready to be prompted (using ``.ask()``).
    z^Some option to move the selection is required. Arrow keys, j/k keys, emacs keys, or shortcuts.zSCannot use j/k keys with prefix filter search, since j/k can be part of the prefix.c              3   :   K   | ]  }t        |d d      dv   yw)shortcut_key )jkN)getattr.0cs     R/root/tools/cai/cai_env/lib/python3.12/site-packages/questionary/prompts/select.py	<genexpr>zselect.<locals>.<genexpr>   s     Mwq."-;Ms   zqA choice is trying to register j/k as a shortcut key when they are in use as arrow keys disable one or the other.r   z'A list of choices needs to be provided.c              3   B   K   | ]  }t        |t              rd   yw)   N)
isinstancer   r-   s     r0   r1   zselect.<locals>.<genexpr>   s     !UJq)<T!!Us   zA list with shortcuts supports a maximum of {} choices as this is the maximum number of keyboard shortcuts that are available. You provided {} choices!)r   r   r   r!   r"   r   initial_choicec            
      @   dfddj                        fg} j                  rt        j                         j                  t
              rM| j                  ddj                  j                         j                  D cg c]  }|d   	 c}      f       | S | j                  dj                         j                  f       | S r| j                  df       | S 	rrdrd	nd d
}n	rsdrd	nd d
}n
drd	nd d
}| j                  d|f       | S c c}w )Nzclass:qmarkzclass:questionz {} zclass:answerr)   r3   zclass:instructionz(Use shortcuts or arrow keysz, type to filter)z(Use shortcutsz(Use arrow keys)formatis_answeredr4   get_pointed_attitlelistappendjoin)
tokenstokeninstruction_msgicr#   r   r   r   r    r   s
      r0   get_prompt_tokensz!select.<locals>.get_prompt_tokens   s;    %(+;V]]7=S*TU>>"++-33T:&r7H7H7J7P7P Qeq QR(  ~r/@/@/B/H/HIJ  2K@A  !^(D[lEWrtDuuv&wO">(6M^7Idf6ggh&iO(7N_8Jeg7hhi&jO2ODE# !Rs    DTeagerc                 F    | j                   j                  t        d       y )Nzclass:aborting)	exceptionr   )appexitKeyboardInterruptevents    r0   _zselect.<locals>._   s     			!2:JK    zc{} does not have a shortcut and arrow keys for movement are disabled. This choice is not reachable.c                 @     j                  |d       fd       }y )NTrD   c                     _         y N)
pointed_at)rL   irB   s    r0   select_choicez3select.<locals>._reg_binding.<locals>.select_choice   s
    $%BMrN   )add)rS   keysrT   bindingsrB   s   `  r0   _reg_bindingzselect.<locals>._reg_binding   s$     d$/& 0&rN   c                     j                          j                         s"j                          j                         s!y y rQ   )select_nextis_selection_validrL   rB   s    r0   move_cursor_downz select.<locals>.move_cursor_down   s1    
'')NN '')rN   c                     j                          j                         s"j                          j                         s!y y rQ   )select_previousr[   r\   s    r0   move_cursor_upzselect.<locals>.move_cursor_up   s5    
'')  '')rN   c                 V    j                  | j                  d   j                         y )Nr   )add_search_characterkey_sequencekeyr\   s    r0   search_filterzselect.<locals>.search_filter   s"    ##E$6$6q$9$=$=>rN   r*   r+   c                 |    d_         | j                  j                  j                         j                         y )NT)result)r9   rH   rI   r:   valuer\   s    r0   
set_answerzselect.<locals>.set_answer  s+    		b//1778rN   c                      y)zDisallow inserting other text.N rK   s    r0   otherzselect.<locals>.other  s    rN   )layoutkey_bindingsr   rk   )%
ValueErroranylensumr   SHORTCUT_KEYSr8   r   r   create_inquirer_layoutr	   rU   r
   ControlQControlC	enumerater   r(   disabledRuntimeErrorr;   r4   r   string	printable	BackspaceDownUpControlNControlPControlMr   r   r   r   used_kwargs__init__) r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   real_len_of_choicesmerged_stylerC   rm   rM   rS   r/   rX   r]   r`   re   	characterri   rl   rW   rB   s    `  `  ``   `  `               @@r0   selectr      s|   L m{nB
 	
 (a
 	
 MWMM,  #g,!+BCC!!UW!UU_%B%B!CC 6#o;;<>QR  (0L	###)%

B 8 **2/@KFKF}H\\$--t\,\\$--t\,L - -L bjj) 	,DAq~~%ajj"44:F177O 
 !Y'1>>+AQZZ& ANN+%	,(
!
 	?  )) 	?I/HLL$L/>	?0T^^40?+TYYd+,<=)TWWD).9%S%&67%S%n5/T]]$/0@A/T]]$/?\\$--t\,9 -9 \\$((- -  	
!	
 (<(<=		
 rN   )!rz   typingr   r   r   r   r   prompt_toolkit.applicationr   prompt_toolkit.key_bindingr	   prompt_toolkit.keysr
   prompt_toolkit.stylesr   questionaryr   questionary.constantsr   r   questionary.promptsr   questionary.prompts.commonr   r   r   questionary.questionr   questionary.stylesr   strboolr   rk   rN   r0   <module>r      se         2 2 $ '  9 : & - 6 0 ) 3 =A(5!#!!%AAeCc3h789A eCc3h789A 	A
 c]A E?A A A A A A A A A #A  !A" #ArN   