
    tni-1                         d Z ddlmZmZmZmZmZ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mZmZmZmZmZmZ d	gZ G d
 de	          Z G d d	e          ZdS )z5Module contains the class to create a rawlist prompt.    )AnyCallableListOptionalTupleUnion)InquirerPyUIListControl)INQUIRERPY_POINTER_SEQUENCE)InvalidArgument)
ListPrompt)	Separator)InquirerPyDefaultInquirerPyKeybindingsInquirerPyListChoicesInquirerPyMessageInquirerPySessionResultInquirerPyStyleInquirerPyValidateRawlistPromptc                        e Zd ZdZ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dZd
eeeef                  fdZ xZS )InquirerPyRawlistControlzAn :class:`~prompt_toolkit.layout.UIControl` class that displays a list of choices.

    Reference the parameter definition in :class:`.RawlistPrompt`.
    choicesdefaultpointer	separatormarkersession_resultmultiselect	marker_plreturnNc	                     || _         || _        || _        || _        t	                                          ||||           d S )N)r   r   r   r   )_pointer
_separator_marker
_marker_plsuper__init__)
selfr   r   r   r   r   r   r   r   	__class__s
            W/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/InquirerPy/prompts/rawlist.pyr'   z!InquirerPyRawlistControl.__init__   sX      ##)#	 	 	
 	
 	
 	
 	
    c                     d}t          | j                  D ]6\  }}t          |d         t                    r|dz  }&|dz   |z
  |d<   ||d<   7| j        rd}t          | j        |         d         t                    r+|dz  }t          | j        |         d         t                    +| j        |k    rI| j        D ]C}t          |d         t                    r|d         | j        k    r|d         | _         d S @d S d S d S )Nr   value   display_indexactual_index)	enumerater   
isinstancer   selected_choice_index_default)r(   separator_countindexchoicefirst_valid_choice_indexs        r*   _format_choicesz(InquirerPyRawlistControl._format_choices2   sR   &t|44 	+ 	+ME6&/955 1$&+ai/&AF?#%*F>""< 	'($56w?  . )A-( 56w?  . )-EEE"l  F!&/9== ! o.$-??5;N5K2 @	 	 FE r+   c                    g }|                     d| j        f           |                     d|d         r| j        n| j        f           t	          |d         t
                    s3|                     dt          |d                   | j        f           |                     d           |                     d|d         f           |S )Nzclass:pointerclass:markerenabledr-   r/   )z[SetCursorPosition] name)appendr"   r$   r%   r2   r   strr#   r(   r7   display_choicess      r*   _get_hover_textz(InquirerPyRawlistControl._get_hover_textI   s    ?@@@ &y 1Ft	
 	
 	
 &/955 	""#!&"9:::DOOL   	:;;;@AAAr+   c                    g }|                     dt          | j                  dz  f           |                     d|d         r| j        n| j        f           t          |d         t                    sQ|                     dt          |d                   | j        f           |                     d|d         f           n|                     d|d         f           |S )	Nr=    r;   r<   r-   r/   r>   zclass:separator)	r?   lenr"   r$   r%   r2   r   r@   r#   rA   s      r*   _get_normal_textz)InquirerPyRawlistControl._get_normal_text]   s    C$6$6$<=>>> &y 1Ft	
 	
 	
 &/955 	H""s6/#:;;;T__MN   ""Bv#78888""$5vf~#FGGGr+   r    N)__name__
__module____qualname____doc__r   r   r@   r   r   boolr'   r9   r   r   rC   rG   __classcell__r)   s   @r*   r   r      s	        

&
 
 	

 
 
 !!89
 
 
 

 
 
 
 
 
,   .eCHo)>    ($uS#X*?        r+   r   c            =           e Zd ZdZddddddd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de	e
         deded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f< fd)Zd,d*Zd(eeeef                  f fd+Z xZS )-r   u	  Create a prompt that displays a list of choices with index number as shortcuts.

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

    Each choice will have an index number infront of them with keybinding created for that index number.
    Enables user to use number to jump to different choices using number.

    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/rawlist: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 be the value of one of the choices.
            For :class:`.RawlistPrompt` specifically, default value can also be value between 0-9.
            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.
        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.rawlist(message="Select one:", choices=[1, 2, 3]).execute()
        >>> print(result)
        1
    Nz) F?rE   r=   zInvalid inputTzMandatory promptmessager   r   r   stylevi_modeqmarkamarkr   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                                          ||||||||
||||||||||||||||           d S )N)r   r   r   r   r   r   r   r   )rR   r   rS   r]   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r   r^   r_   r`   ra   rb   rc   rd   re   rf   r   )r   content_controlr&   r'   )r(   rR   r   r   r   rS   rT   rU   rV   r   rW   rX   rY   rZ   r[   r\   r   r   r   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   r   r)   s                                 r*   r'   zRawlistPrompt.__init__   s    @  8)#	 
 	 
 	 
 	#-#!#+##!%=/)1 	 	
 	
 	
 	
 	
r+   c                       fd} j         j        dk    rt          d           j         j        D ](}t	          |d         t
                    s ||           )dS )a  Override this method to apply custom keybindings.

        Needs to creat these kb in the callback due to `after_render`
        retrieve the choices asynchronously.

        Check if fetched choices exceed the limit of 9, raise
        InvalidArgument exception.
        c                 t                          t           d                             d fd            }|S )Nr/   r    c                 F    t          d                   j        _        d S )Nr0   )intrh   r3   )_r7   r(   s    r*   
keybindingzJRawlistPrompt._on_rendered.<locals>.keybinding_factory.<locals>.keybinding  s!    =@AW=X=X$:::r+   rH   )register_kbr@   )r7   rn   r(   s   ` r*   keybinding_factoryz6RawlistPrompt._on_rendered.<locals>.keybinding_factory  s\    c&"9::;;Y Y Y Y Y Y <;Y r+   
   z2rawlist argument choices cannot exceed length of 9r-   N)rh   choice_countr   r   r2   r   )r(   rm   rp   r7   s   `   r*   _on_renderedzRawlistPrompt._on_rendered   s    	 	 	 	 	 ,22!"VWWW*2 	+ 	+FfWoy99 +""6***	+ 	+r+   c                     t                                                      }| j        d         s@| j        j        r4|                    dt          | 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statusrh   r   r?   r@   	selection)r(   display_messager)   s     r*   rv   z!RawlistPrompt._get_prompt_message  sq    
  ''5577{:& 	4+?+G 	""D$8$B?$S T TU   r+   rH   )rI   rJ   rK   rL   r
   r   r   r   r@   r   r   rM   r   r   r   rl   r   r   r   r'   rs   r   r   rv   rN   rO   s   @r*   r   r   p   s       C CR &*+/ "6:15,004!115.7; )-!3<@=C
 C
"C
 'C
 #	C

 C
 (C
 C
 C
 C
 C
 C
 C
 hucz23C
 3%*-.C
 sCx)C
  U38_-!C
" #C
$ %C
& 'C
( )C
* -.+C
, -C
. 34/C
0 1C
2 3C
4 5C
6 #'7C
8 9C
: ;C
< !!89=C
> 
?C
 C
 C
 C
 C
 C
J+ + + +0
T%S/%: 
 
 
 
 
 
 
 
 
 
r+   N)rL   typingr   r   r   r   r   r   InquirerPy.baser	   InquirerPy.enumr
   InquirerPy.exceptionsr   InquirerPy.prompts.listr   InquirerPy.separatorr   InquirerPy.utilsr   r   r   r   r   r   r   __all__r   r    r+   r*   <module>r      sk   ; ; > > > > > > > > > > > > > > > > 3 3 3 3 3 3 7 7 7 7 7 7 1 1 1 1 1 1 . . . . . . * * * * * *                  
W W W W W6 W W Wtm m m m mJ m m m m mr+   