)L i>`dZddlmZddlmZmZddlmZmZm Z m Z ddl m Z ddl mZmZddlmZmZddlmZmZgd ZGd d ZGd d ZGddeZGddeZGddeZGddeZGddeZGddeZ d d dZ d!dZ d"dZ!y)# ) annotations)ABCMetaabstractmethod)AsyncGeneratorCallableIterableSequence)Documentaclosinggenerator_to_async_generator) FilterOrBool to_filter)AnyFormattedTextStyleAndTextTuples) Completion CompleterThreadedCompleterDummyCompleterDynamicCompleter CompleteEventConditionalCompletermerge_completersget_common_complete_suffixceZdZdZ d d dZd dZddZddZed dZ eddZ ed d Z dd Z y)ra :param text: The new string that will be inserted into the document. :param start_position: Position relative to the cursor_position where the new text will start. The text will be inserted between the start_position and the original cursor position. :param display: (optional string or formatted text) If the completion has to be displayed differently in the completion menu. :param display_meta: (Optional string or formatted text) Meta information about the completion, e.g. the path or source where it's coming from. This can also be a callable that returns a string. :param style: Style string. :param selected_style: Style string, used for a selected completion. This can override the `style` parameter. Ncddlm}||_||_||_||}|||_||_||_|jdksJy)Nrto_formatted_text)prompt_toolkit.formatted_textrtextstart_position _display_metadisplaystyleselected_style)selfr!r"r$ display_metar%r&rs d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/prompt_toolkit/completion/base.py__init__zCompletion.__init__*sX D ,) ?G(1  ,""a'''cNt|jtrL|j|jk(r3|jj d|jd|j dS|jj d|jd|j d|jdS)Nz(text=z, start_position=)z , display=) isinstancer$strr! __class____name__r"r's r)__repr__zCompletion.__repr__Cs dllC (T\\TYY-Fnn--.fTYYMARSWSfSfRiijk knn--.fTYYMARSWSfSfRiistxuAuAtDDEF Fr+ct|tsy|j|jk(xrO|j|jk(xr4|j|jk(xr|j |j k(S)NF)r.rr!r"r$r#)r'others r)__eq__zCompletion.__eq__Ism%, II # :##u';';; :  - :""e&9&99  r+cpt|j|j|j|jfSN)hashr!r"r$r#r2s r)__hash__zCompletion.__hash__Ss*TYY 3 3T\\4CUCUVWWr+c2ddlm}||jS)z"The 'display' field as plain text.rfragment_list_to_text)r r=r$r'r=s r) display_textzCompletion.display_textVs H$T\\22r+c:ddlm}||jxsdS)z7Return meta-text. (This is lazy when using a callable).rr)r rr#)r'rs r)r(zCompletion.display_meta]s D !3!3!9r::r+c2ddlm}||jS)zThe 'meta' field as plain text.rr<)r r=r(r>s r)display_meta_textzCompletion.display_meta_textds H$T%6%677r+c||jz dk\sJt|j||jz d|j|jS)z (Only for internal use!) Get a new completion by splitting this one. Used by `Application` when it needs to have a list of new completions after inserting the common prefix. rN)r!r$r()r"rr!r$r#)r'positions r)new_completion_from_positionz'Completion.new_completion_from_positionksT$---2228d&9&99;<LL++  r+)rNNrArA)r!r/r"intr$AnyFormattedText | Noner(rHr%r/r&r/returnNonerIr/)r5objectrIbool)rIrG)rIr)rErGrIr) r1 __module__ __qualname____doc__r*r3r6r:propertyr?r(rCrFr+r)rrs $ +/04 ((() ( . (  (( (2F  X33 ;; 88  r+rc.eZdZdZ d ddZddZy)ra3 Event that called the completer. :param text_inserted: When True, it means that completions are requested because of a text insert. (`Buffer.complete_while_typing`.) :param completion_requested: When True, it means that the user explicitly pressed the `Tab` key in order to view the completions. These two flags can be used for instance to implement a completer that shows some completions when ``Tab`` has been pressed, but not automatically when the user presses a space. (Because of `complete_while_typing`.) c,|r|rJ||_||_yr8) text_insertedcompletion_requested)r'rUrVs r)r*zCompleteEvent.__init__s$"&:;;+%9!r+ch|jjd|jd|jdS)Nz(text_inserted=z, completion_requested=r-)r0r1rUrVr2s r)r3zCompleteEvent.__repr__sM..))*/$:L:L9OOfgkhAhAgDDEF Fr+N)FF)rUrMrVrMrIrJrK)r1rNrOrPr*r3rRr+r)rr{s1 IN 9! 9AE 9  9Fr+rcBeZdZdZe ddZ ddZy)rz3 Base class for completer implementations. c# Kyw)a$ This should be a generator that yields :class:`.Completion` instances. If the generation of completions is something expensive (that takes a lot of time), consider wrapping this `Completer` class in a `ThreadedCompleter`. In that case, the completer algorithm runs in a background thread and completions will be displayed as soon as they arrive. :param document: :class:`~prompt_toolkit.document.Document` instance. :param complete_event: :class:`.CompleteEvent` instance. NrRr'documentcomplete_events r)get_completionszCompleter.get_completionss scDK|j||D]}| yw)z Asynchronous generator for completions. (Probably, you won't have to override this.) Asynchronous generator of :class:`.Completion` objects. N)r])r'r[r\items r)get_completions_asynczCompleter.get_completions_asyncs)((>B DJ s Nr[r r\rrIzIterable[Completion]r[r r\rrIz AsyncGenerator[Completion, None])r1rNrOrPrr]r`rRr+r)rrsP 2? $   2?  ) r+r) metaclasscHeZdZdZddZ ddZ d dZd dZy) rai Wrapper that runs the `get_completions` generator in a thread. (Use this to prevent the user interface from becoming unresponsive if the generation of completions takes too much time.) The completions will be displayed as soon as they are produced. The user can already select a completion, even if not all completions are displayed. c||_yr8 completer)r'rgs r)r*zThreadedCompleter.__init__s "r+c:|jj||Sr8rgr]rZs r)r]z!ThreadedCompleter.get_completionss~~--hGGr+cKttfd4d{}|23d{}|77 6dddd{7y#1d{7swYyxYww)z8 Asynchronous generator of completions. c<jjSr8ri)r\r[r'sr)z9ThreadedCompleter.get_completions_async.. s66xPr+Nr )r'r[r\async_generator completions``` r)r`z'ThreadedCompleter.get_completions_asyncshl (P   ! !$3 ! !j   !  !O  ! ! ! ! !s[A%9A%A=;=AA%=A A% A  A%A"A A"A%c"d|jdS)NzThreadedCompleter(r-rfr2s r)r3zThreadedCompleter.__repr__s#DNN#5Q77r+N)rgrrIrJrarbrKr1rNrOrPr*r]r`r3rRr+r)rrsP#H H2?H H <! <!2?<! )<!|8r+rc,eZdZdZ ddZddZy)rz9 A completer that doesn't return any completion. cgSr8rRrZs r)r]zDummyCompleter.get_completionss  r+cy)NzDummyCompleter()rRr2s r)r3zDummyCompleter.__repr__s!r+NrarK)r1rNrOrPr]r3rRr+r)rrs) 2?  "r+rcHeZdZdZddZ ddZ d dZd dZy) rz Completer class that can dynamically returns any Completer. :param get_completer: Callable that returns a :class:`.Completer` instance. c||_yr8 get_completer)r'rws r)r*zDynamicCompleter.__init__(s *r+c^|jxs t}|j||Sr8)rwrr]r'r[r\rgs r)r]z DynamicCompleter.get_completions+s-&&(BBr+cK|jxs t}|j||23d{}|7 6ywr8)rwrr`)r'r[r\rgrns r)r`z&DynamicCompleter.get_completions_async1sP&&( r-rvr2s r)r3zDynamicCompleter.__repr__;s)"4#5#5"8T=O=O=QJ J J K Js %1/1cK|jD]6}t|j||4d{}|23d{}|y776dddd{7Q#1d{7swYcxYwwr8)rr r`)r'r[r\rgrmr_s r)r`z&_MergedCompleter.get_completions_asyncqs{ I//.I   "1$J   /     se/A5A A5A A A A A A5 A  A  A5AA5 A2 &A)'A2 .A5N)rSequence[Completer]rIrJrarb)r1rNrOrPr*r]r`rRr+r)rrbsJ%K K2?K K   2?  ) r+rcJ|rddlm}|t|St|S)z Combine several completers into one. :param deduplicate: If `True`, wrap the result in a `DeduplicateCompleter` so that completions that would result in the same text will be deduplicated. )DeduplicateCompleter) deduplicaterr)rrrs r)rr}s&5#$4Z$@AA J ''r+cdfd }|Dcgc] }||s |}}t|t|k7rydd}t|Dcgc] }|| c}Scc}wcc}w)z7 Return the common prefix for all completions. cn|jd|j }jj|Sr8)r!r"text_before_cursorendswith)rnendr[s r)doesnt_change_before_cursorz?get_common_complete_suffix..doesnt_change_before_cursors4oo:!:!: :;**33C88r+rAc6|j|j dSr8)r!r")rns r) get_suffixz.get_common_complete_suffix..get_suffixs 9 99;<A*Q-> ??N?s AAA c||syt|}t|}t|D]\}}|||k7s|d|cS|S)NrA)minmax enumerate)stringss1s2irs r)rrsP \ \bM DAqBqEz"1v   r+N)F)rrrrMrIr)r[r rzSequence[Completion]rIr/)rz Iterable[str]rIr/)"rP __future__rabcrrtypingrrr r prompt_toolkit.documentr prompt_toolkit.eventloopr rprompt_toolkit.filtersrrr rr__all__rrrrrrrrrrrrRr+r)rs"'??,K:N ^ ^ BFF<"'"JR8 R8j "Y "WyW< 9 Fy8:?(#(26(($@@%9@@4 r+