
    tniK                     @   d Z ddlmZ ddlmZmZmZmZmZm	Z	 ddl
mZ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 dd
lmZmZmZmZmZmZmZ g dZ e G d d                      Z!e G d de                      Z" G d de          Z# G d de          Z$dS )z5Module contains the class to create an expand prompt.    )	dataclass)AnyCallableListOptionalTupleUnion)BaseListPromptInquirerPyUIListControl)Choice)INQUIRERPY_POINTER_SEQUENCE)InvalidArgumentRequiredKeyNotFound)
ListPrompt)	Separator)InquirerPyDefaultInquirerPyKeybindingsInquirerPyListChoicesInquirerPyMessageInquirerPySessionResultInquirerPyStyleInquirerPyValidate)ExpandPrompt
ExpandHelpExpandChoicec                   0    e Zd ZU dZdZeed<   dZeed<   dS )r   zHelp choice for the :class:`.ExpandPrompt`.

    Args:
        key: The key to bind to toggle the expansion of the prompt.
        message: The help message.
    hkeyHelp, list all choicesmessageN)__name__
__module____qualname____doc__r   str__annotations__r         V/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/InquirerPy/prompts/expand.pyr   r      s;           CNNN+GS+++++r(   r   c                   >     e Zd ZU dZdZee         ed<    fdZ xZ	S )r   a  Choice class for :class:`.ExpandPrompt`.

    See Also:
        :class:`~InquirerPy.base.control.Choice`

    Args:
        value: The value of the choice when user selects this choice.
        name: The value that should be presented to the user prior/after selection of the choice.
            This value is optional, if not provided, it will fallback to the string representation of `value`.
        enabled: Indicates if the choice should be pre-selected.
            This only has effects when the prompt has `multiselect` enabled.
        key: Char to bind to the choice. Pressing this value will jump to the choice,
            If this value is missing, the first char of the `str(value)` will be used as the key.
    Nr   c                     t                                                       | j        3t          | j                  d                                         | _        dS dS )zdAssign stringify value to name and also create key using the first char of the value if not present.Nr   )super__post_init__r   r%   valuelower)self	__class__s    r)   r-   zExpandChoice.__post_init__8   sM    84:q)//11DHHH r(   )
r!   r"   r#   r$   r   r   r%   r&   r-   __classcell__r1   s   @r)   r   r   %   sZ           C#2 2 2 2 2 2 2 2 2r(   r   c                        e Zd ZdZdededededededed	ee	         d
e
deddf fdZddZdeeeef                  f fdZdeeeef                  fdZdeeeef                  fdZ xZS )InquirerPyExpandControlzAn :class:`~prompt_toolkit.layout.UIControl` class that displays a list of choices.

    Reference the parameter definition in :class:`.ExpandPrompt`.
    choicesdefaultpointer	separatorexpand_helpexpand_pointermarkersession_resultmultiselect	marker_plreturnNc                     || _         || _        d| _        || _        || _        |
| _        || _        t                                          ||||	           d S )NF)r6   r7   r=   r>   )	_pointer
_separator	_expanded_expand_pointer_marker
_marker_pl_expand_helpr,   __init__)r0   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r1   s              r)   rI   z InquirerPyExpandControl.__init__E   so      #-#')#	 	 	
 	
 	
 	
 	
r(   c                    i | _         	 d}d}t          | j        | j                  D ]\  }}t	          |t
                    s9t	          |t                    s$t	          |t                    st          d          t	          |t                    r|dz  }n7t	          |t                    r|j	        n|d         |d<   || j         |d         <   |dz  }n# t          $ r t          d          w xY w| j                            | j        j	        | j        | j        j        dd           t          | j                  dz
  | j         | j        j	        <   d}t	          | j        |         d         t                    r+|dz  }t	          | j        |         d         t                    +| j        |k    rQt#          | j                  D ]>\  }}t	          |d         t                    r!|d         | j        k    r
|| _         d S =d S d S )	Nr   ziexpand prompt argument choices requires each choice to be type of dictionary or Separator or ExpandChoice   r   z3expand prompt choice requires a key 'key' to existsF)r   r.   nameenabledr.   )	_key_mapszip_raw_choicesr6   
isinstancedictr   r   r   r   KeyErrorr   appendrH   r    lenselected_choice_index	enumerate_default)r0   countseparator_count
raw_choicechoicefirst_valid_choice_indexindexs          r)   _format_choicesz'InquirerPyExpandControl._format_choices`   s^   	EO&)$*;T\&J&J  "
F":t44&z9== 'z<@@
 * D   j)44 :#q(OO &j,??/
'. 5M
 5:DN6%=1
%&  	 	 	%E  	
 	(,*)1 	 	
 	
 	
 14DL0A0AA0Et(,-#$ &>?H)TT 	*$)$ &>?H)TT 	*%)AAA!*4<!8!8  vfWoy99 %=DM1116D.EE 2	 BA s   C	C C-c                     | j         r t                                                      S g }|                    d| j        f           |                    d| j        | j                 d         f           |S )zOverride this parent class method as expand require visual switch of content.

        Two types of mode:
            * non expand mode
            * expand mode
        class:pointer rL   )rD   r,   _get_formatted_choicesrT   rE   r6   rV   )r0   display_choicesr1   s     r)   rc   z.InquirerPyExpandControl._get_formatted_choices   s}     > 	7711333 O""OT5I#JKKK""T\$"<=fEF   r(   c                 ~   g }|                     d| j        f           |                     d|d         r| j        n| j        f           t	          |d         t
                    s&|                     d|d         | j        f           |                     d           |                     d|d         f           |S )Nra   class:markerrM   r.   r   )z[SetCursorPosition]rb   rL   )rT   rB   rF   rG   rQ   r   rC   r0   r\   rd   s      r)   _get_hover_textz'InquirerPyExpandControl._get_hover_text   s    ?@@@ &y 1Ft	
 	
 	
 &/955 	"" F5MM4??"KL   	:;;;@AAAr(   c                    g }|                     dt          | j                  dz  f           |                     d|d         r| j        n| j        f           t          |d         t                    sD|                     d|d         | j        f           |                     d|d         f           n|                     d|d         f           |S )	Nrb    rf   rM   r.   r   rL   zclass:separator)rT   rU   rB   rF   rG   rQ   r   rC   rg   s      r)   _get_normal_textz(InquirerPyExpandControl._get_normal_text   s    C$6$6$<=>>> &y 1Ft	
 	
 	
 &/955 	H""B&--(Q#RSSS""Bv#78888""$5vf~#FGGGr(   r@   N)r!   r"   r#   r$   r   r   r%   r   r   r   boolrI   r_   r   r   rc   rh   rk   r2   r3   s   @r)   r5   r5   ?   sP        

&
 
 	

 
  
 
 
 !!89
 
 
 

 
 
 
 
 
60 0 0 0dU38_(=      "eCHo)>    "$uS#X*?        r(   r5   c            C       &    e Zd ZdZdddddddddd	ez  dddddddedddd
ddddddddfdedededee	         de
dedededededee         dedededeeegef                  deeegef                  deeeef                  deeeef                  de
d ed!ed"e
d#ee         d$ed%ee         d&e
d'e
d(e
d)e
d*e
d+ed,ee         d-dfB fd.Zd7d/Zd7d0Zd7d1Zed-efd2            Zd-eeeef                  f fd3Zd8d4ee
         d-dfd5Zd7 fd6Z xZS )9r   u  Create a compact prompt with the ability to expand.

    A wrapper class around :class:`~prompt_toolkit.application.Application`.

    Contains a list of chocies binded to a shortcut letter.
    The prompt can be expanded using `h` key.

    Args:
        message: The question to ask the user.
            Refer to :ref:`pages/dynamic:message` documentation for more details.
        choices: List of choices to display and select.
            Refer to :ref:`pages/prompts/expand:Choices` documentation for more details.
        style: An :class:`InquirerPyStyle` instance.
            Refer to :ref:`Style <pages/style:Alternate Syntax>` documentation for more details.
        vi_mode: Use vim keybinding for the prompt.
            Refer to :ref:`pages/kb:Keybindings` documentation for more details.
        default: Set the default value of the prompt.
            This will be used to determine which choice is highlighted (current selection),
            The default value should the value of one of the choices.
            For :class:`.ExpandPrompt` specifically, default value can also be a `choice["key"]` which is the shortcut key for the choice.
            Refer to :ref:`pages/dynamic:default` documentation for more details.
        separator: Separator symbol. Custom symbol that will be used as a separator between the choice index number and the choices.
        help_msg: This parameter is DEPRECATED. Use expand_help instead.
        expand_help: The help configuration for the prompt. Must be an instance of :class:`.ExpandHelp`.
            If this value is None, the default help key will be binded to `h` and the default help message would be
            "Help, List all choices."
        expand_pointer: Pointer symbol before prompt expansion. Custom symbol that will be displayed to indicate the prompt is not expanded.
        qmark: Question mark symbol. Custom symbol that will be displayed infront of the question before its answered.
        amark: Answer mark symbol. Custom symbol that will be displayed infront of the question after its answered.
        pointer: Pointer symbol. Customer symbol that will be used to indicate the current choice selection.
        instruction: Short instruction to display next to the question.
        long_instruction: Long instructions to display at the bottom of the prompt.
        validate: Add validation to user input.
            The main use case for this prompt would be when `multiselect` is True, you can enforce a min/max selection.
            Refer to :ref:`pages/validator:Validator` documentation for more details.
        invalid_message: Error message to display when user input is invalid.
            Refer to :ref:`pages/validator:Validator` documentation for more details.
        transformer: A function which performs additional transformation on the value that gets printed to the terminal.
            Different than `filter` parameter, this is only visual effect and won’t affect the actual value returned by :meth:`~InquirerPy.base.simple.BaseSimplePrompt.execute`.
            Refer to :ref:`pages/dynamic:transformer` documentation for more details.
        filter: A function which performs additional transformation on the result.
            This affects the actual value returned by :meth:`~InquirerPy.base.simple.BaseSimplePrompt.execute`.
            Refer to :ref:`pages/dynamic:filter` documentation for more details.
        height: Preferred height of the prompt.
            Refer to :ref:`pages/height:Height` documentation for more details.
        max_height: Max height of the prompt.
            Refer to :ref:`pages/height:Height` documentation for more details.
        multiselect: Enable multi-selection on choices.
            You can use `validate` parameter to control min/max selections.
            Setting to True will also change the result from a single value to a list of values.
        marker: Marker Symbol. Custom symbol to indicate if a choice is selected.
            This will take effects when `multiselect` is True.
        marker_pl: Marker place holder when the choice is not selected.
            This is empty space by default.
        border: Create border around the choice window.
        keybindings: Customise the builtin keybindings.
            Refer to :ref:`pages/kb:Keybindings` for more details.
        show_cursor: Display cursor at the end of the prompt.
            Set to False to hide the cursor.
        cycle: Return to top item if hit bottom during navigation or vice versa.
        wrap_lines: Soft wrap question lines when question exceeds the terminal width.
        raise_keyboard_interrupt: Raise the :class:`KeyboardInterrupt` exception when `ctrl-c` is pressed. If false, the result
            will be `None` and the question is skiped.
        mandatory: Indicate if the prompt is mandatory. If True, then the question cannot be skipped.
        mandatory_message: Error message to show when user attempts to skip mandatory prompt.
        session_result: Used internally for :ref:`index:Classic Syntax (PyInquirer)`.

    Examples:
        >>> from InquirerPy import inquirer
        >>> result = inquirer.expand(message="Select one:", choices[{"name": "1", "value": "1", "key": "a"}]).execute()
        >>> print(result)
        "1"
    rb   NF?rj   z) r   z%s zInvalid inputTzMandatory promptr    r6   r7   stylevi_modeqmarkamarkr8   r9   help_msgr:   r;   instructionlong_instructiontransformerfilterheight
max_heightr>   r<   r?   bordervalidateinvalid_messagekeybindingsshow_cursorcycle
wrap_linesraise_keyboard_interrupt	mandatorymandatory_messager=   r@   c!                     |t          |
          }|| _        t          ||||	||||| |
  
        | _        t	                                          ||||||||||||||||||||||||            d S )N)r    )
r6   r7   r8   r9   r:   r;   r<   r?   r=   r>   )r    r6   rp   r{   rq   rr   rs   ru   rv   rw   rx   ry   rz   r|   r}   r>   r~   r   r   r   r   r   r   r=   )r   rH   r5   content_controlr,   rI   )"r0   r    r6   r7   rp   rq   rr   rs   r8   r9   rt   r:   r;   ru   rv   rw   rx   ry   rz   r>   r<   r?   r{   r|   r}   r~   r   r   r   r   r   r   r=   r1   s"                                    r)   rI   zExpandPrompt.__init__  s    F $X666K'8O#))#9
 9
 9
 	#-#!+###!%=/)1 	 	
 	
 	
 	
 	
r(   c                       fd} j         j        D ].}t          |d         t                    s ||d                    /dS )zOverride this method to apply custom keybindings.

        Needs to creat these kb in the callback due to `after_render`
        retrieve the choices asynchronously.
        c                 r                                                                     d fd            }|S )Nr@   c                     j         j        k    rj        j         j        _        d S j        j                 j        _        d S N)rH   r   r   rD   rN   rV   )_r   r0   s    r)   
keybindingzIExpandPrompt._on_rendered.<locals>.keybinding_factory.<locals>.keybindinge  sO    $+///9=9M9W5WD(222 ,6s; (>>>r(   rl   )register_kbr/   )r   r   r0   s   ` r)   keybinding_factoryz5ExpandPrompt._on_rendered.<locals>.keybinding_factoryd  sP    ciikk**      +* r(   r.   r   N)r   r6   rQ   r   )r0   r   r   r\   s   `   r)   _on_renderedzExpandPrompt._on_rendered]  si    
	 
	 
	 
	 
	 *2 	2 	2FfWoy99 2""6%=111	2 	2r(   c                 $   | j         j        sdS 	 t          j        | |          }t	          | j         j        d         t                    s't	          | j         j        d         t                    sdS |r| j        s| 	                    |           dS )zpHandle the event when user attempt to move up.

        Overriding this method to skip the help choice.
        NTr.   )
r   rD   r
   
_handle_uprQ   	selectionr   r   _cycle_handle_downr0   eventcaps      r)   r   zExpandPrompt._handle_upt  s    
 #- 	F		 +D%88C$.w7   !5!?!H*UU  t{ %%e,,,E		r(   c                    | j         j        sdS 	 t          j        | |          }t	          | j         j        d         t                    s't	          | j         j        d         t                    sdS t	          | j         j        d         t                    r| j        s| 	                    |           dS |r| j        s| 	                    |           dS )zrHandle the event when user attempt to move down.

        Overriding this method to skip the help choice.
        NTr.   )
r   rD   r
   r   rQ   r   r   r   r   r   r   s      r)   r   zExpandPrompt._handle_down  s    
 #- 	F	 -dE::C$.w7   !5!?!H*UU 4/9'BJOO		 &&& t{ OOE***E	r(   c                     | j         s4dd                    | j        j                                                  z  n| j         S )zConstruct the instruction behind the question.

        If _instruction exists, use that.

        :return: The instruction text.
        z(%s)rb   )_instructionjoinr   rN   keys)r0   s    r)   ru   zExpandPrompt.instruction  sB     $#FRWWT1;@@BBCCCC"	
r(   c                     t                                                      }| j        d         s'|                    d| j        j        d         f           |S )zReturn the formatted text to display in the prompt.

        Overriding this method to allow multiple formatted class to be displayed.
        answeredzclass:inputr   )r,   _get_prompt_messagestatusrT   r   r   )r0   display_messager1   s     r)   r   z ExpandPrompt._get_prompt_message  s\    
  ''5577{:& 	"" 4 >u EF   r(   r.   c                     | j         j        sdS | j         j        D ]I}t          |d         t                    st          |d         t
                    r9|r|n|d          |d<   JdS )zgOverride this method to ignore `ExpandHelp`.

        :param value: Specify a value to toggle.
        Nr.   rM   )r   rD   r6   rQ   r   r   )r0   r   r.   r\   s       r)   _handle_toggle_allzExpandPrompt._handle_toggle_all  s    
 #- 	F*2 	J 	JF&/955 w: :  ). Iy8I4IF9	J 	Jr(   c                 f    | j         j        sdS t                                          |           dS )z:Override this method to ignore keypress when not expanded.N)r   rD   r,   _handle_toggle_choice)r0   r   r1   s     r)   r   z"ExpandPrompt._handle_toggle_choice  s4    #- 	F%%e,,,,,r(   rl   r   ) r!   r"   r#   r$   r   r   r   r   r   r   rm   r%   r   r   r   r	   intr   r   r   rI   r   r   r   propertyru   r   r   r   r   r   r2   r3   s   @r)   r   r      sd       H H\ &(+/0,0#&AA "6:15,004!115.7; )-!3<@CK
 K
"K
 'K
 #	K

 (K
 K
 K
 K
 K
 K
 K
 j)K
 K
 K
 K
  hucz23!K
" 3%*-.#K
$ sCx)%K
& U38_-'K
( )K
* +K
, -K
. /K
0 -.1K
2 3K
4 345K
6 7K
8 9K
: ;K
< #'=K
> ?K
@ AK
B !!89CK
D 
EK
 K
 K
 K
 K
 K
Z2 2 2 2.   $   0 
S 
 
 
 X

T%S/%: 
 
 
 
 
 
J J8D> JT J J J J- - - - - - - - - -r(   r   N)%r$   dataclassesr   typingr   r   r   r   r   r	   InquirerPy.baser
   r   InquirerPy.base.controlr   InquirerPy.enumr   InquirerPy.exceptionsr   r   InquirerPy.prompts.listr   InquirerPy.separatorr   InquirerPy.utilsr   r   r   r   r   r   r   __all__r   r   r5   r   r'   r(   r)   <module>r      s   ; ; ! ! ! ! ! ! > > > > > > > > > > > > > > > > C C C C C C C C * * * * * * 7 7 7 7 7 7 F F F F F F F F . . . . . . * * * * * *                  9
8
8 	, 	, 	, 	, 	, 	, 	, 	, 2 2 2 2 26 2 2 22C C C C C5 C C CLE- E- E- E- E-: E- E- E- E- E-r(   