
    AHj|                        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 dlmZ d dlmZ d dlmZ  G d de      Z deddddejB                  ddf	de"dee"   de"de"dee   d eee"ef      d!e#d"e#d#ed$ed%ee   d&ed'efd(Z$y))    )Any)Callable)Dict)Iterable)List)Optional)Tuple)Union)CompleteEvent)	Completer)
Completion)Document)HTML)SimpleLexer)CompleteStyle)PromptSession)Style)DEFAULT_QUESTION_PREFIX)build_validator)Question)merge_styles_defaultc                      e Zd ZU eee   eg ee   f   f   ed<   eed<   e	ee
f   ed<   eed<   	 	 	 ddeee   eg ee   f   f   dedee	ee
f      deddf
dZdee   fd	Zd
ededefdZededed
edefd       Zdededee   fdZy)WordCompleterchoices_sourceignore_casemeta_informationmatch_middleNchoicesreturnc                 D    || _         || _        |xs i | _        || _        y N)r   r   r   r   )selfr   r   r   r   s        X/root/tools/cai/cai_env/lib/python3.12/site-packages/questionary/prompts/autocomplete.py__init__zWordCompleter.__init__    s)     && 0 6B(    c                 d    t        | j                        r| j                         S | j                  S r!   )callabler   )r"   s    r#   _choiceszWordCompleter._choices,   s5     ++, !	
 $$	
r%   word_before_cursorchoicec                     | j                   r|j                         }| j                  r|j                  |      S |j	                  |      ryy)z Match index if found, -1 if not.r   )r   lowerr   find
startswith)r"   r)   r*   s      r#   _choice_matcheszWordCompleter._choice_matches3   sF     \\^F;;12212r%   indexc           	          t        d      j                  | d | | ||t        |      z    | |t        |      z   t        |              S )Nz{}<b><u>{}</u></b>{})r   formatlen)r*   r1   r)   s      r#   _display_for_choicez!WordCompleter._display_for_choice@   sR    *+226EN553'9#::;53122S[A
 	
r%   documentcomplete_eventc           	   #   f  K   | j                         }|j                  }| j                  r|j                         }|D ]p  }| j	                  ||      }|dk(  r| j
                  j                  |d      }| j                  |||      }t        |t        |       |j                  |dd       r y w)Nr,    class:answerzclass:selected)start_positiondisplaydisplay_metastyleselected_style)r(   text_before_cursorr   r-   r0   r   getr5   r   r4   formatted_text)	r"   r6   r7   r   r)   r*   r1   r=   r<   s	            r#   get_completionszWordCompleter.get_completionsH   s      --/ &88!3!9!9!; 	F(();VDE{0044VR@L..vu>PQG #F|..)$/ 	s   B/B1)TNT)__name__
__module____qualname__r
   r   strr   __annotations__boolr   r   r   r$   r   r(   intr0   staticmethodr   r5   r   r   r   rC    r%   r#   r   r      s"   $s)Xb$s)m%<<==38n$
 !59!
)tCy(2tCy="99:
) 
) #4S>2	
)
 
) 

)
(3- 
# s s  
C 
 
 
QU 
 
 2?	*	r%   r   r9   NTmessager   defaultqmark	completerr   r   r   complete_stylevalidater>   kwargsr   c           	          t        |
g      }dt        t        t        t        f      f fd}dt        t
        t        t        f      dt        t
        t        t        f      fd}t        |	      }|"|st        d      t        || ||      |      }t        |ft        d      ||||d|}|j                  j                  t        |             t        |j                         S )	a*	  Prompt the user to enter a message with autocomplete help.

    Example:
        >>> import questionary
        >>> questionary.autocomplete(
        ...    'Choose ant species',
        ...    choices=[
        ...         'Camponotus pennsylvanicus',
        ...         'Linepithema humile',
        ...         'Eciton burchellii',
        ...         "Atta colombica",
        ...         'Polyergus lucidus',
        ...         'Polyergus rufescens',
        ...    ]).ask()
        ? Choose ant species Atta colombica
        'Atta colombica'

    .. image:: ../images/autocomplete.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 contains items as strings

        default: Default return value (single value).

        qmark: Question prefix displayed in front of the question.
               By default this is a ``?``

        completer: A prompt_toolkit :class:`prompt_toolkit.completion.Completion`
                   implementation. If not set, a questionary completer implementation
                   will be used.

        meta_information: A dictionary with information/anything about choices.

        ignore_case: If true autocomplete would ignore case.

        match_middle: If true autocomplete would search in every string position
                      not only in string begin.

        complete_style: How autocomplete menu would be shown, it could be ``COLUMN``
                        ``MULTI_COLUMN`` or ``READLINE_LIKE`` from
                        :class:`prompt_toolkit.shortcuts.CompleteStyle`.

        validate: Require the entered value to pass a validation. The
                  value can not be submitted until the validator accepts
                  it (e.g. to check minimum password length).

                  This can either be a function accepting the input and
                  returning a boolean, or an class reference to a
                  subclass of the prompt toolkit Validator class.

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

    Returns:
        :class:`Question`: Question instance, ready to be prompted (using ``.ask()``).
    r   c                  2    dfddj                         fgS )Nzclass:qmarkzclass:questionz {} )r3   )rM   rO   s   r#   get_prompt_tokensz'autocomplete.<locals>.get_prompt_tokens   s"    &)96==;Q(RSSr%   metac                 X    | r'| D ]"  }t        d      j                  | |         | |<   $ | S )Nz<text>{}</text>)r   r3   )rW   keys     r#   get_meta_stylez$autocomplete.<locals>.get_meta_style   s;     F !23::49ES	F r%   z2No choices is given, you should use Text question.)r   r   r   r:   )lexerr>   rP   	validatorrQ   )r   r   r	   rG   r   r   r   r   
ValueErrorr   r   r   default_bufferresetr   r   app)rM   r   rN   rO   rP   r   r   r   rQ   rR   r>   rS   merged_stylerV   rZ   r\   ps   `  `             r#   autocompleterc   f   s    X (0LTtE#s(O4 TXd38n5 (4S>:R   )IQRR!#+,<=%	
	 %.)% A 8G,-AEE?r%   )%typingr   r   r   r   r   r   r	   r
   prompt_toolkit.completionr   r   r   prompt_toolkit.documentr   prompt_toolkit.formatted_textr   prompt_toolkit.lexersr   prompt_toolkit.shortcuts.promptr   r   prompt_toolkit.stylesr   questionary.constantsr   questionary.prompts.commonr   questionary.questionr   questionary.stylesr   r   COLUMNrG   rI   rc   rL   r%   r#   <module>rp      s!           3 / 0 , . - 9 9 ' 9 6 ) 3II I^ (%)15$1$8$8!pp#Yp p 	p
 	"p tCH~.p p p "p p E?p p pr%   