
    tni                          d Z ddlmZ ddlmZm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mZ ddlmZ ddlmZmZ d	d
gZe G d d	                      Z G d d
e          ZdS )zEContains the content control class :class:`.InquirerPyUIListControl`.    )abstractmethod)asdict	dataclass)AnyCallableDictListOptionalTuplecast)FormattedTextControl)InvalidArgumentRequiredKeyNotFound)	Separator)InquirerPyListChoicesInquirerPySessionResultChoiceInquirerPyUIListControlc                   L    e Zd ZU dZeed<   dZee         ed<   dZ	e
ed<   d ZdS )r   aR  Class to create choices for list type prompts.

    A simple dataclass that can be used as an alternate to using :class:`dict`
    when working with choices.

    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.
    valueNnameFenabledc                 J    | j         t          | j                  | _         dS dS )z-Assign strinify value to name if not present.N)r   strr   selfs    T/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/InquirerPy/base/control.py__post_init__zChoice.__post_init__"   s%    9DJDIII     )__name__
__module____qualname____doc__r   __annotations__r   r
   r   r   boolr    r   r   r   r      s^           JJJD(3-GT( ( ( ( (r   c                       e Zd ZdZ	 	 	 ddedededee         ddf
 fd	Z	de
e         dede
eeef                  fd
Zedefd            Zej        deddfd            Zede
eeef                  fd            Zej        de
eeef                  ddfd            ZddZde
eeef                  fdZddZede
eeef                  fd            Zede
eeef                  fd            Zedefd            Zedeeef         fd            Zedefd            Zej        deddfd            Z xZS )r   a  A base class to create :class:`~prompt_toolkit.layout.UIControl` to display list type contents.

    Args:
        choices(InquirerPyListChoices): List of choices to display as the content.
            Can also be a callable or async callable that returns a list of choices.
        default: Default value, this will affect the cursor position.
        multiselect: Indicate if the current prompt has `multiselect` enabled.
        session_result: Current session result.
    NFchoicesdefaultmultiselectsession_resultreturnc                 &   |pi | _         d| _        d | _        || _        t	          |t
                    s|n" t          t
          |          | j                   | _        t	          |t
                    s|n" t          t
          |          | j                   | _        | 	                    | j        | j                  | _
        |                                  |                                  t                                          | j                   d S )Nr   )_session_result_selected_choice_index_choice_func_multiselect
isinstancer   r   _default_raw_choices_get_choices_choices_safety_check_format_choicessuper__init___get_formatted_choices)r   r(   r)   r*   r+   	__class__s        r   r:   z InquirerPyUIListControl.__init__3   s      .3+,# ' gx00?GG(h(()=>> 	 gx00?GG(h(()=>> 	
 ))$*;T]KK455555r   c           	      P   g }	 t          |d          D ]q\  }}t          |t                    rc|d         |k    r|| _        |                    t          |d                   |d         | j        r|                    dd          ndd           ~t          |t                    rQ| j        |k    r| j        dz   t          |          z  | _        |                    t          |          |dd           t          |t                    rEt          |          }|d         |k    r|| _        | j        sd|d<   |                    |           >||k    r|| _        |                    t          |          |dd           sn# t          $ r t          d	          w xY w|S )
a  Process the raw user input choices and format it into dictionary.

        Args:
            choices: List of chices to display.
            default: Default value, this will affect the :attr:`.InquirerPyUIListControl.selected_choice_index`

        Returns:
            List of choices.

        Raises:
            RequiredKeyNotFound: When the provided choice is missing the `name` or `value` key.
        r   )startr   r   r   F)r   r   r      z@dictionary type of choice require a 'name' key and a 'value' key)	enumerater2   dictselected_choice_indexappendr   r1   getr   lenr   r   KeyErrorr   )r   r(   r)   processed_choicesindexchoicedict_choices          r   r5   z$InquirerPyUIListControl._get_choicesM   s    35&	!*7!!<!<!< ! !vfd++  g'115:2%,,$'v$7$7%+G_#0('vzz)U'C'C'C!&      	22 1U:: 6:LL6)2 &,,!$Vv%PP     // "(..K"7+w665:2, 716I.%,,[9999((5:2%,,!$Vv%PP   ?!D  	 	 	%R  	 ! s   FF	 	F#c                     | j         S )zint: Current highlighted index.r/   r   s    r   rB   z-InquirerPyUIListControl.selected_choice_index   s     **r   r   c                     || _         d S NrL   r   r   s     r   rB   z-InquirerPyUIListControl.selected_choice_index   s    &+###r   c                     | j         S )z0List[Dict[str, Any]]: Get all processed choices.r6   r   s    r   r(   zInquirerPyUIListControl.choices        }r   c                     || _         d S rN   rQ   rO   s     r   r(   zInquirerPyUIListControl.choices       r   c                     | j         st          d          d}| j         D ]!}t          |d         t                    sd} n"|st          d          dS )zValidate processed choices.

        Check if the choices are empty or if it only contains :class:`~InquirerPy.separator.Separator`.
        z argument choices cannot be emptyFr   Tz<argument choices should contain choices other than separatorN)r(   r   r2   r   )r   should_proceedrI   s      r   r7   z%InquirerPyUIListControl._safety_check   s    
 | 	F!"DEEE$l 	 	FfWoy99 !%  	!N  	 	r   c                    g }t          | j                  D ]V\  }}|| j        k    r||                     |          z  }n||                     |          z  }|                    d           W|r|                                 |S )zxGet all choices in formatted text format.

        Returns:
            List of choices in formatted text form.
        ) 
)r@   r(   rB   _get_hover_text_get_normal_textrC   pop)r   display_choicesrH   rI   s       r   r;   z.InquirerPyUIListControl._get_formatted_choices   s     &t|44 	/ 	/ME62224#7#7#?#??4#8#8#@#@@"":.... 	"!!!r   c                     dS )zPerform post processing on the choices.

        Additional customisation to the choices after :meth:`.InquirerPyUIListControl._get_choices` call.
        Nr&   r   s    r   r8   z'InquirerPyUIListControl._format_choices   s	    
 	r   c                     dS )z~Generate the formatted text for hovered choice.

        Returns:
            Formatted text in list of tuple format.
        Nr&   r   rI   s     r   rZ   z'InquirerPyUIListControl._get_hover_text   	     	r   c                     dS )zGenerate the formatted text for non-hovered choices.

        Returns:
            Formatted text in list of tuple format.
        Nr&   r`   s     r   r[   z(InquirerPyUIListControl._get_normal_text   ra   r   c                 *    t          | j                  S )zint: Total count of choices.)rE   r(   r   s    r   choice_countz$InquirerPyUIListControl.choice_count   s     4<   r   c                 &    | j         | j                 S )z(Dict[str, Any]: Current selected choice.)r(   rB   r   s    r   	selectionz!InquirerPyUIListControl.selection   s     |D677r   c                     | j         S )z1bool: Indicate if the content control is loading._loadingr   s    r   loadingzInquirerPyUIListControl.loading   rR   r   c                     || _         d S rN   rh   rO   s     r   rj   zInquirerPyUIListControl.loading   rT   r   )NFN)r,   N)r    r!   r"   r#   r   r   r%   r
   r   r:   r	   r   r   r5   propertyintrB   setterr(   r7   r   r;   r8   r   rZ   r[   rd   rf   rj   __classcell__)r<   s   @r   r   r   (   s         !<@6 6&6 6 	6
 !!896 
6 6 6 6 6 645!DI 5! 5!T#s(^@T 5! 5! 5! 5!n +s + + + X+ !,3 ,4 , , , "!, d38n-    X ^T$sCx.1 d    ^   "U38_(=    $    eCHo)>    ^ $uS#X*?    ^ !c ! ! ! X! 84S> 8 8 8 X8     X ^T d    ^    r   N)r#   abcr   dataclassesr   r   typingr   r   r   r	   r
   r   r   prompt_toolkit.layout.controlsr   InquirerPy.exceptionsr   r   InquirerPy.separatorr   InquirerPy.utilsr   r   __all__r   r   r&   r   r   <module>rx      s=   K K       ) ) ) ) ) ) ) ) C C C C C C C C C C C C C C C C C C ? ? ? ? ? ? F F F F F F F F * * * * * * K K K K K K K K.
/ ( ( ( ( ( ( ( (0{ { { { {2 { { { { {r   