
    tni =                     x   d Z ddlZddlmZ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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 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.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 erddl6m7Z7 dgZ8 G d de          Z9 G d de"          Z:dS )z2Module contains the class to create a list prompt.    N)TYPE_CHECKINGAnyCallableListOptionalTupleUnion)Application)IsDone)ConditionalContainerFloatContainerHSplitWindow)DummyControl)	Dimension)Layout)ValidationError)Frame)InquirerPyUIListControl)FakeDocument)BaseListPrompt)InstructionWindow)MessageWindow)ValidationFloat)INQUIRERPY_POINTER_SEQUENCE)	Separator)InquirerPyDefaultInquirerPyKeybindingsInquirerPyListChoicesInquirerPyMessageInquirerPySessionResultInquirerPyStyleInquirerPyValidatecalculate_height)KeyPressEvent
ListPromptc                        e Zd ZdZdededededee         de	ded	d
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 )InquirerPyListControlzAn :class:`~prompt_toolkit.layout.UIControl` class that displays a list of choices.

    Reference the parameter definition in :class:`.ListPrompt`.
    choicesdefaultpointermarkersession_resultmultiselect	marker_plreturnNc                 |    || _         || _        || _        t                                          ||||           d S )N)r)   r*   r-   r.   )_pointer_marker
_marker_plsuper__init__)	selfr)   r*   r+   r,   r-   r.   r/   	__class__s	           T/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/InquirerPy/prompts/list.pyr6   zInquirerPyListControl.__init__2   sQ     %"()#	 	 	
 	
 	
 	
 	
    c                     g }|                     d| j        f           |                     d|d         r| j        n| j        f           |                     d           |                     d|d         f           |S )Nzclass:pointerclass:markerenabledz[SetCursorPosition] name)appendr2   r3   r4   r7   choicedisplay_choicess      r9   _get_hover_textz%InquirerPyListControl._get_hover_textF   s    ?@@@ &y 1Ft	
 	
 	
 	:;;;@AAAr:   c                 d   g }|                     dt          | j                  dz  f           |                     d|d         r| j        n| j        f           t          |d         t                    s|                     d|d         f           n|                     d|d         f           |S )Nr?    r<   r=   valuer@   zclass:separator)rA   lenr2   r3   r4   
isinstancer   rB   s      r9   _get_normal_textz&InquirerPyListControl._get_normal_textS   s    C$6$6$<=>>> &y 1Ft	
 	
 	
 &/955 	H""Bv#78888""$5vf~#FGGGr:   )__name__
__module____qualname____doc__r   r   strr   r!   boolr6   r   r   rE   rK   __classcell__r8   s   @r9   r(   r(   ,   s         

&
 
 	

 
 !!89
 
 
 

 
 
 
 
 
(eCHo)>    $uS#X*?        r:   r(   c            ;           e Zd ZdZddddde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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&eeeef                  fd(Zd2d)Zd3d*ee
         d&dfd+Zd2 fd,Zd2 fd-Zd4d0Zed&efd1            Z xZS )5r&   uO  Create a prompt that displays a list of choices to select.

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

    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/dynamic: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.
            Refer to :ref:`pages/dynamic:default` documentation for more details.
        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.select(message="Select one:", choices=[1, 2, 3]).execute()
        >>> print(result)
        1
    NF?r?   rG   zInvalid inputTzMandatory promptmessager)   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-   r0   c                 F   t          | d          st          |||||||          | _        t                                          |||||||	|
||||||||||||           || _        t          ||| j                  \  | _        | _	        t          | j        t          | j	        | j                  d          }| j        rt          |          }t          t          t!          | j        r| j        n| j        d| j        | j                  t)          |t+                       	          t)          t          t-                      
          t+                       | j        z  	          t1          | j        t+                       | j        z  | j                  g          t5          | j        | j        t+                       z  | j        d| j                  g          | _        t?          tA          | j                  | j!        | j"        | j#                  | _$        d S )N_content_control)r)   r*   r+   r,   r-   r.   r/   )rV   rW   ra   rX   rY   rZ   r[   r\   r]   r^   rb   rc   r.   rd   rf   rg   rh   ri   rj   r-   )height_offset)max	preferredT)contentr_   dont_extend_height)rV   r^   rg   re   )r^   )rp   )rV   r^   rg   r   )rc   r^   rg   leftbottom)rp   floats)layoutrW   key_bindingsafter_render)%hasattrr(   content_controlr5   r6   _show_cursorr$   rm   _dimmension_height_dimmension_max_heightr   r   _borderr   r   r   r   _get_prompt_message_with_cursor_get_prompt_message_wrap_linesr   r   r   _is_displaying_long_instructionr   _long_instructionr   _get_error_message_is_invalid _validation_window_bottom_offset_layoutr
   r   _style_kb_after_renderapplication)r7   rV   r)   r*   rW   rX   rY   rZ   r+   r[   r\   r]   r^   r_   r`   r.   r,   r/   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   r-   main_content_windowr8   s                                 r9   r6   zListPrompt.__init__   s   > t/00 		#8-'#$ $ $D  	#-#+##!%=/)) 	 	
 	
 	
, (?OJd.@@
 @
 @
<!< %(/1    $
 
 
 < 	="'(;"<"<%!,!6 D D!5##'#3$($5   ))<fhhYOOO(|~~666 &y4+OO   & $ 6 &y4+OO#'#3   .  $($;+vxxi7#/@  / 
  
  
D '$,''++	
 
 
r:   c                     |                                  }|                    d           |                    d           |S )zObtain the prompt message to display and display cursor behind the message.

        This ensures that cursor is always at the end of the window.
        r>   )r?   rG   )r   rA   )r7   rV   s     r9   r~   z*ListPrompt._get_prompt_message_with_cursor  s?    
 **,,2333y!!!r:   c                 X    | j         sdS | j        j        d          | j        j        d<   dS )z*Toggle the `enabled` status of the choice.Nr=   )_multiselectry   	selection)r7   _s     r9   _handle_toggle_choicez ListPrompt._handle_toggle_choice&  s;      	F8<8L8V9
 5
&y111r:   rH   c                     | j         sdS | j        j        D ].}t          |d         t                    r|r|n|d          |d<   /dS )ziToggle all choice `enabled` status.

        Args:
            value: Sepcify a value to toggle.
        NrH   r=   )r   ry   r)   rJ   r   )r7   r   rH   rC   s       r9   _handle_toggle_allzListPrompt._handle_toggle_all.  sn       	F*2 	J 	JF&/955 ). Iy8I4IF9	J 	Jr:   c                     	 t                                          |          }t          | j        j        d         t
                    sdS |r| j        s|                     |           dS i)z.Handle the event when user attempt to move up.TrH   N)r5   
_handle_uprJ   ry   r   r   _cycle_handle_downr7   eventcapr8   s      r9   r   zListPrompt._handle_up;  sp    	''$$U++Cd2<WEyQQ  t{ %%e,,,E	r:   c                     	 t                                          |          }t          | j        j        d         t
                    sdS |r| j        s|                     |           dS i)z0Handle the event when user attempt to move down.TrH   N)r5   r   rJ   ry   r   r   r   r   r   s      r9   r   zListPrompt._handle_downF  sn    	''&&u--Cd2<WEyQQ  t{ OOE***E	r:   r   r%   c                    	 t          | j                  }| j                            |           d| j        d<   | j        rP| j        sI| j        j        d         g| j        d<   |j	        
                    | j        j        d         g           dS | j        | j        d<   |j	        
                    | j                   dS # t          $ r-}|                     t          |                     Y d}~dS d}~ww xY w)aB  Handle the event when user hit `enter` key.

        1. Set the prompt state to answered.
        2. Set the result to the name of the selected choices.
        3. Exit the app with the value of the selected choices.

        In multiselect scenario, if nothing is selected, return the current highlighted choice.
        Tansweredr@   resultrH   )r   N)r   result_value
_validatorrb   statusr   selected_choicesry   r   appexitresult_namer   
_set_errorrP   )r7   r   fake_documentes       r9   _handle_enterzListPrompt._handle_enterQ  s   	9():;;MO$$]333 '+DK
#  9)> 9)-)=)G)O(PH%	t';'Eg'N&OPPPPP(,(8H%	d&788888  	$ 	$ 	$OOCFF#########	$s   .C 
C9"C44C9c                 ^    | j         sdnd}t          j                    \  }}| j        |z   |z  S )z~int: Get extra lines created for message caused by line wrapping.

        Overriding it to count the cursor as well.
        r   )rz   shutilget_terminal_sizetotal_message_length)r7   cursor_offset
term_widthr   s       r9   extra_message_line_countz#ListPrompt.extra_message_line_counth  s:     #'"3:022
A)M9jHHr:   )r0   N)N)r   r%   r0   N)rL   rM   rN   rO   r   r    r   r   r   r"   rQ   rP   r   r   r	   intr#   r   r!   r6   r   r   r~   r   r   r   r   r   propertyr   rR   rS   s   @r9   r&   r&   c   s!       > >H &*+/2 "6:15,004!115.7; )-!3<@;v
 v
"v
 'v
 #	v

 (v
 v
 v
 v
 v
 v
 v
 hucz23v
 3%*-.v
 sCx)v
 U38_-v
  !v
" #v
$ %v
& 'v
( -.)v
* +v
, 34-v
. /v
0 1v
2 3v
4 #'5v
6 7v
8 9v
: !!89;v
< 
=v
 v
 v
 v
 v
 v
peCHo1F    
 
 
 
J J8D> JT J J J J	 	 	 	 	 		 	 	 	 	 	9 9 9 9. I# I I I XI I I I Ir:   );rO   r   typingr   r   r   r   r   r   r	   &prompt_toolkit.application.applicationr
   prompt_toolkit.filters.clir    prompt_toolkit.layout.containersr   r   r   r   prompt_toolkit.layout.controlsr   prompt_toolkit.layout.dimensionr   prompt_toolkit.layout.layoutr   prompt_toolkit.validationr   prompt_toolkit.widgets.baser   InquirerPy.baser   InquirerPy.base.complexr   InquirerPy.base.listr   !InquirerPy.containers.instructionr   InquirerPy.containers.messager    InquirerPy.containers.validationr   InquirerPy.enumr   InquirerPy.separatorr   InquirerPy.utilsr   r   r   r    r!   r"   r#   r$   (prompt_toolkit.key_binding.key_processorr%   __all__r(   r&    r:   r9   <module>r      s   8 8  M M M M M M M M M M M M M M M M M M > > > > > > - - - - - -            8 7 7 7 7 7 5 5 5 5 5 5 / / / / / / 5 5 5 5 5 5 - - - - - - 3 3 3 3 3 3 0 0 0 0 0 0 / / / / / / ? ? ? ? ? ? 7 7 7 7 7 7 < < < < < < 7 7 7 7 7 7 * * * * * *	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  GFFFFFF.4 4 4 4 43 4 4 4nMI MI MI MI MI MI MI MI MI MIr:   