U
    oufY                     @  sj   d dl mZ d dlmZmZmZmZ d dlmZm	Z	m
Z
 d dlmZ d dlmZ dgZG dd de	ZdS )	    )annotations)CallableIterableMappingPattern)CompleteEvent	Completer
Completion)Document)AnyFormattedTextWordCompleterc                   @  sB   e Zd ZdZddddddddddd		d
dZddddddZdS )r   a  
    Simple autocompletion on a list of words.

    :param words: List of words or callable that returns a list of words.
    :param ignore_case: If True, case-insensitive completion.
    :param meta_dict: Optional dict mapping words to their meta-text. (This
        should map strings to strings or formatted text.)
    :param WORD: When True, use WORD characters.
    :param sentence: When True, don't complete by comparing the word before the
        cursor, but by comparing all the text before the cursor. In this case,
        the list of words is just a list of strings, where each string can
        contain spaces. (Can not be used together with the WORD option.)
    :param match_middle: When True, match not only the start, but also in the
                         middle of the word.
    :param pattern: Optional compiled regex for finding the word before
        the cursor to complete. When given, use this regex pattern instead of
        default one (see document._FIND_WORD_RE)
    FNz#list[str] | Callable[[], list[str]]boolz%Mapping[str, AnyFormattedText] | NonezPattern[str] | NoneNone)	wordsignore_casedisplay_dict	meta_dictWORDsentencematch_middlepatternreturnc	           	      C  sH   |r|rt || _|| _|pi | _|p(i | _|| _|| _|| _|| _d S )N)	AssertionErrorr   r   r   r   r   r   r   r   )	selfr   r   r   r   r   r   r   r    r   L/tmp/pip-unpacked-wheel-8milen2s/prompt_toolkit/completion/word_completer.py__init__"   s    

zWordCompleter.__init__r
   r   zIterable[Completion])documentcomplete_eventr   c                 #  s    j }t|r| } jr"|jn|j j jd jrB ddd fdd}|D ]@}||r\ j	
||} j
|d}t|t ||dV  q\d S )	N)r   r   strr   )wordr   c                   s*    j r|  }  jr| kS | S dS )z-True when the word before the cursor matches.N)r   lowerr   
startswith)r    r   Zword_before_cursorr   r   word_matchesK   s
    z3WordCompleter.get_completions.<locals>.word_matches )textZstart_positiondisplaydisplay_meta)r   callabler   Ztext_before_cursorZget_word_before_cursorr   r   r   r!   r   getr   r	   len)r   r   r   r   r$   ar'   r(   r   r#   r   get_completions8   s,     
zWordCompleter.get_completions)FNNFFFN)__name__
__module____qualname____doc__r   r-   r   r   r   r   r      s           N)
__future__r   typingr   r   r   r   Zprompt_toolkit.completionr   r   r	   Zprompt_toolkit.documentr
   Zprompt_toolkit.formatted_textr   __all__r   r   r   r   r   <module>   s   