
    Cjs                        S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr  SSKJr  \ " S	 S
\5      5       r " S S\5      r " S S\5      rg)zO

Contains the `Suggester` class, used by the [Input](/widgets/input) widget.

    )annotations)ABCabstractmethod)	dataclass)Iterable)LRUCache)DOMNode)Messagec                  0    \ rS rSr% SrS\S'    S\S'   Srg)SuggestionReady   z+Sent when a completion suggestion is ready.strvalue
suggestion N)__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__r       c/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/textual/suggester.pyr   r      s    5J3O r   r   c                  X    \ rS rSr% SrS\S'    SSS.SS jjrSS	 jr\SS
 j5       r	Sr
g)	Suggester   zDefines how widgets generate completion suggestions.

To define a custom suggester, subclass `Suggester` and implement the async method
`get_suggestion`.
See [`SuggestFromList`][textual.suggester.SuggestFromList] for an example.
z LRUCache[str, str | None] | NonecacheTF)	use_cachecase_sensitivec               B    U(       a  [        S5      OSU l        X l        g)zCreate a suggester object.

Args:
    use_cache: Whether to cache suggestion results.
    case_sensitive: Whether suggestions are case sensitive or not.
        If they are not, incoming values are casefolded before generating
        the suggestion.
i   N)r   r   r    )selfr   r    s      r   __init__Suggester.__init__'   s     (1Xd^d
,r   c                R  #    U R                   (       a  UOUR                  5       nU R                  b  X0R                  ;  a5  U R                  U5      I Sh  vN nU R                  b  X@R                  U'   OU R                  U   nUc  gUR	                  [        X$5      5        g NN7f)zUsed by widgets to get completion suggestions.

Note:
    When implementing custom suggesters, this method does not need to be
    overridden.

Args:
    requester: The message target that requested a suggestion.
    value: The current value to complete.
N)r    casefoldr   get_suggestionpost_messager   )r"   	requesterr   normalized_valuer   s        r   _get_suggestionSuggester._get_suggestion3   s      %)$7$75U^^=M::!1!C#223CDDJzz%/9

+,$45JuAB Es   AB'B%AB'c                   #    g7f)a  Try to get a completion suggestion for the given input value.

Custom suggesters should implement this method.

Note:
    The value argument will be casefolded if `self.case_sensitive` is `False`.

Note:
    If your implementation is not deterministic, you may need to disable caching.

Args:
    value: The current value of the requester widget.

Returns:
    A valid suggestion or `None`.
Nr   )r"   r   s     r   r'   Suggester.get_suggestionK   s
     $ 	s   )r   r    N)r   boolr    r/   returnNone)r)   r	   r   r   r0   r1   r   r   r0   z
str | None)r   r   r   r   r   r   r#   r+   r   r'   r   r   r   r   r   r      s6     ,+$,0 
-C0  r   r   c                  L   ^  \ rS rSrSrSS.     SU 4S jjjrS	S jrSrU =r$ )
SuggestFromList`   a  Give completion suggestions based on a fixed list of options.

Example:
    ```py
    countries = ["England", "Scotland", "Portugal", "Spain", "France"]

    class MyApp(App[None]):
        def compose(self) -> ComposeResult:
            yield Input(suggester=SuggestFromList(countries, case_sensitive=False))
    ```

    If the user types ++p++ inside the input widget, a completion suggestion
    for `"Portugal"` appears.
Tr    c                  > [         TU ]  US9  [        U5      U l        U R                  (       a  U R                  U l        gU R                   Vs/ s H  o3R                  5       PM     snU l        gs  snf )a  Creates a suggester based off of a given iterable of possibilities.

Args:
    suggestions: Valid suggestions sorted by decreasing priority.
    case_sensitive: Whether suggestions are computed in a case sensitive manner
        or not. The values provided in the argument `suggestions` represent the
        canonical representation of the completions and they will be suggested
        with that same casing.
r6   N)superr#   list_suggestionsr    r&   _for_comparison)r"   suggestionsr    r   	__class__s       r   r#   SuggestFromList.__init__p   sq     	7 - ""  	 ;?:K:KL:KJ%%':KL 	 Ms   A2c                   #    [        U R                  5       H,  u  p#UR                  U5      (       d  M  U R                  U   s  $    g7f)zGets a completion from the given possibilities.

Args:
    value: The current value.

Returns:
    A valid completion suggestion or `None`.
N)	enumerater;   
startswithr:   )r"   r   idxr   s       r   r'   SuggestFromList.get_suggestion   sE       ))=)=>OC$$U++((--  ? s
   /A	A	)r;   r:   )r<   zIterable[str]r    r/   r0   r1   r2   )	r   r   r   r   r   r#   r'   r   __classcell__)r=   s   @r   r4   r4   `   s;      EI
(
=A
	
 
( r   r4   N)r   
__future__r   abcr   r   dataclassesr   typingr   textual.cacher   textual.domr	   textual.messager
   r   r   r4   r   r   r   <module>rL      sW    # # !  "  # !g ! !A AH0i 0r   