)L idZddlmZddlmZmZddlmZmZddl m Z ddl m Z ddl mZmZerdd lmZgd ZGd d ZGd deZGddeZGddeZGddeZGddeZGddeZy)a) `Fish-style `_ 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)ABCMetaabstractmethod) TYPE_CHECKINGCallablerun_in_executor_with_context)Document)Filter to_filter)Buffer) Suggestion AutoSuggestThreadedAutoSuggestDummyAutoSuggestAutoSuggestFromHistoryConditionalAutoSuggestDynamicAutoSuggestc eZdZdZddZddZy)rzb Suggestion returned by an auto-suggest algorithm. :param text: The suggestion text. c||_yNtext)selfrs a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/prompt_toolkit/auto_suggest.py__init__zSuggestion.__init__.s  c"d|jdS)Nz Suggestion()r)rs r__repr__zSuggestion.__repr__1sTYYKq))rN)rstrreturnNone)r#r")__name__ __module__ __qualname____doc__rr!rrrr's *rrc6eZdZdZeddZ ddZy)rz9 Base class for auto suggestion implementations. cy)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)rbufferdocuments rget_suggestionzAutoSuggest.get_suggestion:src.K|j||Sw)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. r/rbuffr.s rget_suggestion_asyncz AutoSuggest.get_suggestion_asyncKs""422sNr-rr.r r#Suggestion | Noner3rr.r r#r6)r%r&r'r(rr/r4r)rrrr5s8  33&.3 3rr) metaclassc4eZdZdZddZddZ ddZy)rz 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.) c||_yr) auto_suggest)rr;s rrzThreadedAutoSuggest.__init__]s (rc:|jj||Sr)r;r/r2s rr/z"ThreadedAutoSuggest.get_suggestion`s  //h??rcJKdfd }t|d{S7w)z@ Run the `get_suggestion` function in a thread. c(jSrr1)r3r.rsrrun_get_suggestion_threadzKThreadedAutoSuggest.get_suggestion_async..run_get_suggestion_threadjs&&tX6 6rN)r#r6r)rr3r.r?s``` rr4z(ThreadedAutoSuggest.get_suggestion_asynccs  722KLLLLs #!#N)r;rr#r$r7r%r&r'r(rr/r4r)rrrrVs3 )@ M M&. M  MrrceZdZdZddZy)rz? AutoSuggest class that doesn't return any suggestion. cyrr)r,s rr/zDummyAutoSuggest.get_suggestionusrNr5r%r&r'r(r/r)rrrrps rrceZdZdZddZy)rz= Give suggestions based on the lines in the history. c\|j}|jjddd}|jrqt t |j D]L}t |jD].}|j|st|t|dccSNy)N r ) historyrrsplitstripreversedlist get_strings splitlines startswithrlen)rr-r.rHrstringlines rr/z%AutoSuggestFromHistory.get_suggestion~s..}}##D!,R0 ::<"4(;(;(=#>? =$V%6%6%89=Dt,)$s4y{*;<<= = rNr5rCr)rrrrys rrc eZdZdZddZddZy)rzU Auto suggest that can be turned on and of according to a certain condition. c2||_t||_yr)r;r filter)rr;rUs rrzConditionalAutoSuggest.__init__s(' rc\|jr|jj||Syr)rUr;r/r,s rr/z%ConditionalAutoSuggest.get_suggestions' ;;=$$33FHE ErN)r;rrUz bool | Filterr#r$r5)r%r&r'r(rr/r)rrrrs(rrc4eZdZdZddZddZ ddZy)rz Validator class that can dynamically returns any Validator. :param get_validator: Callable that returns a :class:`.Validator` instance. c||_yr)get_auto_suggest)rrYs rrzDynamicAutoSuggest.__init__s 0rc^|jxs t}|j||Sr)rYrr/rr3r.r;s rr/z!DynamicAutoSuggest.get_suggestions,,,.D2B2D **4::rczK|jxs t}|j||d{S7wr)rYrr4r[s rr4z'DynamicAutoSuggest.get_suggestion_asyncs8,,.D2B2D !66tXFFFFs 2;9;N)rYz Callable[[], AutoSuggest | None]r#r$r7r@r)rrrrs2 1;GG&.G GrrN)r( __future__rabcrrtypingrrprompt_toolkit.eventloopr r.r filtersr r r-r__all__rrrrrrrr)rrrcs #'*A&  * *3G3BM+M4{[, [  GGr