
    Mh                    :   d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
 ddlmZ ddlmZmZ erdd	lmZ g d
Z G d d          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          ZdS )a)  
`Fish-style <http://fishshell.com/>`_  like auto-suggestion.

While a user types input in a certain buffer, suggestions are generated
(asynchronously.) Usually, they are displayed after the input. When the cursor
presses the right arrow and the cursor is at the end of the input, the
suggestion will be inserted.

If you want the auto suggestions to be asynchronous (in a background thread),
because they take too much time, and could potentially block the event loop,
then wrap the :class:`.AutoSuggest` instance into a
:class:`.ThreadedAutoSuggest`.
    )annotations)ABCMetaabstractmethod)TYPE_CHECKINGCallablerun_in_executor_with_context   )Document)Filter	to_filter)Buffer)
SuggestionAutoSuggestThreadedAutoSuggestDummyAutoSuggestAutoSuggestFromHistoryConditionalAutoSuggestDynamicAutoSuggestc                  "    e Zd ZdZd	dZd
dZdS )r   zb
    Suggestion returned by an auto-suggest algorithm.

    :param text: The suggestion text.
    textstrreturnNonec                    || _         d S Nr   )selfr   s     [/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prompt_toolkit/auto_suggest.py__init__zSuggestion.__init__.   s    			    c                    d| j          dS )NzSuggestion()r   )r   s    r   __repr__zSuggestion.__repr__1   s    )TY))))r!   N)r   r   r   r   )r   r   )__name__
__module____qualname____doc__r    r$    r!   r   r   r   '   sF            * * * * * *r!   r   c                  2    e Zd ZdZedd            Zdd
ZdS )r   z9
    Base class for auto suggestion implementations.
    bufferr   documentr   r   Suggestion | Nonec                    dS )a  
        Return `None` or a :class:`.Suggestion` instance.

        We receive both :class:`~prompt_toolkit.buffer.Buffer` and
        :class:`~prompt_toolkit.document.Document`. The reason is that auto
        suggestions are retrieved asynchronously. (Like completions.) The
        buffer text could be changed in the meantime, but ``document`` contains
        the buffer document like it was at the start of the auto suggestion
        call. So, from here, don't access ``buffer.text``, but use
        ``document.text`` instead.

        :param buffer: The :class:`~prompt_toolkit.buffer.Buffer` instance.
        :param document: The :class:`~prompt_toolkit.document.Document` instance.
        Nr)   r   r+   r,   s      r   get_suggestionzAutoSuggest.get_suggestion:   s      r!   buffc                2   K   |                      ||          S )z
        Return a :class:`.Future` which is set when the suggestions are ready.
        This function can be overloaded in order to provide an asynchronous
        implementation.
        r0   r   r1   r,   s      r   get_suggestion_asyncz AutoSuggest.get_suggestion_asyncK   s       ""4222r!   Nr+   r   r,   r   r   r-   r1   r   r,   r   r   r-   )r%   r&   r'   r(   r   r0   r5   r)   r!   r   r   r   5   sR             ^ 3 3 3 3 3 3r!   r   )	metaclassc                  *    e Zd ZdZddZddZddZdS )r   z
    Wrapper that runs auto suggestions in a thread.
    (Use this to prevent the user interface from becoming unresponsive if the
    generation of suggestions takes too much time.)
    auto_suggestr   r   r   c                    || _         d S r   )r:   )r   r:   s     r   r    zThreadedAutoSuggest.__init__]   s    (r!   r1   r   r,   r   r-   c                8    | j                             ||          S r   )r:   r0   r4   s      r   r0   z"ThreadedAutoSuggest.get_suggestion`   s     //h???r!   c                F    K   d fd}t          |           d{V S )z@
        Run the `get_suggestion` function in a thread.
        r   r-   c                 0                                    S r   r3   )r1   r,   r   s   r   run_get_suggestion_threadzKThreadedAutoSuggest.get_suggestion_async.<locals>.run_get_suggestion_threadj   s    &&tX666r!   N)r   r-   r   )r   r1   r,   r?   s   ``` r   r5   z(ThreadedAutoSuggest.get_suggestion_asyncc   sT      	7 	7 	7 	7 	7 	7 	7 	7 22KLLLLLLLLLr!   N)r:   r   r   r   r7   r%   r&   r'   r(   r    r0   r5   r)   r!   r   r   r   V   sd         ) ) ) )@ @ @ @
M 
M 
M 
M 
M 
Mr!   r   c                      e Zd ZdZd
dZd	S )r   z?
    AutoSuggest class that doesn't return any suggestion.
    r+   r   r,   r   r   r-   c                    d S r   r)   r/   s      r   r0   zDummyAutoSuggest.get_suggestionu   s    tr!   Nr6   r%   r&   r'   r(   r0   r)   r!   r   r   r   p   s2              r!   r   c                      e Zd ZdZd
dZd	S )r   z=
    Give suggestions based on the lines in the history.
    r+   r   r,   r   r   r-   c                   |j         }|j                            dd          d         }|                                rt	          t          |                                                    D ]c}t	          |                                          D ]?}|                    |          r(t          |t          |          d                    c c S @dd S )N
r
   )historyr   rsplitstripreversedlistget_strings
splitlines
startswithr   len)r   r+   r,   rH   r   stringlines          r   r0   z%AutoSuggestFromHistory.get_suggestion~   s    . }##D!,,R0 ::<< 	="4(;(;(=(=#>#>?? = =$V%6%6%8%899 = =Dt,, =)$s4yy{{*;<<<<<<<== tr!   Nr6   rC   r)   r!   r   r   r   y   s2              r!   r   c                  "    e Zd ZdZddZddZdS )r   zU
    Auto suggest that can be turned on and of according to a certain condition.
    r:   r   filterbool | Filterr   r   c                <    || _         t          |          | _        d S r   )r:   r   rT   )r   r:   rT   s      r   r    zConditionalAutoSuggest.__init__   s    (''r!   r+   r   r,   r   r-   c                d    |                                  r| j                            ||          S d S r   )rT   r:   r0   r/   s      r   r0   z%ConditionalAutoSuggest.get_suggestion   s1    ;;== 	F$33FHEEEtr!   N)r:   r   rT   rU   r   r   r6   )r%   r&   r'   r(   r    r0   r)   r!   r   r   r      sF         ( ( ( (     r!   r   c                  *    e Zd ZdZddZddZddZdS )r   z
    Validator class that can dynamically returns any Validator.

    :param get_validator: Callable that returns a :class:`.Validator` instance.
    get_auto_suggest Callable[[], AutoSuggest | None]r   r   c                    || _         d S r   )rY   )r   rY   s     r   r    zDynamicAutoSuggest.__init__   s     0r!   r1   r   r,   r   r-   c                r    |                                  pt                      }|                    ||          S r   )rY   r   r0   r   r1   r,   r:   s       r   r0   z!DynamicAutoSuggest.get_suggestion   s5    ,,..D2B2D2D**4:::r!   c                   K   |                                  pt                      }|                    ||           d {V S r   )rY   r   r5   r]   s       r   r5   z'DynamicAutoSuggest.get_suggestion_async   sM       ,,..D2B2D2D!66tXFFFFFFFFFr!   N)rY   rZ   r   r   r7   r@   r)   r!   r   r   r      s`         1 1 1 1; ; ; ;G G G G G Gr!   r   N)r(   
__future__r   abcr   r   typingr   r   prompt_toolkit.eventloopr	   r,   r   filtersr   r   r+   r   __all__r   r   r   r   r   r   r   r)   r!   r   <module>re      s     # " " " " " ' ' ' ' ' ' ' ' * * * * * * * * A A A A A A       & & & & & & & &   * * * * * * * *3 3 3 3 3G 3 3 3 3BM M M M M+ M M M4    {       [   ,    [    G G G G G G G G G Gr!   