Ë
    V.j# ã            	      ó¬  — d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZ ddlmZ ddlmZ ddlmZmZmZmZmZmZ dd	lmZ dd
l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%m&Z&m'Z'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z< ddl=m>Z>m?Z? g d¢Z@ ej‚                  eB«      ZC G d„ deD«      ZE G d„ de«      ZF G d„ d«      ZG ej�                  d«      ZI G d„ d «      ZJed!gdf   ZKed!geLf   ZM G d"„ d!«      ZN ed#ed$eeedf   f   ¬%«      ZOd,d&„ZP G d'„ d(eD«      ZQd-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)ÚAnyÚCallableÚ	CoroutineÚIterableÚTypeVarÚcasté   )Úget_app)Úrun_in_terminal)ÚAutoSuggestÚ
Suggestion)ÚFastDictCache)ÚClipboardData)ÚCompleteEventÚ	CompleterÚ
CompletionÚDummyCompleterÚget_common_complete_suffix)ÚDocument)Úaclosing)ÚFilterOrBoolÚ	to_filter)ÚHistoryÚInMemoryHistory)ÚSearchDirectionÚSearchState)Ú	PasteModeÚSelectionStateÚSelectionType)ÚEventÚto_str)ÚValidationErrorÚ	Validator)ÚEditReadOnlyBufferÚBufferÚCompletionStateÚindentÚunindentÚreshape_textc                  ó   — e Zd ZdZy)r(   z.Attempt editing of read-only :class:`.Buffer`.N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úWC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\site-packages\prompt_toolkit/buffer.pyr(   r(   6   s   „ Ú4r5   r(   c                  ó   — e Zd ZdZdZdZdZy)ÚValidationStatezCThe validation state of a buffer. This is set after the validation.ÚVALIDÚINVALIDÚUNKNOWNN)r0   r1   r2   r3   r9   r:   r;   r4   r5   r6   r8   r8   :   s   „ ÙIà€EØ€GØ�Gr5   r8   c                  óV   — e Zd ZdZ	 	 d	 	 	 	 	 	 	 d	d„Zd
d„Zdd„Zdd„Zedd„«       Z	y)r*   z;
    Immutable class that contains a completion state.
    Nc                ó6   — || _         |xs g | _        || _        y ©N)Úoriginal_documentÚcompletionsÚcomplete_index)Úselfr?   r@   rA   s       r6   Ú__init__zCompletionState.__init__G   s%   € ð "3ˆÔð 'Ò,¨"ˆÔð -ˆÕr5   c                ó”   — | j                   j                  › d| j                  ›dt        | j                  «      ›d| j
                  ›d�S )NÚ(z, <z> completions, index=Ú))Ú	__class__r0   r?   Úlenr@   rA   ©rB   s    r6   Ú__repr__zCompletionState.__repr__X   s_   € Ø—.‘.×)Ñ)Ð*¨!¨D×,BÑ,BÐ+EÀSÌÈT×M]ÑM]ÓI^ÐHaÐavÐw{÷  xKñ  xKð  wNð  NOð  Pð  	Pr5   c                óv   — | j                   r-|�#d|cxk  rt        | j                   «      k  sJ ‚ J ‚|| _        yy)zŒ
        Create a new :class:`.CompletionState` object with the new index.

        When `index` is `None` deselect the completion.
        Nr   )r@   rH   rA   ©rB   Úindexs     r6   Úgo_to_indexzCompletionState.go_to_index[   sE   € ð ×ÒØ�= A¨Ô$F´°T×5EÑ5EÓ1FÒ$FÐFÐFÐ$FÐFÐFØ"'ˆDÕð r5   c                ó¬  — | j                   €,| j                  j                  | j                  j                  fS | j                  j                  }| j                  j
                  }| j                  | j                      }|j                  dk(  r|}n|d|j                   }||j                  z   |z   }t        |«      t        |j                  «      z   }||fS )zM
        Return (new_text, new_cursor_position) for this completion.
        Nr   )	rA   r?   ÚtextÚcursor_positionÚtext_before_cursorÚtext_after_cursorr@   Ústart_positionrH   )rB   Úoriginal_text_before_cursorÚoriginal_text_after_cursorÚcÚbeforeÚnew_textÚnew_cursor_positions          r6   Únew_text_and_positionz%CompletionState.new_text_and_positione   sÉ   € ð ×ÑÐ&Ø×)Ñ)×.Ñ.°×0FÑ0F×0VÑ0VÐVÐVà*.×*@Ñ*@×*SÑ*SÐ'Ø)-×)?Ñ)?×)QÑ)QÐ&à× Ñ  ×!4Ñ!4Ñ5ˆAØ×Ñ 1Ò$Ø4‘à4Ð5G°q×7GÑ7GÐH�à §¡‘Ð)CÑCˆHÜ"% f£+´°A·F±F³Ñ";ÐØÐ0Ð0Ð0r5   c                óN   — | j                   �| j                  | j                      S y)zi
        Return the current completion, or return `None` when no completion is
        selected.
        N)rA   r@   rI   s    r6   Úcurrent_completionz"CompletionState.current_completiony   s*   € ð ×ÑÐ*Ø×#Ñ# D×$7Ñ$7Ñ8Ð8Ør5   )NN)r?   r   r@   zlist[Completion] | NonerA   ú
int | NoneÚreturnÚNone©r_   Ústr©rM   r^   r_   r`   )r_   ztuple[str, int])r_   zCompletion | None)
r0   r1   r2   r3   rC   rJ   rN   r[   Úpropertyr]   r4   r5   r6   r*   r*   B   s^   „ ñð 04Ø%)ð	-à#ð-ð -ð-ð #ð	-ð
 
ó-ó"Pó(ó1ð( òó ñr5   r*   z(\s+|".*?"|'.*?')c                  ó2   — e Zd ZdZ	 d	 	 	 	 	 	 	 dd„Zdd„Zy)ÚYankNthArgStatezT
    For yank-last-arg/yank-nth-arg: Keep track of where we are in the history.
    c                ó.   — || _         || _        || _        y r>   )Úhistory_positionÚprevious_inserted_wordÚn)rB   rh   rj   ri   s       r6   rC   zYankNthArgState.__init__Œ   s   € ð !1ˆÔØ&<ˆÔ#Øˆ�r5   c                ó‚   — | j                   j                  › d| j                  ›d| j                  ›d| j                  ›d�S )Nz(history_position=z, n=z, previous_inserted_word=rF   )rG   r0   rh   rj   ri   rI   s    r6   rJ   zYankNthArgState.__repr__“   sa   € Ø—.‘.×)Ñ)Ð*Ð*<¸T×=RÑ=RÐ<UÐUYÐZ^×Z`ÑZ`ÐYcÐc|ð  ~B÷  ~Yñ  ~Yð  }\ð  \]ð  ^ð  	^r5   N)r   éÿÿÿÿÚ )rh   Úintrj   rn   ri   rb   r_   r`   ra   )r0   r1   r2   r3   rC   rJ   r4   r5   r6   rf   rf   ‡   s9   „ ñð
 UWðØ #ðØ,/ðØNQðà	óô^r5   rf   r)   c                  óÀ  — e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dOd„ZdPd„Z	 dQ	 	 	 	 	 dRd„ZdSd„ZdTd„ZdUd„Z	e
dPd	„«       Zej                  dVd
„«       Ze
dWd„«       Zej                  dXd„«       Ze
dWd„«       Zej                  dXd„«       ZdSd„ZdSd„Ze
dYd„«       Zej                  dZd„«       Zd[d\d„Ze
d]d„«       Zd^d_d„Z	 	 	 	 	 	 d`d„Zdad„Z	 	 	 	 	 	 	 	 dbd„Zdcddd„Zdcddd„Zdcddd„Zdcddd„Z	 de	 	 	 	 	 dfd„Z	 de	 	 	 	 	 dfd„Zdcdgd „Zdcdgd!„Zdhdid"„Z dhdid#„Z!dSd$„Z"djd%„Z#dedkd&„Z$	 de	 	 	 	 	 dkd'„Z%dSd(„Z&dld)„Z'dSd*„Z(dmd+„Z)dnd,„Z*dSd-„Z+dod.„Z,dcddd/„Z-dcddd0„Z.dQdpd1„Z/dqdrd2„Z0e1jd                  f	 	 	 dsd3„Z3d[dtd4„Z4dud5„Z5e6jn                  df	 	 	 	 	 	 	 dvd6„Z8d^dwd7„Z9d^dwd8„Z:d^dwd9„Z;	 	 	 dx	 	 	 	 	 	 	 	 	 dyd:„Z<dSd;„Z=dSd<„Z>d[dzd=„Z?dSd>„Z@dSd?„ZA	 	 d{	 	 	 	 	 	 	 d|d@„ZBd}dA„ZC	 	 d~	 	 	 	 	 	 	 ddB„ZD	 	 d~	 	 	 	 	 	 	 d€dC„ZEdSdD„ZFd�dE„ZGd�dF„ZHd[d‚dG„ZIdƒdH„ZJ	 	 	 	 d„	 	 	 	 	 	 	 	 	 d…dI„ZKd†dJ„ZLd‡dK„ZM	 	 d‡dL„ZNdSdM„ZOy)ˆ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.
    Nc                ó  — t        |
«      }
t        |«      }t        |	«      }	t        |«      }t        |«      }|xs
 t        «       | _        || _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        || _        || _        || _        d| _        |€
t!        «       n|| _        d| _        t'        | |«      | _        t'        | |«      | _        t'        | |«      | _        t'        | |«      | _        t'        | |«      | _        t3        t4        d¬«      | _        | j9                  «       | _        | j=                  «       | _        | jA                  «       | _!        d | _"        | jG                  |¬«       y )Nr   é
   )Úsize)Údocument)$r   r   Ú	completerÚauto_suggestÚ	validatorÚtempfile_suffixÚtempfileÚnameÚaccept_handlerÚcomplete_while_typingÚvalidate_while_typingÚenable_history_searchÚ	read_onlyÚ	multilineÚmax_number_of_completionsÚ
text_widthr   ÚhistoryÚ_Buffer__cursor_positionr$   Úon_text_changedÚon_text_insertÚon_cursor_position_changedÚon_completions_changedÚon_suggestion_setr   r   Ú_document_cacheÚ_create_auto_suggest_coroutineÚ_async_suggesterÚ_create_completer_coroutineÚ_async_completerÚ_create_auto_validate_coroutineÚ_async_validatorÚ_load_history_taskÚreset)rB   rt   ru   r‚   rv   rw   rx   ry   r{   r|   r}   rs   rz   r~   r   r€   r„   r…   r†   r‡   rˆ   s                        r6   rC   zBuffer.__init__×   s…  € ô0 !*Ð*?Ó @ÐÜ )Ð*?Ó @ÐÜ )Ð*?Ó @ÐÜ˜iÓ(ˆ	Ü˜iÓ(ˆ	à"Ò6¤nÓ&6ˆŒØ(ˆÔØ"ˆŒØ.ˆÔØ ˆŒØˆŒ	Ø,ˆÔð &;ˆÔ"Ø%:ˆÔ"Ø%:ˆÔ"Ø"ˆŒØ"ˆŒØ)BˆÔ&ð ˆŒð
 -4¨O”Ô(ÀˆŒà!"ˆÔô /4°D¸/Ó.JˆÔÜ-2°4¸Ó-HˆÔÜ9>ØÐ,ó:
ˆÔ'ô 6;¸4ÐAWÓ5XˆÔ#Ü05°dÐ<MÓ0NˆÔô
 œ(¨Ô,ð 	Ôð
 !%× CÑ CÓ EˆÔØ $× @Ñ @Ó BˆÔØ $× DÑ DÓ FˆÔð @DˆÔð 	�
‰
˜Hˆ
Õ%r5   c                ó®   — t        | j                  «      dk  r| j                  }n| j                  d d dz   }d| j                  ›d|›dt        | «      ›d�S )Né   é   z...z<Buffer(name=z, text=z) at Ú>)rH   rP   ry   Úid)rB   rP   s     r6   rJ   zBuffer.__repr__(  sR   € Üˆt�y‰y‹>˜BÒØ—9‘9‰Dà—9‘9˜S˜b�> EÑ)ˆDà˜tŸy™y˜m¨7°4°(¸%ÄÀ4Ã¸|È1ÐMÐMr5   c                óÈ  — |r| j                  «        |xs
 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_historyr   rQ   rƒ   Úvalidation_errorr8   r;   Úvalidation_stateÚselection_stateÚmultiple_cursor_positionsÚpreferred_columnÚcomplete_stateÚyank_nth_arg_stateÚdocument_before_pasteÚ
suggestionÚhistory_search_textÚ_undo_stackÚ_redo_stackr�   Úcancelr   rP   Ú_working_linesÚ_Buffer__working_index)rB   rs   r˜   s      r6   r‘   zBuffer.reset0  së   € ñ Ø×"Ñ"Ô$àÒ)œx›zˆà!)×!9Ñ!9ˆÔð 9=ˆÔÜ8G×8OÑ8OˆÔð 7;ˆÔð
 57ˆÔ&ð -1ˆÔð 7;ˆÔð ;?ˆÔð 7;ˆÔ"ð .2ˆŒð 04ˆÔ ð 35ˆÔØ24ˆÔð
 ×"Ñ"Ð.Ø×#Ñ#×*Ñ*Ô,Ø"&ˆÔô +0°·±°Ó*@ˆÔØ ˆÕr5   c                ó°   ‡ — ‰ j                   €Idˆ fd„}t        «       j                   |«       «      ‰ _         dd„}‰ j                   j                  |«       yy)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.
        Nc               “  ó¼   •K  — ‰j                   j                  «       2 3 d {  –—† } ‰j                  j                  | «       ‰xj                  dz  c_        Œ:7 Œ56 y ­w)Nr   )r‚   Úloadr¦   Ú
appendleftr§   )ÚitemrB   s    €r6   Úload_historyz;Buffer.load_history_if_not_yet_loaded.<locals>.load_historyˆ  sL   øè ø€ Ø"&§,¡,×"3Ñ"3Ô"5÷ .˜$Ø×'Ñ'×2Ñ2°4Ô8Ø×(Ò(¨AÑ-Ö(ð.øÑ"5ùs%   ƒAžA¢A£A¦2AÁAÁAc                óª   — 	 | j                  «        y# t        j                  $ r Y yt        $ r Y yt        $ r t
        j                  d«       Y yw xY w)zŒ
                Handle `load_history` result when either done, cancelled, or
                when an exception was raised.
                zLoading history failedN)ÚresultÚasyncioÚCancelledErrorÚGeneratorExitÚBaseExceptionÚloggerÚ	exception)Úfs    r6   Úload_history_donez@Buffer.load_history_if_not_yet_loaded.<locals>.load_history_done�  sP   € ð
?Ø—H‘H•JøÜ×-Ñ-ò ñ Ü$ò ñ Ü$ò ?ô ×$Ñ$Ð%=Ö>ð?ús   ‚ “A¨A²AÁA©r_   r`   )r¶   zasyncio.Future[None]r_   r`   )r�   r   Úcreate_background_taskÚadd_done_callback)rB   r­   r·   s   `  r6   Úload_history_if_not_yet_loadedz%Buffer.load_history_if_not_yet_loadedq  sP   ø€ ð* ×"Ñ"Ð*õ.ô
 '.£i×&FÑ&FÁ|Ã~Ó&VˆDÔ#ó?ð* ×#Ñ#×5Ñ5Ð6GÕHð= +r5   c                ó„   — | j                   }| j                  }||   }|||<   t        |«      t        |«      k7  ry||k7  ryy)z=set text at current working_index. Return whether it changed.TF)Úworking_indexr¦   rH   )rB   Úvaluer½   Úworking_linesÚoriginal_values        r6   Ú	_set_textzBuffer._set_text¨  sR   € à×*Ñ*ˆØ×+Ñ+ˆà& }Ñ5ˆØ',ˆ�mÑ$ô ˆu‹:œ˜^Ó,Ò,ð Ø�nÒ$ØØr5   c                óZ   — | j                   }t        d|«      | _         | j                   |k7  S )z/Set cursor position. Return whether it changed.r   )rƒ   Úmax)rB   r¾   Úoriginal_positions      r6   Ú_set_cursor_positionzBuffer._set_cursor_position¼  s.   € à ×2Ñ2ÐÜ!$ Q¨£ˆÔà×%Ñ%Ð):Ñ:Ð:r5   c                ó4   — | j                   | j                     S r>   )r¦   r½   rI   s    r6   rP   zBuffer.textÃ  s   € à×"Ñ" 4×#5Ñ#5Ñ6Ð6r5   c                óÞ   — | j                   t        |«      kD  rt        |«      | _         | j                  «       r
t        «       ‚| j	                  |«      }|r| j                  «        d| _        yy)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)rQ   rH   r~   r(   rÁ   Ú_text_changedr¢   ©rB   r¾   Úchangeds      r6   rP   zBuffer.textÇ  sc   € ð ×Ñ¤# e£*Ò,Ü#& u£:ˆDÔ ð �>‰>ÔÜ$Ó&Ð&à—.‘. Ó'ˆáØ×ÑÔ ð (,ˆDÕ$ð r5   c                ó   — | j                   S r>   )rƒ   rI   s    r6   rQ   zBuffer.cursor_positioná  s   € à×%Ñ%Ð%r5   c                óØ   — t        |t        «      sJ ‚|t        | j                  «      kD  rt        | j                  «      }|dk  rd}| j	                  |«      }|r| j                  «        yy)z*
        Setting cursor position.
        r   N)Ú
isinstancern   rH   rP   rÅ   Ú_cursor_position_changedrÉ   s      r6   rQ   zBuffer.cursor_positionå  sc   € ô
 ˜%¤Ô%Ð%Ð%ð ”3�t—y‘y“>Ò!Ü˜Ÿ	™	“NˆEØ�1Š9ØˆEà×+Ñ+¨EÓ2ˆáØ×)Ñ)Õ+ð r5   c                ó   — | j                   S r>   )r§   rI   s    r6   r½   zBuffer.working_index÷  s   € à×#Ñ#Ð#r5   c                ó`   — | j                   |k7  r|| _         d| _        | j                  «        y y )Nr   )r§   rQ   rÈ   ©rB   r¾   s     r6   r½   zBuffer.working_indexû  s3   € à×Ñ 5Ò(Ø#(ˆDÔ ð $%ˆDÔ Ø×ÑÕ ð )r5   c                óN  — d | _         t        j                  | _        d | _        d | _        d | _        d | _        d | _        d | _	        | j                  j                  «        | j                  r9| j                  «       r(t        «       j                  | j!                  «       «       y y y r>   )r™   r8   r;   rš   rž   rŸ   r    r›   r¡   r�   r„   Úfirerv   r|   r   r¹   r�   rI   s    r6   rÈ   zBuffer._text_changed  s�   € à $ˆÔÜ /× 7Ñ 7ˆÔØ"ˆÔØ"&ˆÔØ%)ˆÔ"Ø#ˆÔØˆŒØ $ˆÔð 	×Ñ×!Ñ!Ô#ð
 �>Š>˜d×8Ñ8Ô:Ü‹I×,Ñ,¨T×-BÑ-BÓ-DÕEð ;ˆ>r5   c                óp   — d | _         d | _        d | _        d | _        | j                  j                  «        y r>   )rž   rŸ   r    r�   r†   rÓ   rI   s    r6   rÎ   zBuffer._cursor_position_changed  s:   € ð #ˆÔØ"&ˆÔØ%)ˆÔ"ð !%ˆÔð 	×'Ñ'×,Ñ,Õ.r5   c                ób   — | j                   | j                  | j                  | j                  f   S )z�
        Return :class:`~prompt_toolkit.document.Document` instance from the
        current text, cursor position and selection state.
        )r‰   rP   rQ   r›   rI   s    r6   rs   zBuffer.document+  s1   € ð ×#Ñ#Ø�I‰I�t×+Ñ+¨T×-AÑ-AÐAñ
ð 	
r5   c                ó&   — | 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_documentrÑ   s     r6   rs   zBuffer.document5  s   € ð 	×Ñ˜%Õ r5   c                ó   — |s| j                  «       r
t        «       ‚| j                  |j                  «      }| j	                  |j
                  «      }|r| j                  «        d| _        |r| j                  «        yy)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(   rÁ   rP   rÅ   rQ   rÈ   r¢   rÎ   )rB   r¾   Úbypass_readonlyÚtext_changedÚcursor_position_changeds        r6   r×   zBuffer.set_document?  sq   € ñ&  4§>¡>Ô#3Ü$Ó&Ð&ð —~‘~ e§j¡jÓ1ˆØ"&×";Ñ";¸E×<QÑ<QÓ"RÐñ Ø×ÑÔ Ø'+ˆDÔ$á"Ø×)Ñ)Õ+ð #r5   c                ó,   — t        | j                  «      S )z?
        True when there is something handling accept.
        )Úboolrz   rI   s    r6   Úis_returnablezBuffer.is_returnableb  s   € ô
 �D×'Ñ'Ó(Ð(r5   c                ó(  — | j                   rK| j                   d   d   | j                  k(  r,| j                   d   d   | j                  f| j                   d<   n1| j                   j                  | j                  | j                  f«       |rg | _        yy)zy
        Safe current state (input text and cursor position), so that we can
        restore it by calling undo.
        rl   r   N)r£   rP   rQ   Úappendr¤   )rB   Úclear_redo_stacks     r6   Úsave_to_undo_stackzBuffer.save_to_undo_stackk  sˆ   € ð ×Ò × 0Ñ 0°Ñ 4°QÑ 7¸4¿9¹9Ò DØ$(×$4Ñ$4°RÑ$8¸Ñ$;¸T×=QÑ=QÐ#RˆD×Ñ˜RÒ à×Ñ×#Ñ# T§Y¡Y°×0DÑ0DÐ$EÔFñ Ø!ˆDÕð r5   c                ó¤   — | j                   j                  d«      }|D ]  }	  |||   «      ||<   Œ dj                  |«      S # t        $ r Y Œ0w xY w)a/  
        Transforms the text on a range of lines.
        When the iterator yield an index not in the range of lines that the
        document contains, it skips them silently.

        To uppercase some lines::

            new_text = transform_lines(range(5,10), lambda text: text.upper())

        :param line_index_iterator: Iterator of line numbers (int)
        :param transform_callback: callable that takes the original text of a
                                   line, and return the new text for this line.

        :returns: The new text.
        Ú
)rP   ÚsplitÚ
IndexErrorÚjoin)rB   Úline_index_iteratorÚtransform_callbackÚlinesrM   s        r6   Útransform_lineszBuffer.transform_lines{  s^   € ð* —	‘	—‘ Ó%ˆó )ˆEðÙ1°%¸±,Ó?��e’ð )ð �y‰y˜ÓÐøô ò Ùðús   ¢AÁ	AÁAc                ó  — | j                   }|j                  |j                  «       z   }|j                  |j                  «       z   }|j                  d|  ||j                  || «      z   |j                  |d z   | _        y)z¨
        Apply the given transformation function to the current line.

        :param transform_callback: callable that takes a string and return a new string.
        N)rs   rQ   Úget_start_of_line_positionÚget_end_of_line_positionrP   )rB   ré   rs   ÚaÚbs        r6   Útransform_current_linezBuffer.transform_current_line›  s   € ð —=‘=ˆØ×$Ñ$ x×'JÑ'JÓ'LÑLˆØ×$Ñ$ x×'HÑ'HÓ'JÑJˆà�M‰M˜"˜1ÐÙ  §¡¨q°Ð!3Ó4ñ5à�m‰m˜A˜BÐñ ð 	�	r5   c                ó¦   — ||k  sJ ‚dj                  | j                  d|  || j                  || «      z   | j                  |d z   g«      | _        y)zþ
        Transform a part of the input string.

        :param from_: (int) start position.
        :param to: (int) end position.
        :param transform_callback: Callable which accepts a string and returns
            the transformed string.
        rm   N)rç   rP   )rB   Úfrom_Útoré   s       r6   Útransform_regionzBuffer.transform_regionª  s]   € ð �rŠzÐˆzà—G‘Gà—	‘	˜&˜5Ð!Ù$ T§Y¡Y¨u°RÐ%8Ó9ñ:à—)‘)˜B˜C�.ñ!ðó
ˆ�	r5   r   c                ób   — | xj                   | j                  j                  |¬«      z  c_         y ©N©Úcount)rQ   rs   Úget_cursor_left_position©rB   rù   s     r6   Úcursor_leftzBuffer.cursor_left¿  s%   € Ø×Ò §¡× FÑ FÈUÐ FÓ SÑSÖr5   c                ób   — | xj                   | j                  j                  |¬«      z  c_         y r÷   )rQ   rs   Úget_cursor_right_positionrû   s     r6   Úcursor_rightzBuffer.cursor_rightÂ  s%   € Ø×Ò §¡× GÑ GÈeÐ GÓ TÑTÖr5   c                óº   — | j                   xs | j                  j                  }| xj                  | j                  j	                  ||¬«      z  c_        || _         y)z7(for multiline edit). Move cursor to the previous line.©rù   r�   N)r�   rs   Úcursor_position_colrQ   Úget_cursor_up_position©rB   rù   Úoriginal_columns      r6   Ú	cursor_upzBuffer.cursor_upÅ  sS   € à×/Ñ/ÒT°4·=±=×3TÑ3TˆØ×Ò §¡× DÑ DØ¨/ð !Eó !
ñ 	
Õð
 !0ˆÕr5   c                óº   — | j                   xs | j                  j                  }| xj                  | j                  j	                  ||¬«      z  c_        || _         y)z3(for multiline edit). Move cursor to the next line.r  N)r�   rs   r  rQ   Úget_cursor_down_positionr  s      r6   Úcursor_downzBuffer.cursor_downÏ  sS   € à×/Ñ/ÒT°4·=±=×3TÑ3TˆØ×Ò §¡× FÑ FØ¨/ð !Gó !
ñ 	
Õð
 !0ˆÕr5   c                ó8  — | j                   r| j                  |¬«       y| j                  j                  dkD  r| j	                  |¬«       y| j
                  sC| j                  |¬«       |r.| xj                  | j                  j                  «       z  c_        yyy)z•
        If we're not on the first line (of a multiline input) go a line up,
        otherwise go back in history. (If nothing is selected.)
        rø   r   N)	rž   Úcomplete_previousrs   Úcursor_position_rowr  r›   Úhistory_backwardrQ   rí   ©rB   rù   Ú&go_to_start_of_line_if_history_changess      r6   Úauto_upzBuffer.auto_upÙ  s…   € ð ×ÒØ×"Ñ"¨Ð"Õ/Ø�]‰]×.Ñ.°Ò2Ø�N‰N ˆNÕ'Ø×%Ò%Ø×!Ñ!¨Ð!Ô.ñ 6Ø×$Ò$¨¯©×(PÑ(PÓ(RÑRÖ$ð 6ð	 &r5   c                óf  — | j                   r| j                  |¬«       y| j                  j                  | j                  j                  dz
  k  r| j                  |¬«       y| j                  sC| j                  |¬«       |r.| xj                  | j                  j                  «       z  c_        yyy)z™
        If we're not on the last line (of a multiline input) go a line down,
        otherwise go forward in history. (If nothing is selected.)
        rø   r   N)
rž   Úcomplete_nextrs   r  Ú
line_countr	  r›   Úhistory_forwardrQ   rí   r  s      r6   Ú	auto_downzBuffer.auto_downë  s—   € ð ×ÒØ×Ñ UÐÕ+Ø�]‰]×.Ñ.°·±×1IÑ1IÈAÑ1MÒMØ×Ñ 5ÐÕ)Ø×%Ò%Ø× Ñ  uÐ Ô-ñ 6Ø×$Ò$¨¯©×(PÑ(PÓ(RÑRÖ$ð 6ð	 &r5   c                ó@  — |dk\  sJ ‚d}| j                   dkD  r…| j                  | j                   |z
  | j                    }| j                  d| j                   |z
   | j                  | j                   d z   }| j                   t        |«      z
  }t        ||«      | _        |S )zj
        Delete specified number of characters before cursor and return the
        deleted text.
        r   rm   N)rQ   rP   rH   r   rs   )rB   rù   ÚdeletedrY   rZ   s        r6   Údelete_before_cursorzBuffer.delete_before_cursorý  s¬   € ð
 ˜ŠzÐˆzØˆà×Ñ !Ò#Ø—i‘i × 4Ñ 4°uÑ <¸t×?SÑ?SÐTˆGð —	‘	Ð8˜D×0Ñ0°5Ñ8Ð9Ø—)‘)˜D×0Ñ0Ð2Ð3ñ4ð ð #'×"6Ñ"6¼¸W»Ñ"EÐô % XÐ/BÓCˆDŒMàˆr5   c                ó  — | j                   t        | j                  «      k  r_| j                  j                  d| }| j                  d| j                    | j                  | j                   t        |«      z   d z   | _        |S y)zT
        Delete specified number of characters and Return the deleted text.
        Nrm   )rQ   rH   rP   rs   rS   )rB   rù   r  s      r6   ÚdeletezBuffer.delete  sz   € ð ×Ñ¤# d§i¡i£.Ò0Ø—m‘m×5Ñ5°f°uÐ=ˆGà—	‘	Ð0˜D×0Ñ0Ð1Ø—)‘)˜D×0Ñ0´3°w³<Ñ?ÐAÐBñCð ŒIð ˆNàr5   c                ó4  — | j                   j                  s‚| xj                  | j                   j                  «       z  c_        | j	                  «        | j                   j
                  |z   | j                   j                  j                  d«      z   | _        yy)zs
        Join the next line to the current one by deleting the line ending after
        the current line.
        Ú N)	rs   Úon_last_linerQ   rî   r  rR   rS   ÚlstriprP   )rB   Ú	separators     r6   Újoin_next_linezBuffer.join_next_line!  sx   € ð
 �}‰}×)Ò)Ø× Ò  D§M¡M×$JÑ$JÓ$LÑLÕ Ø�K‰KŒMð —‘×0Ñ0Øñà—-‘-×1Ñ1×8Ñ8¸Ó=ñ>ð �Ið *r5   c                óÎ  — | j                   sJ ‚t        | j                  | j                   j                  g«      \  }}| j                  d| }| j                  || j                  «       }| j                  |d }|D �cg c]  }|j                  d«      |z   ‘Œ }}t        |dj                  |«      z   |z   t        |dj                  |dd «      z   «      dz
  ¬«      | _
        yc c}w )z*
        Join the selected lines.
        Nr  rm   rl   r   ©rP   rQ   )r›   ÚsortedrQ   Úoriginal_cursor_positionrP   Ú
splitlinesr  r   rç   rH   rs   )rB   r  ró   rô   rX   rê   ÚafterÚls           r6   Újoin_selected_lineszBuffer.join_selected_lines1  sã   € ð ×#Ò#Ð#Ð#ô Ø×!Ñ! 4×#7Ñ#7×#PÑ#PÐQó
‰	ˆˆrð —‘˜6˜EÐ"ˆØ—	‘	˜% Ð#×.Ñ.Ó0ˆØ—	‘	˜"˜#�ˆñ 5:Ó:±E¨q�—‘˜#“ Ó*°EˆÐ:ô !Ø˜"Ÿ'™' %›.Ñ(¨5Ñ0Ü ¨¯©°°s¸°Ó)<Ñ <Ó=ÀÑAô
ˆ�ùò ;s   Á<C"c                óÊ   — | j                   }|dk\  rR| j                  |dz
     }| j                  |dz
     }| j                  d|dz
   |z   |z   | j                  |d z   | _        yy)zA
        Swap the last two characters before the cursor.
        é   r   N)rQ   rP   )rB   Úposrï   rð   s       r6   Úswap_characters_before_cursorz$Buffer.swap_characters_before_cursorI  sn   € ð ×"Ñ"ˆà�!Š8Ø—	‘	˜# ™'Ñ"ˆAØ—	‘	˜# ™'Ñ"ˆAàŸ	™	 ) C¨!¡GÐ,¨qÑ0°1Ñ4°t·y±yÀÀ°ÑFˆD�Ið	 r5   c                óx   — |t        | j                  «      k  r"|| _        t        | j                  «      | _        yy)z1
        Go to this item in the history.
        N)rH   r¦   r½   rP   rQ   rL   s     r6   Úgo_to_historyzBuffer.go_to_historyU  s4   € ð ”3�t×*Ñ*Ó+Ò+Ø!&ˆDÔÜ#& t§y¡y£>ˆDÕ ð ,r5   c                ó>  — | j                   r‘t        | j                   j                  «      }| j                   j                  €d}nG| j                   j                  |dz
  k(  rd}|r'yt	        |dz
  | j                   j                  |z   «      }| j                  |«       yy)zd
        Browse to the next completions.
        (Does nothing if there are no completion.)
        Nr   r   )rž   rH   r@   rA   ÚminÚgo_to_completion)rB   rù   Údisable_wrap_aroundÚcompletions_countrM   s        r6   r  zBuffer.complete_next]  s›   € ð ×ÒÜ # D×$7Ñ$7×$CÑ$CÓ DÐà×"Ñ"×1Ñ1Ð9Ø‘Ø×$Ñ$×3Ñ3Ð7HÈ1Ñ7LÒLØ�á&ØäØ%¨Ñ)¨4×+>Ñ+>×+MÑ+MÐPUÑ+Uó�ð ×!Ñ! %Õ(ð r5   c                ó4  — | j                   rŒ| j                   j                  dk(  rd}|r]y| j                   j                  €#t        | j                   j                  «      dz
  }n#t	        d| j                   j                  |z
  «      }| j                  |«       yy)zh
        Browse to the previous completions.
        (Does nothing if there are no completion.)
        r   Nr   )rž   rA   rH   r@   rÃ   r1  )rB   rù   r2  rM   s       r6   r  zBuffer.complete_previoust  s‰   € ð ×ÒØ×"Ñ"×1Ñ1°QÒ6Ø�á&ØØ×$Ñ$×3Ñ3Ð;Ü˜D×/Ñ/×;Ñ;Ó<¸qÑ@‘ä˜A˜t×2Ñ2×AÑAÀEÑIÓJ�à×!Ñ! %Õ(ð r5   c                óN   — | j                   r| j                  d«       d| _         yy)zB
        Cancel completion, go back to the original text.
        N)rž   r1  rI   s    r6   Úcancel_completionzBuffer.cancel_completionŠ  s(   € ð ×ÒØ×!Ñ! $Ô'Ø"&ˆDÕð r5   c                ó†   — t        | j                  |¬«      | _        | j                  j	                  «        | j                  S )zˆ
        Start completions. (Generate list of completions and initialize.)

        By default, no completion will be selected.
        )r?   r@   )r*   rs   rž   r‡   rÓ   )rB   r@   s     r6   Ú_set_completionszBuffer._set_completions’  s:   € ô .Ø"Ÿm™m¸ô
ˆÔð
 	×#Ñ#×(Ñ(Ô*à×"Ñ"Ð"r5   c           
     óD  — t        «       }g }| j                  j                  j                  «       }t	        | j
                  «      D ]¯  \  }}t	        |j                  d«      «      D ]�  \  }}|j                  «       }|sŒ|j                  |«      sŒ+||vsŒ0|j                  |«       || j                  k(  r	d|dz   z  }nd|dz   › d|dz   › �}|j                  t        |t        |«       |¬«      «       Œ� Œ± | j                  |ddd…   ¬	«       | j                  d
«       y)zj
        Start a completion based on all the other lines in the document and the
        history.
        rä   zCurrent, line %sr   zHistory z, line )rP   rT   Údisplay_metaNrl   ©r@   r   )Úsetrs   Úcurrent_line_before_cursorr  Ú	enumerater¦   rå   ÚstripÚ
startswithÚaddr½   rà   r   rH   r8  r1  )	rB   Úfound_completionsr@   Úcurrent_lineÚiÚstringÚjr'  r:  s	            r6   Ústart_history_lines_completionz%Buffer.start_history_lines_completion¡  s  € ô
 '*£eÐØˆð —}‘}×?Ñ?×FÑFÓHˆä" 4×#6Ñ#6Ö7‰IˆAˆvÜ! &§,¡,¨tÓ"4Ö5‘��1Ø—G‘G“I�Ú˜Ÿ™ lÕ3àÐ 1Ò1Ø)×-Ñ-¨aÔ0ð  × 2Ñ 2Ò2Ø+=ÀÀQÁÑ+G™Là-5°a¸!±e°W¸GÀAÈÁEÀ7Ð+K˜Là#×*Ñ*Ü&Ø%&Ü03°LÓ0AÐ/AØ-9ôõñ 6ð 8ð, 	×Ñ¨+±d¸°dÑ*;ÐÔ<Ø×Ñ˜aÕ r5   c                ó°   — | j                   sJ ‚| j                   }|j                  |«       |j                  «       \  }}t        ||«      | _        || _         y)zK
        Select a completion from the list of current completions.
        N)rž   rN   r[   r   rs   )rB   rM   ÚstaterY   rZ   s        r6   r1  zBuffer.go_to_completionÅ  s]   € ð ×"Ò"Ð"Ð"ð ×#Ñ#ˆØ×Ñ˜%Ô ð ).×(CÑ(CÓ(EÑ%ˆÐ%Ü  Ð+>Ó?ˆŒð $ˆÕr5   c                óº   — | j                   r| j                  d«       d| _         | j                  |j                   «       | j	                  |j
                  «       y)z,
        Insert a given completion.
        N)rž   r1  r  rT   Úinsert_textrP   )rB   Ú
completions     r6   Úapply_completionzBuffer.apply_completionÖ  sN   € ð
 ×ÒØ×!Ñ! $Ô'Ø"ˆÔð 	×!Ñ! :×#<Ñ#<Ð"<Ô=Ø×Ñ˜Ÿ™Õ)r5   c                ó„   — | j                  «       r)| j                  €| j                  j                  | _        yyd| _        y)zy
        Set `history_search_text`.
        (The text before the cursor will be used for filtering the history.)
        N)r}   r¢   rs   rR   rI   s    r6   Ú_set_history_searchzBuffer._set_history_searchã  s=   € ð
 ×%Ñ%Ô'Ø×'Ñ'Ð/Ø+/¯=©=×+KÑ+K�Õ(ð 0ð (,ˆDÕ$r5   c                ór   — | j                   du xs( | j                  |   j                  | j                   «      S )z†
        True when the current entry matches the history search.
        (when we don't have history search, it's also True.)
        N)r¢   r¦   r@  )rB   rD  s     r6   Ú_history_matcheszBuffer._history_matchesî  s=   € ð
 ×'Ñ'¨4Ð/ò 
°4×3FÑ3FÀqÑ3I×3TÑ3TØ×$Ñ$ó4
ð 	
r5   c                óD  — | j                  «        d}t        | j                  dz   t        | j                  «      «      D ](  }| j                  |«      r|| _        |dz  }d}|dk(  sŒ( n |r5d| _        | xj                  | j                  j                  «       z  c_        yy)zl
        Move forwards through the history.

        :param count: Amount of items to move forward.
        Fr   Tr   N)	rO  Úranger½   rH   r¦   rQ  rQ   rs   rî   ©rB   rù   Úfound_somethingrD  s       r6   r  zBuffer.history_forward÷  s�   € ð 	× Ñ Ô"ð  ˆä�t×)Ñ)¨AÑ-¬s°4×3FÑ3FÓ/GÖHˆAØ×$Ñ$ QÔ'Ø%&�Ô"Ø˜‘
�Ø"&�Ø˜‹zÙð Iñ Ø#$ˆDÔ Ø× Ò  D§M¡M×$JÑ$JÓ$LÑLÖ ð r5   c                óì   — | j                  «        d}t        | j                  dz
  dd«      D ](  }| j                  |«      r|| _        |dz  }d}|dk(  sŒ( n |rt	        | j
                  «      | _        yy)z1
        Move backwards through history.
        Fr   rl   Tr   N)rO  rS  r½   rQ  rH   rP   rQ   rT  s       r6   r  zBuffer.history_backward  s}   € ð 	× Ñ Ô"ð  ˆä�t×)Ñ)¨AÑ-¨r°2Ö6ˆAØ×$Ñ$ QÔ'Ø%&�Ô"Ø˜‘
�Ø"&�Ø˜‹zÙð 7ñ Ü#& t§y¡y£>ˆDÕ ð r5   c                ó¬  — |�t        |t        «      sJ ‚| j                  j                  «       }t	        |«      sy| j
                  €t        |rdnd¬«      }n| j
                  }|�||_        |j                  dz
  }| t	        |«      kD  rd}||   }t        j                  |«      D �cg c]  }|j                  «       ‘Œ }}|D �cg c]  }|sŒ|‘Œ	 }}	 ||j                     }	|j                  r$| j                  t	        |j                  «      «       | j                  |	«       |	|_        ||_        || _        yc c}w c c}w # t        $ r d}	Y Œnw xY w)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.
        Nrl   r   )rj   rm   )rÍ   rn   r‚   Úget_stringsrH   rŸ   rf   rj   rh   Ú_QUOTED_WORDS_RErå   r?  ræ   ri   r  rK  )
rB   rj   Ú_yank_last_argÚhistory_stringsrI  Únew_posÚlineÚwÚwordsÚwords
             r6   Úyank_nth_argzBuffer.yank_nth_arg$  sT  € ð ˆyœJ q¬#Ô.Ð.Ð.ØŸ,™,×2Ñ2Ó4ˆä�?Ô#Øð ×"Ñ"Ð*Ü#©N¡bÀÔB‰Eà×+Ñ+ˆEàˆ=ØˆEŒGð ×(Ñ(¨1Ñ,ˆØˆ8”c˜/Ó*Ò*ØˆGð ˜wÑ'ˆä$4×$:Ñ$:¸4Ô$@ÓAÑ$@˜q�—‘•Ð$@ˆÐAÙ!Ó'™E�q¢Q’˜EˆÐ'ð	Ø˜Ÿ™‘>ˆDð
 ×'Ò'Ø×%Ñ%¤c¨%×*FÑ*FÓ&GÔHØ×Ñ˜Ôð (,ˆÔ$Ø!(ˆÔØ"'ˆÕùò! BùÚ'øô ò 	ØŠDð	ús$   Â)D;ÃE ÃE ÃE ÅEÅEc                ó*   — | j                  |d¬«       y)zp
        Like `yank_nth_arg`, but if no argument has been given, yank the last
        word by default.
        T)rj   rZ  N)ra  )rB   rj   s     r6   Úyank_last_argzBuffer.yank_last_argW  s   € ð
 	×Ñ˜A¨dÐÕ3r5   c                ó:   — t        | j                  |«      | _        y)zR
        Take the current cursor position as the start of this selection.
        N)r"   rQ   r›   )rB   Úselection_types     r6   Ústart_selectionzBuffer.start_selection^  s   € ô  .¨d×.BÑ.BÀNÓSˆÕr5   c                ó`   — | j                   j                  «       \  }}|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_documentÚclipboard_datas       r6   Úcopy_selectionzBuffer.copy_selectionf  s3   € ð (,§}¡}×'BÑ'BÓ'DÑ$ˆ�nÙØ(ˆDŒMà#ˆÔØÐr5   c                ó&   — | j                  d¬«      S )zS
        Delete selected text and return :class:`.ClipboardData` instance.
        T)ri  )rl  rI   s    r6   rh  zBuffer.cut_selectiony  s   € ð ×"Ñ"¨Ð"Ó-Ð-r5   c                óú   — t        |t        «      sJ ‚|t        j                  t        j                  t        j
                  fv sJ ‚| j                  }| j                  j                  |||¬«      | _        || _        y)z5
        Insert the data from the clipboard.
        )Ú
paste_moderù   N)	rÍ   r   r!   Ú	VI_BEFOREÚVI_AFTERÚEMACSrs   Úpaste_clipboard_datar    )rB   Údataro  rù   r?   s        r6   rs  zBuffer.paste_clipboard_data  so   € ô ˜$¤Ô.Ð.Ð.Øœi×1Ñ1´9×3EÑ3EÄyÇÁÐWÑWÐWÐWà ŸM™MÐØŸ™×:Ñ:Ø˜Z¨uð ;ó 
ˆŒð &7ˆÕ"r5   c                ó|   — |r)| j                  d| j                  j                  z   «       y| j                  d«       y)z?
        Insert a line ending at the current position.
        rä   N)rK  rs   Ú"leading_whitespace_in_current_line)rB   Úcopy_margins     r6   ÚnewlinezBuffer.newline”  s2   € ñ Ø×Ñ˜T D§M¡M×$TÑ$TÑTÕUà×Ñ˜TÕ"r5   c                óæ   — |r| j                   j                  dz   }nd}| xj                  | j                   j                  «       z  c_        | j	                  |«       | xj                  dz  c_        y)z:
        Insert a new line above the current one.
        rä   r   N)rs   rv  rQ   rí   rK  ©rB   rw  Úinserts      r6   Úinsert_line_abovezBuffer.insert_line_above�  s]   € ñ Ø—]‘]×EÑEÈÑL‰FàˆFà×Ò §¡× HÑ HÓ JÑJÕØ×Ñ˜Ô Ø×Ò Ñ!Ör5   c                ó¼   — |rd| j                   j                  z   }nd}| xj                  | j                   j                  «       z  c_        | j	                  |«       y)z:
        Insert a new line below the current one.
        rä   N)rs   rv  rQ   rî   rK  rz  s      r6   Úinsert_line_belowzBuffer.insert_line_belowª  sL   € ñ Ø˜DŸM™M×LÑLÑL‰FàˆFà×Ò §¡× FÑ FÓ HÑHÕØ×Ñ˜Õ r5   c                ót  — | j                   }| j                  }|rD|||t        |«      z    }d|v r|d|j                  d«       }|d| |z   ||t        |«      z   d z   }n|d| |z   ||d z   }|r| j                  t        |«      z   }	n| j                  }	t	        ||	«      | _        |r’| j                  j                  «        | j                  r7| j                  «       r't        «       j                  | j                  «       «       | j                  r(t        «       j                  | j                  «       «       yyy)z¸
        Insert characters at cursor position.

        :param fire_event: Fire `on_text_insert` event. This is mainly used to
            trigger autocompletion while typing.
        rä   N)rP   rQ   rH   Úfindr   rs   r…   rÓ   rt   r{   r   r¹   r�   ru   r‹   )
rB   rt  Ú	overwriteÚmove_cursorÚ
fire_eventÚotextÚocposÚoverwritten_textrP   Úcposs
             r6   rK  zBuffer.insert_text¶  s?  € ð —	‘	ˆØ×$Ñ$ˆñ ð  % U¨U´S¸³YÑ->Ð?ÐØÐ'Ñ'Ø#3Ð4QÐ6F×6KÑ6KÈDÓ6QÐ#RÐ à˜˜%�= 4Ñ'¨%°¼Ð<LÓ8MÑ0MÐ0OÐ*PÑP‰Dà˜˜%�= 4Ñ'¨%°°¨-Ñ7ˆDáØ×'Ñ'¬#¨d«)Ñ3‰Dà×'Ñ'ˆDô !  tÓ,ˆŒñ Ø×Ñ×$Ñ$Ô&ð �~Š~ $×"<Ñ"<Ô">Ü“	×0Ñ0°×1FÑ1FÓ1HÔIð × Ò Ü“	×0Ñ0°×1FÑ1FÓ1HÕIð !ð r5   c                ó  — | j                   r~| j                   j                  «       \  }}|| j                  k7  rD| j                  j	                  | j                  | j
                  f«       t        ||¬«      | _        y | j                   rŒ}y y )N©rQ   )r£   ÚpoprP   r¤   rà   rQ   r   rs   ©rB   rP   r+  s      r6   ÚundozBuffer.undoê  sr   € ð
 ×ÒØ×(Ñ(×,Ñ,Ó.‰IˆD�#à�t—y‘yÒ à× Ñ ×'Ñ'¨¯©°D×4HÑ4HÐ(IÔJô !)¨¸sÔ C�”Øð ×Õr5   c                ó    — | j                   rB| j                  d¬«       | j                   j                  «       \  }}t        ||¬«      | _        y y )NF)rá   r‰  )r¤   râ   rŠ  r   rs   r‹  s      r6   ÚredozBuffer.redoú  sI   € Ø×Òà×#Ñ#°UÐ#Ô;ð ×(Ñ(×,Ñ,Ó.‰IˆD�#Ü$ T¸3Ô?ˆD�Mð r5   c                óì  — | j                   t        j                  k7  r| j                   t        j                  k(  S | j                  r&	 | j                  j                  | j                  «       t        j                  | _         d| _        y# t        $ r`}|r8t        t        d|j                  «      t        | j                  «      «      | _
        t        j                  | _         || _        Y d}~yd}~ww xY w)zv
        Returns `True` if valid.

        :param set_cursor: Set the cursor position, if an error was found.
        r   NFT)rš   r8   r;   r9   rv   Úvalidaters   r&   r0  rÃ   rQ   rH   rP   r:   r™   )rB   Ú
set_cursorÚes      r6   r�  zBuffer.validate  sÅ   € ð × Ñ ¤O×$;Ñ$;Ò;Ø×(Ñ(¬O×,AÑ,AÑAÐAð �>Š>ðØ—‘×'Ñ'¨¯©Ô6ô !0× 5Ñ 5ˆÔØ $ˆÔØøô #ò 	áÜ+.Ü˜A˜q×0Ñ0Ó1´3°t·y±y³>ó,�DÔ(ô )8×(?Ñ(?�Ô%Ø()�Ô%Üûð	ús   Á%B
 Â
	C3ÂAC.Ã.C3c              ƒ  óÆ  K  — 	 | j                   t        j                  k7  ryd}| j                  }| j                  r>	 | j                  j                  | j                  «      ƒ d{  –—†  | j                  |k7  rŒw|rt        j                  | _         nt        j                  | _         || _	        t        «       j                  «        ŒÃ7 Œa# t        $ r}|}Y d}~Œod}~ww xY w­w)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)rš   r8   r;   rs   rv   Úvalidate_asyncr&   r:   r9   r™   r   Ú
invalidate)rB   Úerrorrs   r’  s       r6   Ú_validate_asynczBuffer._validate_async"  sÃ   è ø€ ð ð ×$Ñ$¬×(?Ñ(?Ò?Øð ˆEØ—}‘}ˆHà�~Š~ðØŸ.™.×7Ñ7¸¿¹ÓF×FÐFð
 —=‘= HÒ,Øñ Ü(7×(?Ñ(?�Õ%ä(7×(=Ñ(=�Ô%à$)ˆDÔ!Ü‹I× Ñ Ô"ð7 ð GùÜ&ò Ø•EûðüsA   ‚:C!½(C	 Á%CÁ&C	 Á*AC!ÃC	 Ã		CÃCÃC!ÃCÃC!c                óØ   — | j                   r^| j                  j                  «       }t        |«      r|d   | j                   k7  r&| j                  j	                  | j                   «       yyy)z:
        Append the current input to the history.
        rl   N)rP   r‚   rX  rH   Úappend_string)rB   r[  s     r6   r˜   zBuffer.append_to_historyL  sV   € ð �9Š9Ø"Ÿl™l×6Ñ6Ó8ˆOÜ�Ô'¨?¸2Ñ+>À$Ç)Á)Ò+KØ—‘×*Ñ*¨4¯9©9Õ5ð ,Lð r5   c                ó  ‡ ‡‡	‡
‡— |dkD  sJ ‚|j                   Š|j                  Š	|j                  «       Š
	 	 	 	 	 	 dˆ	ˆ
ˆˆ ˆfd„}‰ j                  }‰ j                  }t        |«      D ]  } |||«      }|€ y|\  }}Œ ||j                  fS )z£
        Execute search. Return (working_index, cursor_position) tuple when this
        search is applied. Returns `None` when this text cannot be found.
        r   c                óp  •— ‰t         j                  k(  rÇ|j                  ‰‰‰¬«      }|�%| t        |j                  |j
                  |z   «      fS t        | dz   t        ‰j                  «      dz   «      D ]c  }|t        ‰j                  «      z  }t        ‰j                  |   d«      }|j                  ‰d‰¬«      }|€ŒK|t        |j                  |«      fc S  y|j                  ‰‰¬«      }|�%| t        |j                  |j
                  |z   «      fS t        | dz
  dd«      D ]Ž  }|t        ‰j                  «      z  }t        ‰j                  |   t        ‰j                  |   «      «      }|j                  ‰‰¬«      }|€Œ`|t        |j                  t        |j                  «      |z   «      fc S  y)	zd
            Do search one time.
            Return (working_index, document) or `None`
            )Úinclude_current_positionÚignore_caseNr   r   T)r�  éþÿÿÿrl   )
r   ÚFORWARDr€  r   rP   rQ   rS  rH   r¦   Úfind_backwards)	r½   rs   Ú	new_indexrD  Ú	directionr�  rœ  rB   rP   s	       €€€€€r6   Úsearch_oncez#Buffer._search.<locals>.search_onceg  sß  ø€ ð œO×3Ñ3Ò3à$ŸM™MØØ-EØ +ð *ó �	ð Ð(à%Ü  §¡°×0HÑ0HÈ9Ñ0TÓUðð ô # =°1Ñ#4´c¸$×:MÑ:MÓ6NÐQRÑ6RÖS˜ØœS ×!4Ñ!4Ó5Ñ5˜ä#+¨D×,?Ñ,?ÀÑ,BÀAÓ#F˜Ø$,§M¡MØ ¸4È[ð %2ó %˜	ð %Ñ0Ø$%¤x°·±¸yÓ'IÐ#JÒJð TðD ð/ %×3Ñ3°DÀkÐ3ÓR�	àÐ(à%Ü  §¡°×0HÑ0HÈ9Ñ0TÓUðð ô # =°1Ñ#4°b¸"Ö=˜ØœS ×!4Ñ!4Ó5Ñ5˜ä#+Ø ×/Ñ/°Ñ2´C¸×8KÑ8KÈAÑ8NÓ4Oó$˜ð %-×$;Ñ$;Ø ¨kð %<ó %˜	ð %Ñ0à !Ü (¨¯©¼¸H¿M¹MÓ8JÈYÑ8VÓ Wð$ò ð >ð r5   N)r½   rn   rs   r   r_   ztuple[int, Document] | None)rP   r¢  r�  r½   rs   rS  rQ   )rB   Úsearch_staterœ  rù   r£  r½   rs   Ú_r¯   r¢  r�  rP   s   ` `      @@@r6   Ú_searchzBuffer._searchW  s­   ü€ ð �qŠyÐˆyà× Ñ ˆØ ×*Ñ*ˆ	Ø"×.Ñ.Ó0ˆð:	Øð:	Ø*2ð:	à(÷:	ñ :	ðz ×*Ñ*ˆØ—=‘=ˆÜ�u–ˆAÙ  °Ó9ˆFØˆ~Ùà*0Ñ'�™xð ð ˜x×7Ñ7Ð8Ð8r5   c                óÀ   — | j                  |d¬«      }|€| j                  S |\  }}|| j                  k(  r| j                  }nd}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)rœ  N)Ú	selection)r¦  rs   r½   r›   r   r¦   )rB   r¤  Úsearch_resultr½   rQ   r¨  s         r6   Údocument_for_searchzBuffer.document_for_search¯  so   € ð Ÿ™ \ÈD˜ÓQˆàÐ Ø—=‘=Ð à-:Ñ*ˆM˜?ð  × 2Ñ 2Ò2Ø ×0Ñ0‘	à �	äØ×#Ñ# MÑ2°OÈyôð r5   c                óT   — | j                  |||¬«      }|€| j                  S |\  }}|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.)
        ©rœ  rù   )r¦  rQ   ©rB   r¤  rœ  rù   r©  r½   rQ   s          r6   Úget_search_positionzBuffer.get_search_positionÈ  sD   € ð Ÿ™ØÐ3KÐSXð %ó 
ˆð Ð Ø×'Ñ'Ð'à-:Ñ*ˆM˜?Ø"Ð"r5   c                óX   — | j                  |||¬«      }|�|\  }}|| _        || _        yy)zi
        Apply search. If something is found, set `working_index` and
        `cursor_position`.
        r¬  N)r¦  r½   rQ   r­  s          r6   Úapply_searchzBuffer.apply_searchÝ  sG   € ð Ÿ™ØÐ3KÐSXð %ó 
ˆð Ð$Ø-:Ñ*ˆM˜?Ø!.ˆDÔØ#2ˆDÕ ð %r5   c                ó   — d | _         y r>   )r›   rI   s    r6   Úexit_selectionzBuffer.exit_selectionð  s
   € Ø#ˆÕr5   c                óú   ‡— t        | j                  «      }t        j                  |«      \  }Št	        j
                  || j                  j                  d«      «       t	        j                  |«       dˆfd„}‰|fS )za
        Simple (file) tempfile implementation.
        Return (tempfile, cleanup_func).
        úutf-8c                 ó0   •— t        j                  ‰ «       y r>   )ÚosÚunlink)Úfilenames   €r6   Úcleanupz/Buffer._editor_simple_tempfile.<locals>.cleanupþ  s   ø€ Ü�I‰I�hÕr5   r¸   )	r%   rw   rx   Úmkstempr¶  ÚwriterP   ÚencodeÚclose)rB   ÚsuffixÚ
descriptorr¹  r¸  s       @r6   Ú_editor_simple_tempfilezBuffer._editor_simple_tempfileó  se   ø€ ô
 ˜×,Ñ,Ó-ˆÜ'×/Ñ/°Ó7Ñˆ
�Hä
�‰�˜TŸY™Y×-Ñ-¨gÓ6Ô7Ü
�‰�Ôõ	 ð ˜Ð Ð r5   c                óZ  ‡— t        | j                  «      }|s| j                  «       S t        |«      }t        j
                  j                  |«      \  }}t        j
                  j                  |«      r|dd  }t        j                  «       Š|r t        j
                  j                  ‰|«      Št	        j                  ‰«       t        j
                  j                  ‰|«      }t        |dd¬«      5 }|j                  | j                  «       d d d «       dˆfd„}||fS # 1 sw Y   ŒxY w)Nr   r^  r´  )Úencodingc                 ó0   •— t        j                  ‰ «       y r>   )ÚshutilÚrmtree)Údirpaths   €r6   r¹  z0Buffer._editor_complex_tempfile.<locals>.cleanup  s   ø€ Ü�M‰M˜'Õ"r5   r¸   )r%   rx   rÀ  rb   r¶  Úpathrå   ÚisabsÚmkdtemprç   ÚmakedirsÚopenr»  rP   )rB   ÚheadtailÚheadÚtailr¸  Úfhr¹  rÆ  s          @r6   Ú_editor_complex_tempfilezBuffer._editor_complex_tempfile  sä   ø€ ä˜$Ÿ-™-Ó(ˆÙà×/Ñ/Ó1Ð1Ü�x“=ˆô —W‘W—]‘] 8Ó,‰
ˆˆdÜ�7‰7�=‰=˜ÔØ˜˜�8ˆDä×"Ñ"Ó$ˆÙÜ—g‘g—l‘l 7¨DÓ1ˆGä
�‰�GÔô —7‘7—<‘< ¨Ó.ˆÜ�(˜C¨'Õ2°bØ�H‰H�T—Y‘YÔ÷ 3õ	#ð ˜Ð Ð ÷ 3Ð2ús   Ã3D!Ä!D*c                óò   ‡ ‡‡‡— ‰ j                  «       r
t        «       ‚‰ j                  r‰ j                  «       \  ŠŠn‰ j	                  «       \  ŠŠdˆˆˆ ˆfd„}t        «       j                   |«       «      S )ze
        Open code in editor.

        This returns a future, and runs in a thread executor.
        c               “  óv  •K  — 	 t        ˆˆfd„d¬«      ƒ d {  –—† } | rwt        ‰d«      5 }|j                  «       j                  d«      }|j	                  d«      r|d d }t        |t        |«      ¬«      ‰_        d d d «       ‰r‰j                  «         ‰«        y 7 Œ…# 1 sw Y   Œ%xY w#  ‰«        w xY w­w)	Nc                 ó&   •— ‰j                  ‰ «      S r>   )Ú_open_file_in_editor)r¸  rB   s   €€r6   Ú<lambda>z4Buffer.open_in_editor.<locals>.run.<locals>.<lambda>6  s   ø€ ˜D×5Ñ5°hÔ?r5   T)Úin_executorÚrbr´  rä   rl   r"  )	r   rË  ÚreadÚdecodeÚendswithr   rH   rs   Úvalidate_and_handle)Úsuccessr¶   rP   Úcleanup_funcr¸  rB   rÛ  s      €€€€r6   Úrunz"Buffer.open_in_editor.<locals>.run/  s¦   øè ø€ ðô
 !0Ü?ÈTô!÷ �ñ
 Ü˜h¨Ô-°Ø Ÿv™v›xŸ™¨wÓ7˜ð  Ÿ=™=¨Ô.Ø#'¨¨ 9˜Dä(0°dÌCÐPTËIÔ(V˜œ÷ .ñ +Ø×0Ñ0Ô2ñ •ð-ø÷ .Ð-ûñ  •üsD   ƒB9…B- ™BšB- ¬AB!Á=B- ÂB9ÂB- Â!B*Â&B- Â-	B6Â6B9r¸   )r~   r(   rx   rÐ  rÀ  r   r¹   )rB   rÛ  rÞ  rÝ  r¸  s   `` @@r6   Úopen_in_editorzBuffer.open_in_editor   sh   û€ ð �>‰>ÔÜ$Ó&Ð&ð �=Š=Ø%)×%BÑ%BÓ%DÑ"ˆH‘là%)×%AÑ%AÓ%CÑ"ˆH�l÷	ð 	ô< ‹y×/Ñ/±³Ó6Ð6r5   c                ó*  — t         j                  j                  d«      }t         j                  j                  d«      }||dddddg}|D ]8  }|sŒ	 t        j                  t        j                  |«      |gz   «      }|dk(  c S  y	# t        $ r Y ŒGw xY w)
zc
        Call editor executable.

        Return True when we received a zero return code.
        ÚVISUALÚEDITORz/usr/bin/editorz/usr/bin/nanoz/usr/bin/picoz/usr/bin/viz/usr/bin/emacsr   F)r¶  ÚenvironÚgetÚ
subprocessÚcallÚshlexrå   ÚOSError)rB   r¸  ÚvisualÚeditorÚeditorsr’  Ú
returncodes          r6   rÔ  zBuffer._open_file_in_editorO  sœ   € ô —‘—‘ Ó)ˆÜ—‘—‘ Ó)ˆð ØàØØØØð	
ˆó ˆAÚðô ",§¡´·±¸Q³À8À*Ñ1LÓ!M�JØ%¨™?Ò*ð ð øô	 ò áðús   Á0BÂ	BÂBc           
     ó’   — ||z   |z   dk  sJ ‚t        «       j                  | j                  ||||xs t        d¬«      ¬«      «       y)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_lastÚinsert_common_partÚcomplete_eventN)r   r¹   r�   r   )rB   rï  rð  rñ  rò  s        r6   Ústart_completionzBuffer.start_completions  sY   € ð ˜kÑ)Ð,>Ñ>À!ÒCÐCÐCä‹	×(Ñ(Ø×!Ñ!Ø)Ø'Ø#5Ø-ò  <Ü °dÔ;ð "ó õ	
r5   c                óN   ‡ ‡— dd„Št         	 	 	 	 d	 	 	 	 	 	 	 	 	 dˆˆ fd„«       }|S )zÉ
        Create function for asynchronous autocompletion.

        (This consumes the asynchronous completer generator, which possibly
        runs the completion algorithm in another thread.)
        c                ón   — | j                   }|t        |«      |j                  z   d }||j                  k(  S )zŽ
            Return `True` if applying this completion doesn't have any effect.
            (When it doesn't insert any new text.
            N)rR   rH   rT   rP   )rs   rL  rR   Úreplaced_texts       r6   Úcompletion_does_nothingzCBuffer._create_completer_coroutine.<locals>.completion_does_nothing“  sB   € ð
 "*×!<Ñ!<ÐØ.ÜÐ&Ó'¨*×*CÑ*CÑCÐEðˆMð ! J§O¡OÑ3Ð3r5   c              “  ó®  •‡‡K  — ‰j                   }|xs t        d¬«      }‰j                  s‰j                  sy t	        ‰j                   ¬«      Š‰‰_        d	ˆˆfd„}t        j                  «       Šd
ˆˆfd„}t        j                   |«       «      }	 t        ‰j                  j                  ||«      «      4 ƒd {  –—† }|2 3 d {  –—† }	‰j                  j                  |	«       ‰j                  «         |«       s n$t        ‰j                  «      ‰j                  k\  sŒ` d d d «      ƒd {  –—†  |j                  «        ‰j                   j#                  «        ‰j                  }
t        |
«      dk(  r ‰||
d   «      r|
d d …=  |«       �r‰j                  r‰j                  j$                  �y |
s"d ‰_        ‰j                   j#                  «        y | r‰j'                  d«       y |r‰j'                  t        |
«      dz
  «       y |r”t)        ||
«      }|re‰j+                  |«       t        |
«      dkD  r>|
D �cg c]  }|j-                  t        |«      «      ‘Œ c}|
d d  ‰j/                  |
¬«       y d ‰_        y t        |
«      dk(  r‰j'                  d«       y y y ‰j                   j0                  |j0                  k(  ry ‰j                   j0                  j3                  |j0                  «      rt4        ‚y 7 �ŒA7 �Œ96 �Œâ7 �Œ×# 1 ƒd {  –—†7  sw Y   �ŒèxY w# |j                  «        ‰j                   j#                  «        w xY wc c}w ­w)NT)Útext_inserted)r?   c                 ó"   •— ‰j                   ‰ k(  S )ziKeep retrieving completions. Input text has not yet changed
                while generating completions.)rž   )rž   rB   s   €€r6   ÚproceedzLBuffer._create_completer_coroutine.<locals>.async_completer.<locals>.proceed°  s   ø€ ð ×*Ñ*¨nÑ<Ð<r5   c               “  óÖ   •K  — 	 ‰j                   j                  «        ‰ j                  «        t        j                  d«      ƒ d{  –—†  ‰ j                  «       ƒ d{  –—†  Œ`7 Œ7 Œ­w)aÕ  Background loop to refresh the UI at most 3 times a second
                while the completion are loading. Calling
                `on_completions_changed.fire()` for every completion that we
                receive is too expensive when there are many completions. (We
                could tune `Application.max_render_postpone_time` and
                `Application.min_redraw_interval`, but having this here is a
                better approach.)
                g333333Ó?N)r‡   rÓ   Úclearr°   ÚsleepÚwait)Úrefresh_neededrB   s   €€r6   Úrefresh_while_loadingzZBuffer._create_completer_coroutine.<locals>.async_completer.<locals>.refresh_while_loading·  s\   øè ø€ ð Ø×/Ñ/×4Ñ4Ô6Ø"×(Ñ(Ô*Ü!Ÿ-™-¨Ó,×,Ð,Ø(×-Ñ-Ó/×/Ð/ð	 ð -øØ/ús$   ƒAA)ÁA%ÁA)ÁA'Á A)Á'A)r   r   r;  ©r_   rÝ   r¸   )rs   r   rž   rt   r*   r°   r$   Úensure_futurer   Úget_completions_asyncr@   rà   r<  rH   r€   r¥   r‡   rÓ   rA   r1  r   rK  Únew_completion_from_positionr8  rR   r@  Ú_Retry)rï  rð  rñ  rò  rs   rû  r  Úrefresh_taskÚasync_generatorrL  r@   Úcommon_partrW   rž   r   r÷  rB   s                @@€€r6   Úasync_completerz;Buffer._create_completer_coroutine.<locals>.async_completerž  s  úè ø€ ð —}‘}ˆHØ+ÒP¬}È4Ô/PˆNð ×"Ò"¨$¯.ª.Øô -¸t¿}¹}ÔMˆNØ"0ˆDÔö=ô
 %Ÿ]™]›_ˆNö0ô #×0Ñ0Ñ1FÓ1HÓIˆLð3ä#Ø—N‘N×8Ñ8¸À>ÓR÷ô à$Ù,;÷ "˜jØ&×2Ñ2×9Ñ9¸*ÔEØ&×*Ñ*Ô,ñ  'œyÙ!ô   × :Ñ :Ó;Ø#×=Ñ=ó>ð "÷!÷ ð$ ×#Ñ#Ô%ð ×+Ñ+×0Ñ0Ô2à(×4Ñ4ˆKô �;Ó 1Ò$Ñ)@Ø˜+ a™.ô*ð  ¢�Nñ �yð ×+Ò+Ø×*Ñ*×9Ñ9ÐEàñ #Ø*.�DÔ'ð ×/Ñ/×4Ñ4Ô6Øñ  Ø×)Ñ)¨!Õ,á Ø×)Ñ)¬#¨kÓ*:¸QÑ*>Õ?á'Ü"<¸XÀ{Ó"S�KÙ"à×(Ñ(¨Ô5Ü˜{Ó+¨aÒ/ñ *5ó.á)4 Að !"× >Ñ >¼sÀ;Ó?OÕ PØ)4ñ.˜K©˜Nð
 !×1Ñ1¸kÐ1ÕJà26˜DÕ/ô ˜{Ó+¨qÒ0Ø ×1Ñ1°!Õ4ð 1ð1 (ð> —=‘=×3Ñ3°x×7RÑ7RÒRØà—=‘=×3Ñ3×>Ñ>Ø×/Ñ/ôô !�Lðð{ùð"ù¨Oùðù÷ ÷ ò ûð$ ×#Ñ#Ô%ð ×+Ñ+×0Ñ0Õ2üò^.ùsŸ   …BMÂ)L! Â>K?Â?L! ÃLÃLÃ	LÃ
LÃALÄ%LÄ&L! Ä1LÄ2L! Ä6DMÉ!MÉ"BMË?L! ÌLÌLÌL! ÌLÌLÌLÌL! Ì!,MÍM)rs   r   rL  r   r_   rÝ   ©FFFN©
rï  rÝ   rð  rÝ   rñ  rÝ   rò  zCompleteEvent | Noner_   r`   ©Ú_only_one_at_a_time)rB   r
  r÷  s   ` @r6   rŒ   z"Buffer._create_completer_coroutine‹  sf   ù€ ó		4ô 
à!&Ø %Ø',Ø37ð	J	!ØðJ	!àðJ	!ð !%ðJ	!ð 1ð	J	!ð
 õJ	!ó 
ðJ	!ðX Ðr5   c                ó&   ‡ — t         dˆ fd„«       }|S )zl
        Create function for asynchronous auto suggestion.
        (This can be in another thread.)
        c               “  ó  •K  — ‰j                   } ‰j                  s‰j                  sy ‰j                  j                  ‰| «      ƒ d {  –—† }‰j                   | k(  r"|‰_        ‰j                  j                  «        y t        ‚7 Œ;­wr>   )rs   r¡   ru   Úget_suggestion_asyncrˆ   rÓ   r  )rs   r¡   rB   s     €r6   Úasync_suggestorz>Buffer._create_auto_suggest_coroutine.<locals>.async_suggestor3  ss   øè ø€ à—}‘}ˆHð �Š d×&7Ò&7Øà#×0Ñ0×EÑEÀdÈHÓU×UˆJð �}‰} Ò(à",�”Ø×&Ñ&×+Ñ+Õ-ô �ð Vús   ƒABÁBÁ	<Br¸   r  )rB   r  s   ` r6   rŠ   z%Buffer._create_auto_suggest_coroutine-  s   ø€ ô 
ô	ó 
ð	ð$ Ðr5   c                ó&   ‡ — t         dˆ fd„«       }|S )zv
        Create a function for asynchronous validation while typing.
        (This can be in another thread.)
        c               “  óB   •K  — ‰ j                  «       ƒ d {  –—†  y 7 Œ­wr>   )r—  rI   s   €r6   Úasync_validatorz?Buffer._create_auto_validate_coroutine.<locals>.async_validatorP  s   øè ø€ à×&Ñ&Ó(×(Ò(ús   ƒ—˜r¸   r  )rB   r  s   ` r6   rŽ   z&Buffer._create_auto_validate_coroutineH  s   ø€ ô 
ô	)ó 
ð	)ð Ðr5   c                ó´   — | j                  d¬«      }|rD| j                  r| j                  | «      }nd}| j                  «        |s| j                  «        yyy)z?
        Validate buffer and handle the accept action.
        T)r‘  FN)r�  rz   r˜   r‘   )rB   ÚvalidÚ	keep_texts      r6   rÛ  zBuffer.validate_and_handleV  sY   € ð —‘¨�Ó.ˆñ Ø×"Ò"Ø ×/Ñ/°Ó5‘	à!�	à×"Ñ"Ô$áØ—
‘
•ð ð r5   )NNNNrm   rm   rm   FFFNNFTi'  NNNNN)*rt   zCompleter | Noneru   zAutoSuggest | Noner‚   zHistory | Nonerv   zValidator | Nonerw   ústr | Callable[[], str]rx   r  ry   rb   r{   r   r|   r   r}   r   rs   úDocument | Nonerz   zBufferAcceptHandler | Noner~   r   r   r   r€   rn   r„   úBufferEventHandler | Noner…   r  r†   r  r‡   r  rˆ   r  r_   r`   ra   )NF)rs   r  r˜   rÝ   r_   r`   r¸   )r¾   rb   r_   rÝ   )r¾   rn   r_   rÝ   )r¾   rb   r_   r`   )r_   rn   )r¾   rn   r_   r`   )r_   r   )r¾   r   r_   r`   )F)r¾   r   rÙ   rÝ   r_   r`   r  )T)rá   rÝ   r_   r`   )rè   zIterable[int]ré   úCallable[[str], str]r_   rb   )ré   r  r_   r`   )ró   rn   rô   rn   ré   r  r_   r`   ©r   )rù   rn   r_   r`   )r   F)rù   rn   r  rÝ   r_   r`   )rù   rn   r_   rb   )r  )r  rb   r_   r`   )rM   rn   r_   r`   )rù   rn   r2  rÝ   r_   r`   )r@   zlist[Completion]r_   r*   rc   )rL  r   r_   r`   )rD  rn   r_   rÝ   )rj   r^   rZ  rÝ   r_   r`   r>   )rj   r^   r_   r`   )re  r#   r_   r`   )ri  rÝ   r_   r   )r_   r   )rt  r   ro  r!   rù   rn   r_   r`   )rw  rÝ   r_   r`   )FTT)
rt  rb   r�  rÝ   r‚  rÝ   rƒ  rÝ   r_   r`   )r‘  rÝ   r_   rÝ   )Fr   )r¤  r    rœ  rÝ   rù   rn   r_   ztuple[int, int] | None)r¤  r    r_   r   )Tr   )r¤  r    rœ  rÝ   rù   rn   r_   rn   )r¤  r    rœ  rÝ   rù   rn   r_   r`   )r_   ztuple[str, Callable[[], None]])rÛ  rÝ   r_   zasyncio.Task[None])r¸  rb   r_   rÝ   r  r  )r_   z(Callable[..., Coroutine[Any, Any, None]])r_   z'Callable[[], Coroutine[Any, Any, None]])Pr0   r1   r2   r3   rC   rJ   r‘   r»   rÁ   rÅ   rd   rP   ÚsetterrQ   r½   rÈ   rÎ   rs   r×   rÞ   râ   rë   rñ   rõ   rü   rÿ   r  r	  r  r  r  r  r   r(  r,  r.  r  r  r6  r8  rG  r1  rM  rO  rQ  r  r  ra  rc  r#   Ú
CHARACTERSrf  rl  rh  r!   rr  rs  rx  r|  r~  rK  rŒ  rŽ  r�  r—  r˜   r¦  rª  r®  r°  r²  rÀ  rÐ  rß  rÔ  ró  rŒ   rŠ   rŽ   rÛ  r4   r5   r6   r)   r)   ›   st  „ ñ9ðz '+Ø+/Ø"&Ø&*Ø35Ø,.ØØ.3Ø.3Ø.3Ø$(Ø59Ø"'Ø"&Ø).Ø59Ø48Ø@DØ<@Ø7;ð+O&à#ðO&ð )ðO&ð  ð	O&ð
 $ðO&ð 1ðO&ð *ðO&ð ðO&ð  ,ðO&ð  ,ðO&ð  ,ðO&ð "ðO&ð 3ðO&ð  ðO&ð  ðO&ð  $'ð!O&ð" 3ð#O&ð$ 2ð%O&ð& %>ð'O&ð( !:ð)O&ð* 5ð+O&ð, 
ó-O&óbNð KPð?!Ø'ð?!ØCGð?!à	ó?!óB3Iónó(;ð ò7ó ð7ð 
‡[�[ò,ó ð,ð2 ò&ó ð&ð ×Ñò,ó ð,ð" ò$ó ð$ð ×Ñò!ó ð!óFó(/ð$ ò
ó ð
ð ‡_�_ò!ó ð!ô!,ðF ò)ó ð)ô"ð  à*ð ð 1ð ð 
ó	 ó@
ð
Øð
Ø!ð
Ø7Kð
à	ó
ô*TôUô0ô0ð NSðSØðSØFJðSà	óSð& NSðSØðSØFJðSà	óSô$ô,ôô 
ó0
Gó2ô)ð0 ;@ð)Øð)Ø37ð)à	ó)ó,'ó#ó"!óH$ó"*ó	,ó
ôMô02ô*1(ôf4ð /<×.FÑ.FðTØ+ðTà	óTôó&.ð !*§¡Øð	7àð7ð ð7ð ð	7ð
 
ó7ô*#ô"ô
!ð  Ø Øð2Jàð2Jð ð2Jð ð	2Jð
 ð2Jð 
ó2Jóhó @ôó>(#óT	6ð */Øð	V9à!ðV9ð #'ðV9ð ð	V9ð
 
 óV9ópð8 *.Øð	#à!ð#ð #'ð#ð ð	#ð
 
ó#ð0 *.Øð	3à!ð3ð #'ð3ð ð	3ð
 
ó3ó&$ó!ó !ô:-7ó^"ðL #Ø!Ø#(Ø/3ð
àð
ð ð
ð !ð	
ð
 -ð
ð 
ó
ó0`óDð6à	0óôr5   Ú_T.)Úboundc                óT   ‡ ‡— dŠt        ‰ «      dˆ ˆfd„«       }t        t        |«      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.
    Fc               Ÿ  ót   •K  — ‰ry dŠ	 	 	  ‰| i |¤Žƒ d {  –—†  	 dŠy 7 Œ# t         $ r Y Œ#w xY w# dŠw xY w­w)NTF)r  )rï   ÚkwÚ	coroutineÚrunnings     €€r6   Únew_coroutinez*_only_one_at_a_time.<locals>.new_coroutinev  s\   øè ø€ ñ
 Øàˆð		Øð Ù# QÐ-¨"Ñ-×-Ð-ð  à‰Gð .ùÜò Ùðûð
 ‰Güs4   ƒ8Š1 Œ" — ˜" �8 " ¢	.«1 ­.®1 ±5µ8)rï   r   r$  r   r_   r   )r   r   r   )r%  r'  r&  s   ` @r6   r  r  l  s0   ù€ ð €Gä
ˆ9Óõó ðô( ”�MÓ"Ð"r5   c                  ó   — e Zd ZdZy)r  zRetry in `_only_one_at_a_time`.Nr/   r4   r5   r6   r  r  Ž  s   „ Ú%r5   r  c                ó@  ‡— | j                   j                  }| j                   j                  }t        ||«      }d|z  Š| j	                  |ˆfd„«      }t        |t        |«      j                  |d«      «      | _         | xj                  |t        ‰«      z   z  c_        y)z3
    Indent text of a :class:`.Buffer` object.
    ú    c                ó   •— ‰| z   S r>   r4   )r'  Úindent_contents    €r6   rÕ  zindent.<locals>.<lambda>œ  s
   ø€ ¸NÈQÒ<Nr5   r   N©	rs   r  r  rS  rë   r   Útranslate_row_col_to_indexrQ   rH   )	ÚbufferÚfrom_rowÚto_rowrù   Úcurrent_rowÚcurrent_colÚ
line_rangerY   r,  s	           @r6   r+   r+   ’  s�   ø€ ð —/‘/×5Ñ5€KØ—/‘/×5Ñ5€KÜ�x Ó(€Jð ˜e‘^€NØ×%Ñ% jÓ2NÓO€HÜØ”(˜8Ó$×?Ñ?ÀÈQÓOó€F„Oð
 ×Ò˜k¬C°Ó,?Ñ?Ñ?Ör5   c                óF  ‡	— | j                   j                  }| j                   j                  }t        ||«      }d|z  Š	dˆ	fd„}| j	                  ||«      }t        |t        |«      j                  |d«      «      | _         | xj                  |t        ‰	«      z
  z  c_        y)z5
    Unindent text of a :class:`.Buffer` object.
    r*  c                óf   •— ‰}| j                  |«      r| t        |«      d  S | j                  «       S r>   )r@  rH   r  )rP   Úremover,  s     €r6   Ú	transformzunindent.<locals>.transform¯  s1   ø€ ØˆØ�?‰?˜6Ô"Øœ˜F›˜Ð&Ð&à—;‘;“=Ð r5   r   N)rP   rb   r_   rb   r-  )
r/  r0  r1  rù   r2  r3  r4  r8  rY   r,  s
            @r6   r,   r,   ¥  s‘   ø€ ð —/‘/×5Ñ5€KØ—/‘/×5Ñ5€KÜ�x Ó(€Jà˜e‘^€Nõ!ð ×%Ñ% j°)Ó<€HÜØ”(˜8Ó$×?Ñ?ÀÈQÓOó€F„Oð
 ×Ò˜k¬C°Ó,?Ñ?Ñ?Ör5   c           	     ó  — | j                   j                  d«      }|d| }||dz   d }|||dz    }|�rXt        j                  d|d   «      }|r|j	                  «       nd}|d   d| j                  dd«      }	dj                  |«      j                  «       }
| j                  xs dt        |	«      z
  }|	g}d}|
D ]r  }|rOt        |«      |z   dz   |kD  r%|j                  d«       |j                  |	«       d}n|j                  d	«       |dz  }|j                  |«       |t        |«      z  }Œt |d
   dk7  r|j                  d«       t        dj                  ||z   |z   «      t        dj                  ||z   «      «      ¬«      | _        yy)zi
    Reformat text, taking the width into account.
    `to_row` is included.
    (Vi 'gq' operator.)
    TNr   z^\s*r   rä   rm   éP   r  rl   r"  )rP   r%  ÚreÚsearchÚendÚreplacerç   rå   r�   rH   rà   r   rs   )r/  r0  r1  rê   Úlines_beforeÚlines_afterÚlines_to_reformatÚmatchÚlengthr+   r_  ÚwidthÚreshaped_textÚcurrent_widthr^  s                  r6   r-   r-   À  s   € ð �K‰K×"Ñ" 4Ó(€EØ˜˜(Ð#€LØ˜ ™
˜Ð%€KØ˜h¨°!©Ð4Ðâä—	‘	˜'Ð#4°QÑ#7Ó8ˆÙ %�—‘”¨1ˆà" 1Ñ% g vÐ.×6Ñ6°t¸RÓ@ˆð —‘Ð)Ó*×0Ñ0Ó2ˆð ×"Ñ"Ò( b¬C°«KÑ7ˆØ˜ˆØˆÛˆAÙÜ�q“6˜MÑ)¨AÑ-°Ò5Ø!×(Ñ(¨Ô.Ø!×(Ñ(¨Ô0Ø$%‘Mà!×(Ñ(¨Ô-Ø! QÑ&�Mà× Ñ  Ô#ØœS ›VÑ#‰Mð ð ˜Ñ Ò$Ø× Ñ  Ô&ô #Ø—‘˜¨Ñ5¸ÑCÓDÜ §¡¨°}Ñ(DÓ EÓFô
ˆ�ð? r5   )r%  r   r_   r   r  )
r/  r)   r0  rn   r1  rn   rù   rn   r_   r`   )r/  r)   r0  rn   r1  rn   r_   r`   )Ur3   Ú
__future__r   r°   Úloggingr¶  r;  rç  rÄ  rå  rx   Úcollectionsr   Úenumr   Ú	functoolsr   Útypingr   r   r	   r
   r   r   Úapplication.currentr   Úapplication.run_in_terminalr   ru   r   r   Úcacher   Ú	clipboardr   rL  r   r   r   r   r   rs   r   Ú	eventloopr   Úfiltersr   r   r‚   r   r   r<  r   r    r¨  r!   r"   r#   Úutilsr$   r%   Ú
validationr&   r'   Ú__all__Ú	getLoggerr0   r´   Ú	Exceptionr(   r8   r*   ÚcompilerY  rf   ÚBufferEventHandlerrÝ   ÚBufferAcceptHandlerr)   r   r  r  r+   r,   r-   r4   r5   r6   Ú<module>r[     sC  ðñõ
 #ã Û Û 	Û 	Û Û Û Û Ý Ý Ý ß D× Då (Ý 8ß 1Ý  Ý $÷õ õ Ý ß ,ß -ß 0ß ?Ñ ?ß  ß 2ò€ð 
ˆ×	Ñ	˜8Ó	$€ô5˜ô 5ô�dô ÷?ñ ?ðD �2—:‘:Ð6Ó7Ð ÷^ñ ^ð  ˜x˜j¨$Ð.Ñ/Ð Ø ˜z¨4Ð/Ñ0Ð ÷Kñ Kñ\6 ˆT˜ # y°°c¸4°Ñ'@Ð"@ÑAÔB€ó#ôD&ˆYô &ô@ô&@ô6-
r5   