+
    j,i:                        ^ RI Ht ^ RIt^ RIHtHtHtHt ^ RIH	t	 ^ RI
HtHt ^ RIHtHt ^RIHtHtHt ^RIHt R	R
.t ! R R	]4      t ! R R
]4      t ! R R]4      tR# )    )annotationsN)CallableIterable
NamedTupleSequence)Document)FilterOrBool	to_filter)AnyFormattedTextStyleAndTextTuples)CompleteEvent	Completer
Completion)WordCompleterFuzzyCompleterFuzzyWordCompleterc                  Z    ] tR t^tRtRR R lltR R ltR R ltR	 R
 ltR R lt	Rt
R# )r   a  
Fuzzy completion.
This wraps any other completer and turns it into a fuzzy completer.

If the list of words is: ["leopard" , "gorilla", "dinosaur", "cat", "bee"]
Then trying to complete "oar" would yield "leopard" and "dinosaur", but not
the others, because they match the regular expression 'o.*a.*r'.
Similar, in another application "djm" could expand to "django_migrations".

The results are sorted by relevance, which is defined as the start position
and the length of the match.

Notice that this is not really a tool to work around spelling mistakes,
like what would be possible with difflib. The purpose is rather to have a
quicker or more intuitive way to filter the given completions, especially
when many completions have a common prefix.

Fuzzy algorithm is based on this post:
https://blog.amjith.com/fuzzyfinder-in-10-lines-of-python

:param completer: A :class:`~.Completer` instance.
:param WORD: When True, use WORD characters.
:param pattern: Regex pattern which selects the characters before the
    cursor that are considered for the fuzzy matching.
:param enable_fuzzy: (bool or `Filter`) Enabled the fuzzy behavior. For
    easily turning fuzzyness on or off according to a certain condition.
Nc          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )   	completerr   WORDboolpatternz
str | Noneenable_fuzzyr	   returnNone )formats   "K/usr/lib/python3/dist-packages/prompt_toolkit/completion/fuzzy_completer.py__annotate__FuzzyCompleter.__annotate__0   s<     4 44 4 	4
 #4 
4    c                	    Ve   VP                  R4      '       g   Q hWn        W0n        W n        W0n        \	        V4      V n        R # )N^)
startswithr   r   r   r
   r   )selfr   r   r   r   s   &&&&&r   __init__FuzzyCompleter.__init__0   s@     '"4"4S"9"999"	%l3r"   c               $    V ^8  d   QhRRRRRR/# r   documentr   complete_eventr   r   zIterable[Completion]r   )r   s   "r   r    r!   ?   s)     L L L2?L	Lr"   c                	    V P                  4       '       d   V P                  W4      # V P                  P                  W4      # N)r   _get_fuzzy_completionsr   get_completionsr&   r+   r,   s   &&&r   r0   FuzzyCompleter.get_completions?   s9     ..xHH>>11(KKr"   c                   V ^8  d   QhRR/# )r   r   strr   )r   s   "r   r    r!   G   s        c  r"   c                	j    V P                   '       d   V P                   # V P                  '       d   R # R# )z[^\s]+z^[a-zA-Z0-9_]*)r   r   )r&   s   &r   _get_patternFuzzyCompleter._get_patternG   s$    <<<<<999r"   c               $    V ^8  d   QhRRRRRR/# r*   r   )r   s   "r   r    r!   N   s$     6 6 62?6	6r"   c           
   #  	  "   VP                  \        P                  ! V P                  4       4      R 7      p\	        VP
                  RVP                  \        V4      ,
           VP                  \        V4      ,
          R7      p\        V P                  P                  WB4      4      p. pVR8X  d   V Uu. uF  p\        ^ ^ V4      NK  	  ppMRP                  \        \        P                  V4      4      pRV R2p\        P                  ! V\        P                  4      p	V F  p\        V	P!                  VP
                  4      4      p
V
'       g   K1  \#        V
R R7      pVP%                  \        \        VP'                  ^4      4      VP)                  4       V4      4       K  	  R	 R
 lp\+        WlR7      pV F  p\-        VP.                  P
                  VP.                  P0                  \        V4      ,
          VP.                  P2                  V P5                  W4      VP.                  P6                  R7      x  K  	  R# u upi 5i))r   N)textcursor_position z.*?z(?=(z))c                V    V P                  4       \        V P                  ^4      4      3# )   )startlengroup)ms   &r   <lambda>7FuzzyCompleter._get_fuzzy_completions.<locals>.<lambda>n   s    qwwy#aggaj/6Rr"   )keyc                    V ^8  d   QhRRRR/# )r   fuzzy_match_FuzzyMatchr   ztuple[int, int]r   )r   s   "r   r    ;FuzzyCompleter._get_fuzzy_completions.<locals>.__annotate__s   s     G Gk Go Gr"   c                2    V P                   V P                  3# )z8Sort by start position, then by the length of the match.)	start_posmatch_length)rG   s   &r   sort_key7FuzzyCompleter._get_fuzzy_completions.<locals>.sort_keys   s    ",,k.F.FFFr"   )r:   start_positiondisplay_metadisplaystyle)get_word_before_cursorrecompiler6   r   r:   r;   r@   listr   r0   rH   joinmapescape
IGNORECASEfinditerminappendrA   r?   sortedr   
completionrO   _display_meta_get_displayrR   )r&   r+   r,   word_before_cursor	document2inner_completionsfuzzy_matchescomplpatregexmatchesbestrM   matchs   &&&           r   r/   %FuzzyCompleter._get_fuzzy_completionsN   s     &<<JJt0023 = 

 S!9!9C@R<S!ST$44s;M7NN
	
 !NN**9E
 ,.# DUUCT%[Au5CTMUM**S,>?@CR.CJJsBMM2E*u~~ejj9:7w,RSD!((#C

1$6

eL +G #=?M"E %%**$//>>() * #--;;))%D&&,,  #) Vs   B4I6IBIC7Ic               $    V ^8  d   QhRRRRRR/# )r   rG   rH   rb   r4   r   r   r   )r   s   "r   r    r!      s$     ( (&(<?(	(r"   c                (   aa R VV3R llpV! 4       # )z0
Generate formatted text for the display label.
c                   V ^8  d   QhRR/# )r   r   r   r   )r   s   "r   r    1FuzzyCompleter._get_display.<locals>.__annotate__   s     	 	- 	r"   c                 D  < Sp V P                   P                  pV P                  ^ 8X  d   V P                   P                  # . pVP	                  RVRV P
                   34       \        S4      pWP
                  V P
                  V P                  ,             FU  pRpV'       d7   VP                  4       V^ ,          P                  4       8X  d   VR,          pV^  VP	                  WT34       KW  	  VP	                  RWP
                  V P                  ,           R 34       V# )r   zclass:fuzzymatch.outsideNzclass:fuzzymatch.insidez
.character)r_   r:   rL   rQ   r]   rK   rV   lower)rB   wordresult
charactersc	classnamerG   rb   s         r   get_display0FuzzyCompleter._get_display.<locals>.get_display   s    A<<$$D~~" ||+++)+F MM5tMakk7JKL 01J++ann(DE5	!'')z!}/B/B/D"D-I"1yn- F MM+T++2N2P-QR Mr"   r   )r&   rG   rb   rx   s   &ff r   ra   FuzzyCompleter._get_display   s    	 	B }r"   )r   r   r   r   )FNT)__name__
__module____qualname____firstlineno____doc__r'   r0   r6   r/   ra   __static_attributes__r   r"   r   r   r      s'    84L 6p( (r"   c                  6    ] tR t^tRtRR R lltR R ltRtR# )	r   a)  
Fuzzy completion on a list of words.

(This is basically a `WordCompleter` wrapped in a `FuzzyCompleter`.)

:param words: List of words or callable that returns a list of words.
:param meta_dict: Optional dict mapping words to their meta-information.
:param WORD: When True, use WORD characters.
Nc               (    V ^8  d   QhRRRRRRRR/# )	r   wordsz+Sequence[str] | Callable[[], Sequence[str]]	meta_dictzdict[str, str] | Noner   r   r   r   r   )r   s   "r   r    FuzzyWordCompleter.__annotate__   s8     S S:S )S 	S
 
Sr"   c                	    Wn         T;'       g    / V n        W0n        \        V P                   V P                  V P                  R 7      V n        \        V P                  V P                  R7      V n        R# ))r   r   r   )r   N)r   r   r   r   word_completerr   fuzzy_completer)r&   r   r   r   s   &&&&r   r'   FuzzyWordCompleter.__init__   sV     
"b	+**499
  .d.A.A		Rr"   c               $    V ^8  d   QhRRRRRR/# r*   r   )r   s   "r   r    r      s)     N N N2?N	Nr"   c                	8    V P                   P                  W4      # r.   )r   r0   r1   s   &&&r   r0   "FuzzyWordCompleter.get_completions   s     ##33HMMr"   )r   r   r   r   r   )NF)r{   r|   r}   r~   r   r'   r0   r   r   r"   r   r   r      s    S N Nr"   c                  6    ] tR t^t$ R]R&   R]R&   R]R&   RtR# )rH   intrL   rK   r   r_   r   N)r{   r|   r}   r~   __annotations__r   r   r"   r   rH   rH      s    Nr"   rH   )
__future__r   rT   typingr   r   r   r   prompt_toolkit.documentr   prompt_toolkit.filtersr	   r
   prompt_toolkit.formatted_textr   r   baser   r   r   r   r   __all__r   r   rH   r   r"   r   <module>r      s\    " 	 ; ; , : N 6 6 ) [Y [|N NB* r"   