o
    i|                     @   s|  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 deZ deddddej!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(d)Z$dS )*    )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                   @   s   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	d
Zdee fddZdededefddZededededefddZdededee fddZdS )WordCompleterchoices_sourceignore_casemeta_informationmatch_middleTNchoicesreturnc                 C   s    || _ || _|p	i | _|| _d S N)r   r   r   r   )selfr   r   r   r    r    T/home/ubuntu/.local/lib/python3.10/site-packages/questionary/prompts/autocomplete.py__init__    s   

zWordCompleter.__init__c                 C   s   t | jr	|  S | jS r   )callabler   )r   r    r    r!   _choices,   s
   zWordCompleter._choicesword_before_cursorchoicec                 C   s0   | j r| }| jr||S ||rdS dS )z Match index if found, -1 if not.r   )r   lowerr   find
startswith)r   r%   r&   r    r    r!   _choice_matches3   s   

zWordCompleter._choice_matchesindexc                 C   s>   t d| d | | ||t|  | |t| t|  S )Nz{}<b><u>{}</u></b>{})r   formatlen)r&   r,   r%   r    r    r!   _display_for_choice@   s
   
z!WordCompleter._display_for_choicedocumentcomplete_eventc           	   	   c   s|    |   }|j}| jr| }|D ]*}| ||}|dkrq| j|d}| |||}t|t	| |j
|dddV  qd S )Nr'    class:answerzclass:selected)start_positiondisplaydisplay_metastyleselected_style)r$   text_before_cursorr   r(   r+   r   getr/   r   r.   formatted_text)	r   r0   r1   r   r%   r&   r,   r6   r5   r    r    r!   get_completionsH   s(   
zWordCompleter.get_completions)TNT)__name__
__module____qualname__r	   r   strr   __annotations__boolr   r   r   r"   r   r$   intr+   staticmethodr   r/   r   r
   r   r<   r    r    r    r!   r      s<   
  
r   r2   NTmessager   defaultqmark	completerr   r   r   complete_stylevalidater7   kwargsr   c                    s   t |
g}dttttf  f fdd}dttttf  dttttf  fdd}t|	}|du rB|s8tdt	|||||d	}t
|ftd
||||d|}|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                      s   dfdd  fgS )Nzclass:qmarkzclass:questionz {} )r-   r    rE   rG   r    r!   get_prompt_tokens   s   z'autocomplete.<locals>.get_prompt_tokensmetac                 S   s(   | r| D ]}t d| | | |< q| S )Nz<text>{}</text>)r   r-   )rN   keyr    r    r!   get_meta_style   s   z$autocomplete.<locals>.get_meta_styleNz2No choices is given, you should use Text question.)r   r   r   r3   )lexerr7   rH   	validatorrI   )r   r   r   r@   r   r   r   r   
ValueErrorr   r   r   default_bufferresetr   r   app)rE   r   rF   rG   rH   r   r   r   rI   rJ   r7   rK   merged_stylerM   rP   rR   pr    rL   r!   autocompletef   s4   
L *	
rY   )%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   COLUMNr@   rB   rY   r    r    r    r!   <module>   st    O	
