ó
    NÎh:  ã                  óÆ   • S SK Jr  S SKrS SKJrJrJrJr  S SKJ	r	  S SK
JrJr  S SKJrJr  SSKJrJrJr  SS	KJr  S
S/r " S S
\5      r " S S\5      r " S S\5      rg)é    )ÚannotationsN)ÚCallableÚIterableÚ
NamedTupleÚSequence)ÚDocument)ÚFilterOrBoolÚ	to_filter)ÚAnyFormattedTextÚStyleAndTextTuplesé   )ÚCompleteEventÚ	CompleterÚ
Completion)ÚWordCompleterÚFuzzyCompleterÚFuzzyWordCompleterc                  óŠ   • \ rS rSrSr   S
         SS jjr      SS jrSS jr      SS jr      SS jr	S	r
g)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                óŠ   • Ub  UR                  S5      (       d   eXl        X0l        X l        X0l        [	        U5      U l        g )NÚ^)Ú
startswithÚ	completerÚpatternÚWORDr
   Úenable_fuzzy)Úselfr   r   r   r   s        Úf/home/mande/repo/quber/.venv/lib/python3.13/site-packages/prompt_toolkit/completion/fuzzy_completer.pyÚ__init__ÚFuzzyCompleter.__init__0   s@   € ð ‰ '×"4Ñ"4°S×"9Ñ"9Ð9Ð9à"ŒØŒØŒ	ØŒÜ% lÓ3ˆÕó    c                ó„   • U R                  5       (       a  U R                  X5      $ U R                  R                  X5      $ ©N)r   Ú_get_fuzzy_completionsr   Úget_completions©r   ÚdocumentÚcomplete_events      r   r%   ÚFuzzyCompleter.get_completions?   s9   € ð ×Ñ×ÑØ×.Ñ.¨xÓHÐHà—>‘>×1Ñ1°(ÓKÐKr!   c                ób   • U R                   (       a  U R                   $ U R                  (       a  gg)Nz[^\s]+z^[a-zA-Z0-9_]*)r   r   )r   s    r   Ú_get_patternÚFuzzyCompleter._get_patternG   s    € Ø�<�<Ø—<‘<ÐØ�9�9ØØr!   c           
   #  ób  #   • UR                  [        R                  " U R                  5       5      S9n[	        UR
                  S UR                  [        U5      -
   UR                  [        U5      -
  S9n[        U R                  R                  XB5      5      n/ nUS:X  a  U Vs/ s H  n[        SSU5      PM     nnOåSR                  [        [        R                  U5      5      nSU S3n[        R                  " U[        R                  5      n	U H}  n[        U	R!                  UR
                  5      5      n
U
(       d  M0  [#        U
S S	9nUR%                  [        [        UR'                  S
5      5      UR)                  5       U5      5        M     SS jn[+        XlS	9nU H}  n[-        UR.                  R
                  UR.                  R0                  [        U5      -
  UR.                  R2                  U R5                  XÓ5      UR.                  R6                  S9v •  M     g s  snf 7f)N)r   )ÚtextÚcursor_positionÚ r   z.*?z(?=(z))c                óV   • U R                  5       [        U R                  S5      5      4$ )Nr   )ÚstartÚlenÚgroup)Úms    r   Ú<lambda>Ú7FuzzyCompleter._get_fuzzy_completions.<locals>.<lambda>n   s   € °q·w±w³yÄ#ÀaÇgÁgÈaÃjÃ/Ñ6Rr!   )Úkeyr   c                ó2   • U R                   U R                  4$ )z8Sort by start position, then by the length of the match.)Ú	start_posÚmatch_length)Úfuzzy_matchs    r   Úsort_keyÚ7FuzzyCompleter._get_fuzzy_completions.<locals>.sort_keys   s   € à"×,Ñ,¨k×.FÑ.FÐFÐFr!   )r.   Ústart_positionÚdisplay_metaÚdisplayÚstyle)r<   Ú_FuzzyMatchÚreturnztuple[int, int])Úget_word_before_cursorÚreÚcompiler+   r   r.   r/   r3   Úlistr   r%   rC   ÚjoinÚmapÚescapeÚ
IGNORECASEÚfinditerÚminÚappendr4   r2   Úsortedr   Ú
completionr?   Ú_display_metaÚ_get_displayrB   )r   r'   r(   Úword_before_cursorÚ	document2Úinner_completionsÚfuzzy_matchesÚcomplÚpatÚregexÚmatchesÚbestr=   Úmatchs                 r   r$   Ú%FuzzyCompleter._get_fuzzy_completionsN   së  é € ð &×<Ñ<Ü—J’J˜t×0Ñ0Ó2Ó3ð =ð 
Ðô
 Ø—‘ÐS ×!9Ñ!9¼CÐ@RÓ<SÑ!SÐTØ$×4Ñ4´sÐ;MÓ7NÑNñ
ˆ	ô
 !Ø�N‰N×*Ñ*¨9ÓEó
Ðð ,.ˆà Ó#ñ DUÓUÒCT¸%œ[¨¨A¨uÖ5ÑCTˆMÐUˆMà—*‘*œS¤§¡Ð,>Ó?Ó@ˆCØ˜˜˜R�.ˆCÜ—J’J˜s¤B§M¡MÓ2ˆEÛ*�Ü˜uŸ~™~¨e¯j©jÓ9Ó:�ß�7ä˜wÑ,RÑS�DØ!×(Ñ(Ü#¤C¨¯
©
°1«Ó$6¸¿
¹
»ÀeÓLöñ +ôGô # =Ñ?ˆMã"ˆEô Ø×%Ñ%×*Ñ*Ø$×/Ñ/×>Ñ>ÜÐ(Ó)ñ *ð #×-Ñ-×;Ñ;Ø×)Ñ)¨%ÓDØ×&Ñ&×,Ñ,ñô ò #ùò) Vùs   ‚B%H/Â'H*Â>BH/ÅC(H/c                ó&   ^^• SUU4S jjnU" 5       $ )z0
Generate formatted text for the display label.
c                 ó  >• Tn U R                   R                  nU R                  S:X  a  U R                   R                  $ / nUR	                  SUS U R
                   45        [        T5      nXR
                  U R
                  U R                  -     HK  nSnU(       a-  UR                  5       US   R                  5       :X  a  US-  nUS	 UR	                  XT45        MM     UR	                  SXR
                  U R                  -   S  45        U$ )Nr   zclass:fuzzymatch.outsidezclass:fuzzymatch.insidez
.character)rQ   r.   r;   rA   rO   r:   rH   Úlower)r5   ÚwordÚresultÚ
charactersÚcÚ	classnamer<   rT   s         €€r   Úget_displayÚ0FuzzyCompleter._get_display.<locals>.get_display�   sø   ø€ ØˆAØ—<‘<×$Ñ$ˆDà�~‰~ Ó"ð —|‘|×+Ñ+Ð+à)+ˆFð �M‰MÐ5°t¸M¸a¿k¹kÐ7JÐKÔLô Ð0Ó1ˆJàŸ+™+¨¯©°a·n±nÑ(DÓE�Ø5�	Þ !§'¡'£)¨z¸!©}×/BÑ/BÓ/DÓ"DØ Ñ-�IØ" 1˜à—‘˜y˜nÖ-ñ Fð �M‰MØ+¨T·+±+ÀÇÁÑ2NÐ2PÐ-QÐRôð ˆMr!   )rD   r   © )r   r<   rT   rg   s    `` r   rS   ÚFuzzyCompleter._get_display†   s   ù€ ÷	ð 	ñB ‹}Ðr!   )r   r   r   r   )FNT)
r   r   r   Úboolr   z
str | Noner   r	   rD   ÚNone©r'   r   r(   r   rD   zIterable[Completion])rD   Ústr)r<   rC   rT   rn   rD   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r%   r+   r$   rS   Ú__static_attributes__ri   r!   r   r   r      s¨   † ñð> Ø"Ø%)ð4àð4ð ð4ð ð	4ð
 #ð4ð 
õ4ðLØ ðLØ2?ðLà	ôLô ð6Ø ð6Ø2?ð6à	ô6ðp(Ø&ð(Ø<?ð(à	÷(r!   c                  óN   • \ rS rSrSr  S       SS jjr      S	S jrSrg)
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                óÞ   • Xl         U=(       d    0 U l        X0l        [        U R                   U R                  U R                  S9U l        [        U R                  U R                  S9U l        g )N)Úwordsr   Ú	meta_dict)r   )rx   ry   r   r   Úword_completerr   Úfuzzy_completer)r   rx   ry   r   s       r   r   ÚFuzzyWordCompleter.__init__¼   sT   € ð Œ
Ø"Ÿ bˆŒØŒ	ä+Ø—*‘* 4§9¡9¸¿¹ñ
ˆÔô  .¨d×.AÑ.AÈÏ	É	ÑRˆÕr!   c                ó8   • U R                   R                  X5      $ r#   )r{   r%   r&   s      r   r%   Ú"FuzzyWordCompleter.get_completionsÌ   s   € ð ×#Ñ#×3Ñ3°HÓMÐMr!   )r   r{   ry   rz   rx   )NF)rx   z+Sequence[str] | Callable[[], Sequence[str]]ry   zdict[str, str] | Noner   rk   rD   rl   rm   )ro   rp   rq   rr   rs   r   r%   rt   ri   r!   r   r   r   ±   s`   † ñð ,0Øð	Sà:ðSð )ðSð ð	Sð
 
õSð NØ ðNØ2?ðNà	÷Nr!   c                  ó4   • \ rS rSr% S\S'   S\S'   S\S'   Srg)	rC   éÒ   Úintr;   r:   r   rQ   ri   N)ro   rp   rq   rr   Ú__annotations__rt   ri   r!   r   rC   rC   Ò   s   ‡ ØÓØƒNØÖr!   rC   )Ú
__future__r   rF   Útypingr   r   r   r   Úprompt_toolkit.documentr   Úprompt_toolkit.filtersr	   r
   Úprompt_toolkit.formatted_textr   r   Úbaser   r   r   rz   r   Ú__all__r   r   rC   ri   r!   r   Ú<module>rŠ      s\   ðÝ "ã 	ß ;Ó ;å ,ß :ß Nç 6Ñ 6Ý )ð Øð€ô[�Yô [ô|N˜ô NôB�*õ r!   