)L i# dZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZddlmZddlmZmZmZmZmZmZdd lmZdd lmZdd lmZmZdd lm Z dd l!m"Z"ddl#m$Z$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.m/Z/ddl0m1Z1m2Z2ddl3m4Z4m5Z5ddl6m7Z7m8Z8m9Z9ddl:m;Z;mZ>m?Z?gdZ@ejeBZCGddeDZEGddeZFGddZGejdZIGdd ZJed!gdfZKed!geLfZMGd"d!ZNed#ed$eeedff%ZOd,d&ZPGd'd(eDZQd-d.d)ZRd-d.d*ZSd/d+ZTy)0zU Data structures for the Buffer. It holds the text, cursor position, history, etc... ) annotationsN)deque)Enum)wraps)AnyCallable CoroutineIterableTypeVarcast)get_app)run_in_terminal) AutoSuggest Suggestion) FastDictCache) ClipboardData) CompleteEvent Completer CompletionDummyCompleterget_common_complete_suffix)Document)aclosing) FilterOrBool to_filter)HistoryInMemoryHistory)SearchDirection SearchState) PasteModeSelectionState SelectionType)Eventto_str)ValidationError Validator)EditReadOnlyBufferBufferCompletionStateindentunindent reshape_textceZdZdZy)r(z.Attempt editing of read-only :class:`.Buffer`.N__name__ __module__ __qualname____doc__[/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/prompt_toolkit/buffer.pyr(r(6s4r5r(ceZdZdZdZdZdZy)ValidationStatezCThe validation state of a buffer. This is set after the validation.VALIDINVALIDUNKNOWNN)r0r1r2r3r9r:r;r4r5r6r8r8:sI EGGr5r8cVeZdZdZ d d dZd dZd dZd dZed dZ y)r*z; Immutable class that contains a completion state. Nc6||_|xsg|_||_yN)original_document completionscomplete_index)selfr?r@rAs r6__init__zCompletionState.__init__Gs%"3',"-r5c|jjd|jdt|jd|j dS)N(z, completions, index=)) __class__r0r?lenr@rArBs r6__repr__zCompletionState.__repr__Xs_..))*!D,B,B+ESTM]M]I^Haavw{xKxKwNNOP Pr5cv|jr-|#d|cxkrt|jksJJ||_yy)z Create a new :class:`.CompletionState` object with the new index. When `index` is `None` deselect the completion. Nr)r@rHrArBindexs r6 go_to_indexzCompletionState.go_to_index[sE   =A$FT5E5E1F$F FF$F FF"'D  r5c|j,|jj|jjfS|jj}|jj }|j |j}|jdk(r|}n|d|j}||jz|z}t|t|jz}||fS)zM Return (new_text, new_cursor_position) for this completion. Nr) rAr?textcursor_positiontext_before_cursortext_after_cursorr@start_positionrH)rBoriginal_text_before_cursororiginal_text_after_cursorcbeforenew_textnew_cursor_positions r6new_text_and_positionz%CompletionState.new_text_and_positiones    &))..0F0F0V0VV V*.*@*@*S*S ')-)?)?)Q)Q &  !4!45A1$445Gq7G7GH)CCH"%f+AFF "; 00 0r5cN|j|j|jSy)zi Return the current completion, or return `None` when no completion is selected. N)rAr@rIs r6current_completionz"CompletionState.current_completionys*    *##D$7$78 8r5)NN)r?rr@zlist[Completion] | NonerA int | NonereturnNoner_strrMr^r_r`)r_ztuple[str, int])r_zCompletion | None) r0r1r2r3rCrJrNr[propertyr]r4r5r6r*r*Bs^04%) -#---# -  -"P(1(r5r*z(\s+|".*?"|'.*?')c2eZdZdZ d ddZddZy)YankNthArgStatezT For yank-last-arg/yank-nth-arg: Keep track of where we are in the history. c.||_||_||_yr>)history_positionprevious_inserted_wordn)rBrhrjris r6rCzYankNthArgState.__init__s!1&<#r5c|jjd|jd|jd|jdS)Nz(history_position=z, n=z, previous_inserted_word=rF)rGr0rhrjrirIs r6rJzYankNthArgState.__repr__sa..))**d[dzd=Z?dSd>Z@dSd?ZA d{ d|d@ZBd}dAZC d~ ddBZD d~ ddCZEdSdDZFddEZGddFZHd[ddGZIddHZJ d ddIZKddJZLddKZM ddLZNdSdMZOy)r)a The core data structure that holds the text and cursor position of the current input line and implements all text manipulations on top of it. It also implements the history, undo stack and the completion state. :param completer: :class:`~prompt_toolkit.completion.Completer` instance. :param history: :class:`~prompt_toolkit.history.History` instance. :param tempfile_suffix: The tempfile suffix (extension) to be used for the "open in editor" function. For a Python REPL, this would be ".py", so that the editor knows the syntax highlighting to use. This can also be a callable that returns a string. :param tempfile: For more advanced tempfile situations where you need control over the subdirectories and filename. For a Git Commit Message, this would be ".git/COMMIT_EDITMSG", so that the editor knows the syntax highlighting to use. This can also be a callable that returns a string. :param name: Name for this buffer. E.g. DEFAULT_BUFFER. This is mostly useful for key bindings where we sometimes prefer to refer to a buffer by their name instead of by reference. :param accept_handler: Called when the buffer input is accepted. (Usually when the user presses `enter`.) The accept handler receives this `Buffer` as input and should return True when the buffer text should be kept instead of calling reset. In case of a `PromptSession` for instance, we want to keep the text, because we will exit the application, and only reset it during the next run. :param max_number_of_completions: Never display more than this number of completions, even when the completer can produce more (limited by default to 10k for performance). Events: :param on_text_changed: When the buffer text changes. (Callable or None.) :param on_text_insert: When new text is inserted. (Callable or None.) :param on_cursor_position_changed: When the cursor moves. (Callable or None.) :param on_completions_changed: When the completions were changed. (Callable or None.) :param on_suggestion_set: When an auto-suggestion text has been set. (Callable or None.) Filters: :param complete_while_typing: :class:`~prompt_toolkit.filters.Filter` or `bool`. Decide whether or not to do asynchronous autocompleting while typing. :param validate_while_typing: :class:`~prompt_toolkit.filters.Filter` or `bool`. Decide whether or not to do asynchronous validation while typing. :param enable_history_search: :class:`~prompt_toolkit.filters.Filter` or `bool` to indicate when up-arrow partial string matching is enabled. It is advised to not enable this at the same time as `complete_while_typing`, because when there is an autocompletion found, the up arrows usually browse through the completions, rather than through the history. :param read_only: :class:`~prompt_toolkit.filters.Filter`. When True, changes will not be allowed. :param multiline: :class:`~prompt_toolkit.filters.Filter` or `bool`. When not set, pressing `Enter` will call the `accept_handler`. Otherwise, pressing `Esc-Enter` is required. Nct| } t|}t| } t| } t|}|xs t|_||_||_||_||_||_| |_||_ | |_ | |_ | |_ ||_ ||_d|_| t!n||_d|_t'|||_t'|||_t'|||_t'|||_t'|||_t3t4d|_|j9|_|j=|_|jA|_!d|_"|jG| y)Nr )size)document)$rr completer auto_suggest validatortempfile_suffixtempfilenameaccept_handlercomplete_while_typingvalidate_while_typingenable_history_search read_only multilinemax_number_of_completions text_widthrhistory_Buffer__cursor_positionr$on_text_changedon_text_inserton_cursor_position_changedon_completions_changedon_suggestion_setrr_document_cache_create_auto_suggest_coroutine_async_suggester_create_completer_coroutine_async_completer_create_auto_validate_coroutine_async_validator_load_history_taskreset)rBrtrurrvrwrxryr{r|r}rsrzr~rrrrrrrs r6rCzBuffer.__init__s0!**? @ )*? @ )*? @i( i( "6n&6(".   ,&;"%:"%:""")B& -4O( !"/4D/.J-24-H9> ,: '6;4AW5X#05d)rHrPryid)rBrPs r6rJzBuffer.__repr__(sR tyy>B 99D99Sb>E)Dtyym74(%4|1MMr5c|r|j|xs t}|j|_d|_t j |_d|_g|_ d|_ d|_ d|_ d|_ d|_d|_g|_g|_|j$|j$j'd|_t)|j*g|_d|_y)zR :param append_to_history: Append current input to history first. Nr)append_to_historyrrQrvalidation_errorr8r;validation_stateselection_statemultiple_cursor_positionspreferred_columncomplete_stateyank_nth_arg_statedocument_before_paste suggestionhistory_search_text _undo_stack _redo_stackrcancelrrP_working_lines_Buffer__working_index)rBrsrs r6rz Buffer.reset0s   " " $)xz!)!9!99=8G8O8O7; 57&-17;;?7;".204 3524  " " .  # # * * ,"&+0*@ r5cjIdfd }tj|_dd}jj|yy)a Create task for populating the buffer history (if not yet done). Note:: This needs to be called from within the event loop of the application, because history loading is async, and we need to be sure the right event loop is active. Therefor, we call this method in the `BufferControl.create_content`. There are situations where prompt_toolkit applications are created in one thread, but will later run in a different thread (Ptpython is one example. The REPL runs in a separate thread, in order to prevent interfering with a potential different event loop in the main thread. The REPL UI however is still created in the main thread.) We could decide to not support creating prompt_toolkit objects in one thread and running the application in a different thread, but history loading is the only place where it matters, and this solves it. NcKjj23d{}jj|xjdz c_:756yw)Nr )rloadr appendleftr)itemrBs r6 load_historyz;Buffer.load_history_if_not_yet_loaded..load_historysQ"&,,"3"3"5..$''2248((A-(."5s%AAAA2AAAc |jy#tj$rYyt$rYyt$rt j dYywxYw)z Handle `load_history` result when either done, cancelled, or when an exception was raised. zLoading history failedN)resultasyncioCancelledError GeneratorExit BaseExceptionlogger exception)fs r6load_history_donez@Buffer.load_history_if_not_yet_loaded..load_history_donesP ?HHJ--$$?$$%=>?sAAAAr_r`)rzasyncio.Future[None]r_r`)rrcreate_background_taskadd_done_callback)rBrrs` r6load_history_if_not_yet_loadedz%Buffer.load_history_if_not_yet_loadedqsP*  " " * . '.i&F&F|~&VD # ?*  # # 5 56G H= +r5c|j}|j}||}|||<t|t|k7ry||k7ryy)z=set text at current working_index. Return whether it changed.TF) working_indexrrH)rBvaluer working_linesoriginal_values r6 _set_textzBuffer._set_textsR** ++ &}5', m$ u:^, ,  n $r5cZ|j}td||_|j|k7S)z/Set cursor position. Return whether it changed.r)rmax)rBroriginal_positions r6_set_cursor_positionzBuffer._set_cursor_positions. 22!$Q%%):::r5c4|j|jSr>)rrrIs r6rPz Buffer.texts""4#5#566r5c|jt|kDrt||_|jr t|j |}|r|j d|_yy)z Setting text. (When doing this, make sure that the cursor_position is valid for this text. text/cursor_position should be consistent at any time, otherwise set a Document instead.) N)rQrHr~r(r _text_changedrrBrchangeds r6rPz Buffer.textsc   #e* ,#&u:D  >> $& &..'     (,D $ r5c|jSr>)rrIs r6rQzBuffer.cursor_positions%%%r5ct|tsJ|t|jkDrt|j}|dkrd}|j |}|r|j yy)z* Setting cursor position. rN) isinstancernrHrPr_cursor_position_changedrs r6rQzBuffer.cursor_positionsc %%%% 3tyy> ! NE 19E++E2   ) ) + r5c|jSr>)rrIs r6rzBuffer.working_indexs###r5c`|j|k7r||_d|_|jyy)Nr)rrQrrBrs r6rzBuffer.working_indexs3   5 (#(D $%D    )r5cNd|_tj|_d|_d|_d|_d|_d|_d|_ |jj|jr9|jr(tj|j!yyyr>)rr8r;rrrrrrrrfirervr|rrrrIs r6rzBuffer._text_changeds $ / 7 7""&%)"# $ !!# >>d88: I , ,T-B-B-D E;>r5cpd|_d|_d|_d|_|jj yr>)rrrrrrrIs r6rzBuffer._cursor_position_changeds:#"&%)"!% '',,.r5cb|j|j|j|jfS)z Return :class:`~prompt_toolkit.document.Document` instance from the current text, cursor position and selection state. )rrPrQrrIs r6rszBuffer.document+s1 ## IIt++T-A-A A  r5c&|j|y)z Set :class:`~prompt_toolkit.document.Document` instance. This will set both the text and cursor position at the same time, but atomically. (Change events will be triggered only after both have been set.) N) set_documentrs r6rszBuffer.document5s % r5c|s|jr t|j|j}|j |j }|r|j d|_|r|jyy)a3 Set :class:`~prompt_toolkit.document.Document` instance. Like the ``document`` property, but accept an ``bypass_readonly`` argument. :param bypass_readonly: When True, don't raise an :class:`.EditReadOnlyBuffer` exception, even when the buffer is read-only. .. warning:: When this buffer is read-only and `bypass_readonly` was not passed, the `EditReadOnlyBuffer` exception will be caught by the `KeyProcessor` and is silently suppressed. This is important to keep in mind when writing key bindings, because it won't do what you expect, and there won't be a stack trace. Use try/finally around this function if you need some cleanup code. N) r~r(rrPrrQrrr)rBrbypass_readonly text_changedcursor_position_changeds r6rzBuffer.set_document?sq&4>>#3$& &~~ejj1 "&";";E I *r5c |jsJt|j|jjg\}}|jd|}|j||j }|j|d}|Dcgc]}|j d|z}}t|dj|z|zt|dj|ddzdz |_ ycc}w)z* Join the selected lines. Nrrmrlr rPrQ) rsortedrQoriginal_cursor_positionrP splitlinesrrrrHrs)rBrrrrXrafterls r6join_selected_lineszBuffer.join_selected_lines1s####  ! !4#7#7#P#P Q r6E" %#..0 "#5::q#*::!"''%.(50s)< <=A  ;s<C"c|j}|dk\rR|j|dz }|j|dz }|jd|dz |z|z|j|dz|_yy)zA Swap the last two characters before the cursor. r N)rQrP)rBposrrs r6swap_characters_before_cursorz$Buffer.swap_characters_before_cursorIsn"" !8 #'"A #'"A )C!G,q014tyyFDI r5cx|t|jkr"||_t|j|_yy)z1 Go to this item in the history. N)rHrrrPrQrLs r6 go_to_historyzBuffer.go_to_historyUs4 3t**+ +!&D #&tyy>D  ,r5c>|jrt|jj}|jjd}nG|jj|dz k(rd}|r'yt |dz |jj|z}|j |yy)zd Browse to the next completions. (Does nothing if there are no completion.) Nrr )rrHr@rAmingo_to_completion)rBrdisable_wrap_aroundcompletions_countrMs r6rzBuffer.complete_next]s    #D$7$7$C$C D ""119$$337H17LL&%)4+>+>+M+MPU+U  ! !% ( r5c4|jr|jjdk(rd}|r]y|jj#t|jjdz }n#t d|jj|z }|j |yy)zh Browse to the previous completions. (Does nothing if there are no completion.) rNr )rrArHr@rr1)rBrr2rMs r6r zBuffer.complete_previousts   ""11Q6&$$33;D//;;? $r5c|jr|jdd|_|j|j |j |j y)z, Insert a given completion. N)rr1rrT insert_textrP)rB completions r6apply_completionzBuffer.apply_completionsN     ! !$ '" !!:#<#<"<= )r5c|jr)|j|jj|_yyd|_y)zy Set `history_search_text`. (The text before the cursor will be used for filtering the history.) N)r}rrsrRrIs r6_set_history_searchzBuffer._set_history_searchs=  % % '''/+/==+K+K(0(,D $r5cr|jduxs(|j|j|jS)z True when the current entry matches the history search. (when we don't have history search, it's also True.) N)rrr@)rBrDs r6_history_matcheszBuffer._history_matchess= ''4/ 43F3Fq3I3T3T  $ $4  r5cD|jd}t|jdzt|jD](}|j |r||_|dz}d}|dk(s(n|r5d|_|xj |jjz c_yy)zl Move forwards through the history. :param count: Amount of items to move forward. Fr TrN) rOrangerrHrrQrQrsrrBrfound_somethingrDs r6rzBuffer.history_forwards   " t))A-s43F3F/GH A$$Q'%&" "&z   #$D  DMM$J$J$L L  r5c|jd}t|jdz ddD](}|j|r||_|dz}d}|dk(s(n|rt |j |_yy)z1 Move backwards through history. Fr rlTrN)rOrSrrQrHrPrQrTs r6r zBuffer.history_backwards   " t))A-r26 A$$Q'%&" "&z   #&tyy>D  r5c|t|tsJ|jj}t |sy|j t |rdnd}n |j }|||_|jdz }| t |kDrd}||}tj|Dcgc]}|j}}|Dcgc]}|s| }} ||j} |jr$|jt |j|j| | |_ ||_||_ycc}wcc}w#t$rd} YnwxYw)ay Pick nth word from previous history entry (depending on current `yank_nth_arg_state`) and insert it at current position. Rotate through history if called repeatedly. If no `n` has been given, take the first argument. (The second word.) :param n: (None or int), The index of the word from the previous line to take. Nrlr )rjrm)rrnr get_stringsrHrrfrjrh_QUOTED_WORDS_RErr?rrirrK) rBrj_yank_last_arghistory_stringsrInew_poslinewwordswords r6 yank_nth_argzBuffer.yank_nth_arg$sPyJq#...,,224?#   " " *#NbBE++E =EG((1, 8c/* *Gw'$4$:$:4$@AqAA!'qQ'' >D  ' '  % %c%*F*F&G H (,$!("'!B' D s$)D;EEE EEc*|j|dy)zp Like `yank_nth_arg`, but if no argument has been given, yank the last word by default. T)rjrZN)ra)rBrjs r6 yank_last_argzBuffer.yank_last_argWs Ad3r5c:t|j||_y)zR Take the current cursor position as the start of this selection. N)r"rQr)rBselection_types r6start_selectionzBuffer.start_selection^s .d.B.BNSr5c`|jj\}}|r||_d|_|S)a8 Copy selected text and return :class:`.ClipboardData` instance. Notice that this doesn't store the copied data on the clipboard yet. You can store it like this: .. code:: python data = buffer.copy_selection() get_app().clipboard.set_data(data) N)rs cut_selectionr)rB_cut new_documentclipboard_datas r6copy_selectionzBuffer.copy_selectionfs3(,}}'B'B'D$ n (DM#r5c&|jdS)zS Delete selected text and return :class:`.ClipboardData` instance. T)ri)rlrIs r6rhzBuffer.cut_selectionys"""--r5ct|tsJ|tjtjtj fvsJ|j }|j j||||_||_y)z5 Insert the data from the clipboard. ) paste_moderN) rrr! VI_BEFOREVI_AFTEREMACSrspaste_clipboard_datar)rBdatarorr?s r6rszBuffer.paste_clipboard_dataso$ ...i1193E3EyWWWW MM :: Zu;  &7"r5c||r)|jd|jjzy|jdy)z? Insert a line ending at the current position. rN)rKrs"leading_whitespace_in_current_line)rB copy_margins r6newlinezBuffer.newlines2    TDMM$T$TT U   T "r5c|r|jjdz}nd}|xj|jjz c_|j ||xjdzc_y)z: Insert a new line above the current one. rr N)rsrvrQrrKrBrwinserts r6insert_line_abovezBuffer.insert_line_aboves] ]]EELFF  H H JJ   !r5c|rd|jjz}nd}|xj|jjz c_|j |y)z: Insert a new line below the current one. rN)rsrvrQrrKrzs r6insert_line_belowzBuffer.insert_line_belowsL DMMLLLFF  F F HH  r5ct|j}|j}|rD|||t|z}d|vr|d|jd}|d||z||t|zdz}n|d||z||dz}|r|jt|z} n |j} t || |_|r|j j|jr7|jr'tj|j|jr(tj|jyyy)z Insert characters at cursor position. :param fire_event: Fire `on_text_insert` event. This is mainly used to trigger autocompletion while typing. rN)rPrQrHfindrrsrrrtr{rrrrur) rBrt overwrite move_cursor fire_eventotextocposoverwritten_textrPcposs r6rKzBuffer.insert_texts? $$  %UUSY->? ''#34Q6F6K6KD6Q#R %=4'% 001F1F1HI   001F1F1HI! r5c|jr~|jj\}}||jk7rD|jj |j|j ft |||_y|jr}yy)NrQ)rpoprPrrrQrrsrBrPr+s r6undoz Buffer.undosr ((,,.ID#tyy   ''D4H4H(IJ!)s C r5c|jrB|jd|jj\}}t|||_yy)NF)rr)rrrrrsrs r6redoz Buffer.redosI     # #U # ;((,,.ID#$T3?DM r5c|jtjk7r|jtjk(S|jr& |jj |j tj|_d|_y#t$r`}|r8ttd|jt|j|_ tj|_||_Yd}~yd}~wwxYw)zv Returns `True` if valid. :param set_cursor: Set the cursor position, if an error was found. rNFT)rr8r;r9rvvalidatersr&r0rrQrHrPr:r)rB set_cursores r6rzBuffer.validates  O$;$; ;((O,A,AA A >> '' 6!0 5 5 $# +.Aq0013tyy>,D()8(?(?%()% s%B C3AC..C3cK |jtjk7ryd}|j}|jr> |jj |jd{|j|k7rw|rtj|_ntj|_||_ tj7a#t $r }|}Yd}~od}~wwxYww)a Asynchronous version of `validate()`. This one doesn't set the cursor position. We have both variants, because a synchronous version is required. Handling the ENTER key needs to be completely synchronous, otherwise stuff like type-ahead is going to give very weird results. (People could type input while the ENTER key is still processed.) An asynchronous version is required if we have `validate_while_typing` enabled. N) rr8r;rsrvvalidate_asyncr&r:r9rr invalidate)rBerrorrsrs r6_validate_asynczBuffer._validate_async"s$$(?(??E}}H~~..77 FFF ==H,(7(?(?%(7(=(=%$)D ! I "7G&EsA:C!(C %C&C *AC!C CCC!CC!c|jr^|jj}t|r|d|jk7r&|jj |jyyy)z: Append the current input to the history. rlN)rPrrXrH append_string)rBr[s r6rzBuffer.append_to_historyLsV 99"ll668O'?2+>$))+K **4995,L r5c |dkDsJ|j |j |j d  fd }j}j}t |D]}|||}|y|\}}||j fS)z Execute search. Return (working_index, cursor_position) tuple when this search is applied. Returns `None` when this text cannot be found. rcptjk(r|j}|%|t|j|j |zfSt |dztjdzD]c}|tjz}tj|d}|jd}|K|t|j|fcSy|j}|%|t|j|j |zfSt |dz ddD]}|tjz}tj|tj|}|j}|`|t|jt|j|zfcSy) zd Do search one time. Return (working_index, document) or `None` )include_current_position ignore_caseNr rT)rrl) rFORWARDrrrPrQrSrHrfind_backwards) rrs new_indexrD directionrrrBrPs r6 search_oncez#Buffer._search..search_oncegsO333$MM-E +* (% 0H0H90TU#=1#4c$:M:M6NQR6RSKS!4!455#+D,?,?,BA#F$,MM 4[%2% %0$%x y'I#JJKD/%33Dk3R (% 0H0H90TU #=1#4b"= S!4!455#+ //2C8K8KA8N4O$%-$;$; k%<% %0 ! (HMM8JY8V W$ r5N)rrnrsrr_ztuple[int, Document] | None)rPrrrrsrSrQ) rB search_staterrrrrs_rrrrPs ` ` @@@r6_searchzBuffer._searchWsqyy   ** "..0 : : *2:  (: : z** ==u 1A 9F~*0' x  1x7788r5c|j|d}| |jS|\}}||jk(r |j}nd}t |j |||S)a# Return a :class:`~prompt_toolkit.document.Document` instance that has the text/cursor position for this search, if we would apply it. This will be used in the :class:`~prompt_toolkit.layout.BufferControl` to display feedback while searching. T)rN) selection)rrsrrrr)rBr search_resultrrQrs r6document_for_searchzBuffer.document_for_searchso \D Q  == -: *M? 2 22 00  ##M2Oy r5cT|j|||}| |jS|\}}|S)z Get the cursor position for this search. (This operation won't change the `working_index`. It's won't go through the history. Vi text objects can't span multiple items.) rr)rrQrBrrrrrrQs r6get_search_positionzBuffer.get_search_positionsD 3KSX%   '' '-: *M?" "r5cX|j|||}||\}}||_||_yy)zi Apply search. If something is found, set `working_index` and `cursor_position`. rN)rrrQrs r6 apply_searchzBuffer.apply_searchsG 3KSX%   $-: *M?!.D #2D  %r5cd|_yr>)rrIs r6exit_selectionzBuffer.exit_selections #r5ct|j}tj|\}t j ||j jdt j|dfd }|fS)za Simple (file) tempfile implementation. Return (tempfile, cleanup_func). utf-8c0tjyr>)osunlink)filenamesr6cleanupz/Buffer._editor_simple_tempfile..cleanups IIh r5r) r%rwrxmkstemprwriterPencodeclose)rBsuffix descriptorrrs @r6_editor_simple_tempfilezBuffer._editor_simple_tempfilese ,,-'//7 H TYY--g67    r5cZt|j}|s|jSt|}tj j |\}}tj j|r|dd}tj|r tj j|t jtj j|}t|dd5}|j|jddddfd }||fS#1swYxYw)Nr r^r)encodingc0tjyr>)shutilrmtree)dirpathsr6rz0Buffer._editor_complex_tempfile..cleanups MM' "r5r)r%rxrrbrpathrisabsmkdtemprmakedirsopenrrP)rBheadtailheadtailrfhrrs @r6_editor_complex_tempfilezBuffer._editor_complex_tempfiles$--(//1 1x=WW]]8, d 77== 8D""$ ggll7D1G G77<<. (C' 2 b HHTYY   #    s 3D!!D*cjr tjrj\nj \dfd }t j |S)ze Open code in editor. This returns a future, and runs in a thread executor. cvK tfddd{}|rwtd5}|jjd}|j dr|dd}t |t |_dddrjy7#1swY%xYw#wxYww) Nc&jSr>)_open_file_in_editor)rrBsr6z4Buffer.open_in_editor..run..6sD55h?r5T) in_executorrbrrrlr") rrreaddecodeendswithrrHrsvalidate_and_handle)successrrP cleanup_funcrrBrs r6runz"Buffer.open_in_editor..run/s  !0?T! h-W vvxw7 ==.#'9D(0dCPTI(V W+002- WW sDB9B-BB-AB!=B-B9B-!B*&B-- B66B9r)r~r(rxrrrr)rBrrrrs`` @@r6open_in_editorzBuffer.open_in_editor sh >> $& & ==%)%B%B%D "Hl%)%A%A%C "Hl  <y//66r5c*tjjd}tjjd}||dddddg}|D]8}|s tjt j ||gz}|dk(cSy #t$rYGwxYw) zc Call editor executable. Return True when we received a zero return code. VISUALEDITORz/usr/bin/editorz /usr/bin/nanoz /usr/bin/picoz /usr/bin/viz/usr/bin/emacsrF)renvironget subprocesscallshlexrOSError)rBrvisualeditoreditorsr returncodes r6rzBuffer._open_file_in_editorOs))          A",Q8*1L!MJ%?*  s0B BBc ||z|zdksJtj|j||||xs tdy)z Start asynchronous autocompletion of this buffer. (This will do nothing if a previous completion was still in progress.) r T)completion_requested) select_first select_lastinsert_common_partcomplete_eventN)rrrr)rBrrrrs r6start_completionzBuffer.start_completionssYk),>>!CCC ((  ! !)'#5- < d; "  r5cNddt d dfd }|S)z Create function for asynchronous autocompletion. (This consumes the asynchronous completer generator, which possibly runs the completion algorithm in another thread.) cn|j}|t||jzd}||jk(S)z Return `True` if applying this completion doesn't have any effect. (When it doesn't insert any new text. N)rRrHrTrP)rsrLrR replaced_texts r6completion_does_nothingzCBuffer._create_completer_coroutine..completion_does_nothingsB "*!| D cgc]} | j-t| c} | ddj/| yd_yt| dk(rj'dyyyjj0|j0k(ryjj0j3|j0rt4y7A7967#1d{7swYxYw#|jj j#wxYwcc} ww) NT) text_inserted)r?c"jk(S)ziKeep retrieving completions. Input text has not yet changed while generating completions.)r)rrBsr6proceedzLBuffer._create_completer_coroutine..async_completer..proceeds**n<.async_completer..refresh_while_loadings\//446"((*!--,,,(--/// -/s$AA)A%A)A' A)'A)r rr;r_rr)rsrrrtr*rr$ ensure_futurerget_completions_asyncr@rr<rHrrrrrAr1rrKnew_completion_from_positionr8rRr@_Retry)rrrrrsrr refresh_taskasync_generatorrLr@ common_partrWrrrrBs @@r6async_completerz;Buffer._create_completer_coroutine..async_completers}}H+P}4/PN""$..-t}}MN"0D  = %]]_N 0#001F1HIL 3#NN88>R""$,; " "j&2299*E&**, 'y!  : :;#==>"!""$##%++002(44K;1$)@+a.* Ny++**99E#*.D'//446  ))!, ))#k*:Q*>?'" >s;?O P.KN !11k1J26D/{+q0 11!411(>==33x7R7RR==33>>//!L{" "O""""$##%++002^.sBM)L!>K??L!L L L L AL %L & L!1L2L!6D M!M"BM?L!LL L! LL LL!!,M  M)rsrrLrr_rFFFN rrrrrrrzCompleteEvent | Noner_r`_only_one_at_a_time)rBr rs` @r6rz"Buffer._create_completer_coroutinesf 4 !& %',37 J !J !J !!%J !1 J !  J ! J !Xr5c&tdfd }|S)zl Create function for asynchronous auto suggestion. (This can be in another thread.) cKj}js jsyjj|d{}j|k(r"|_jj yt 7;wr>)rsrruget_suggestion_asyncrrr)rsrrBs r6async_suggestorz>Buffer._create_auto_suggest_coroutine..async_suggestor3ss}}Hd&7&7#00EEdHUUJ}}(",&&++- VsABB )rrIsr6async_validatorz?Buffer._create_auto_validate_coroutine..async_validatorPs&&( ( (s rr )rBrs` r6rz&Buffer._create_auto_validate_coroutineHs  )  )r5c|jd}|rD|jr|j|}nd}|j|s|jyyy)z? Validate buffer and handle the accept action. T)rFN)rrzrr)rBvalid keep_texts r6rzBuffer.validate_and_handleVsY  . "" //5 !  " " $  r5)NNNNrmrmrmFFFNNFTi'NNNNN)*rtzCompleter | NoneruzAutoSuggest | NonerzHistory | NonervzValidator | Nonerwstr | Callable[[], str]rxrryrbr{rr|rr}rrsDocument | NonerzzBufferAcceptHandler | Noner~rrrrrnrBufferEventHandler | Nonerrrrrrrrr_r`ra)NF)rsrrrr_r`r)rrbr_r)rrnr_r)rrbr_r`)r_rn)rrnr_r`)r_r)rrr_r`)F)rrrrr_r`r)T)rrr_r`)rz Iterable[int]rCallable[[str], str]r_rb)rrr_r`)rrnrrnrrr_r`r )rrnr_r`)r F)rrnrrr_r`)rrnr_rb)r)rrbr_r`)rMrnr_r`)rrnr2rr_r`)r@zlist[Completion]r_r*rc)rLrr_r`)rDrnr_r)rjr^rZrr_r`r>)rjr^r_r`)rer#r_r`)rirr_r)r_r)rtrror!rrnr_r`)rwrr_r`)FTT) rtrbrrrrrrr_r`)rrr_r)Fr )rr rrrrnr_ztuple[int, int] | None)rr r_r)Tr )rr rrrrnr_rn)rr rrrrnr_r`)r_ztuple[str, Callable[[], None]])rrr_zasyncio.Task[None])rrbr_rr r )r_z(Callable[..., Coroutine[Any, Any, None]])r_z'Callable[[], Coroutine[Any, Any, None]])Pr0r1r2r3rCrJrrrrrdrPsetterrQrrrrsrrrrrrrrrr rrrrr r(r,r.rr r6r8rGr1rMrOrQrr rarcr# CHARACTERSrfrlrhr!rrrsrxr|r~rKrrrrrrrrrrrrrrrrrrrr4r5r6r)r)st9z'++/"&&*35,..3.3.3$(59"'"&).5948@D<@7;+O&#O&)O& O& $ O& 1 O&*O&O& ,O& ,O& ,O&"O&3O& O& O& $'!O&"3#O&$2%O&&%>'O&(!:)O&*5+O&, -O&bNKP?!'?!CG?! ?!B3In(;77 [[,,2&&,,"$$!!F(/$  __!!!,F))"  * 1   @    ! 7K  *TU00NSSSFJS S&NSSSFJS S$,   0 G2)0;@))37) ),' #"!H$" * , M02*1(f4/<.F.FT+T T&.!* 777 7  7*# " !   2J2J2J 2J  2J  2Jh @>(#T 6*/ V9!V9#'V9 V9 V9p8*. #!##'# # #0*. 3!3#'3 3  3&$! !:-7^"L#!#(/3    !  -    0`D6  0 r5_T.)boundcTdtdfd }tt|S)a Decorator that only starts the coroutine only if the previous call has finished. (Used to make sure that we have only one autocompleter, auto suggestor and validator running at a time.) When the coroutine raises `_Retry`, it is restarted. FctKryd |i|d{ dy7#t$rY#wxYw#dwxYww)NTF)r)rkw coroutinerunnings r6 new_coroutinez*_only_one_at_a_time..new_coroutinevs\    #Q-"--- G . Gs481 " "8" .1.158)rrr$rr_r)rr r )r%r'r&s` @r6rrls0G 9( M ""r5ceZdZdZy)rzRetry in `_only_one_at_a_time`.Nr/r4r5r6rrs%r5rc@|jj}|jj}t||}d|z|j |fd}t |t |j |d|_|xj|tzz c_y)z3 Indent text of a :class:`.Buffer` object.  c|zSr>r4)r'indent_contents r6rzindent..s NQ)r@rHr)rPremover,s r6 transformzunindent..transforms1 ??6 "F & &;;= r5rN)rPrbr_rbr-) r/r0r1rr2r3r4r8rYr,s @r6r,r,s//55K//55Kx(Je^N!%%j)r[sC # DD(81 $,-0?? 2    8 $55d??D2::67 ^ ^ xj$./z4/0KK\6 T#yc4'@"@AB#D&Y&@&@6- r5