Ë
    V.j×   ã                  óð  — d Z ddlmZ ddlZddlmZmZmZ ddlm	Z	 ddl
mZ dd	lmZ d
gZ ej                  d ej                   d«      z   dz   «      Z ej                  d ej                   d«      z   dz   «      Z ej                  d ej                   d«      z   dz   «      Z ej                  d ej                   d«      z   dz   «      Z G d„ d«      Z G d„ deeef   «      Z e«       Z G d„ d
«      Zy)z 
Parser for VT100 input stream.
é    )ÚannotationsN)ÚCallableÚDictÚ	Generatoré   )ÚKeyPress)ÚKeysé   )ÚANSI_SEQUENCESÚVt100ParserÚ^z[z
\d+;\d+R\Zz(<?[\d;]+[mM]|M...)\Zz[\d;]*\Zz(<?[\d;]*|M.{0,2})\Zc                  ó   — e Zd ZdZy)Ú_Flushz8Helper object to indicate flush operation to the parser.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úcC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\site-packages\prompt_toolkit/input/vt100_parser.pyr   r   $   s   „ ÙBàr   r   c                  ó   — e Zd ZdZdd„Zy)Ú_IsPrefixOfLongerMatchCachez„
    Dictionary that maps input sequences to a boolean indicating whether there is
    any key that start with this characters.
    c                ó¸   ‡— t         j                  ‰«      st        j                  ‰«      rd}n&t        ˆfd„t	        j
                  «       D «       «      }|| ‰<   |S )NTc              3  óT   •K  — | ]  \  }}|j                  ‰«      r	|‰k7  r|–— Œ! y ­w©N)Ú
startswith)Ú.0ÚkÚvÚprefixs      €r   Ú	<genexpr>z:_IsPrefixOfLongerMatchCache.__missing__.<locals>.<genexpr>9   s/   øè ø€ ð á2‘D�A�qØ—<‘< Ô'¨A°ªKô Ù2ùs   ƒ%()Ú_cpr_response_prefix_reÚmatchÚ_mouse_event_prefix_reÚanyr   Úitems)Úselfr    Úresults    ` r   Ú__missing__z'_IsPrefixOfLongerMatchCache.__missing__0   s]   ø€ ô #×(Ñ(¨Ô0Ô4J×4PÑ4PØô5
ð ‰Fô ó ä*×0Ñ0Ô2óó ˆFð ˆˆV‰Øˆr   N)r    ÚstrÚreturnÚbool)r   r   r   r   r)   r   r   r   r   r   *   s   „ ñô
r   r   c                  óf   — e Zd ZdZdd„Zddd„Zdd„Zdd„Zdd„Z	 	 	 	 	 	 dd„Z	dd„Z
dd	„Zdd
„Zy)r   aZ  
    Parser for VT100 input stream.
    Data can be fed through the `feed` method and the given callback will be
    called with KeyPress objects.

    ::

        def callback(key):
            pass
        i = Vt100Parser(callback)
        i.feed('data...')

    :attr feed_key_callback: Function that will be called when a key is parsed.
    c                ó2   — || _         | j                  «        y r   )Úfeed_key_callbackÚreset)r'   r/   s     r   Ú__init__zVt100Parser.__init__Y   s   € Ø!2ˆÔØ�
‰
�r   c                ó2   — d| _         | j                  «        y )NF)Ú_in_bracketed_pasteÚ_start_parser)r'   Úrequests     r   r0   zVt100Parser.reset]   s   € Ø#(ˆÔ Ø×ÑÕr   c                ód   — | j                  «       | _        | j                  j                  d«       y)z-
        Start the parser coroutine.
        N)Ú_input_parser_generatorÚ_input_parserÚsend©r'   s    r   r4   zVt100Parser._start_parsera   s)   € ð "×9Ñ9Ó;ˆÔØ×Ñ×Ñ Õ%r   c                óÈ   — t         j                  |«      rt        j                  S t        j                  |«      rt        j
                  S 	 t        |   S # t        $ r Y yw xY w)zD
        Return the key (or keys) that maps to this prefix.
        N)Ú_cpr_response_rer#   r	   ÚCPRResponseÚ_mouse_event_reÚVt100MouseEventr   ÚKeyError)r'   r    s     r   Ú
_get_matchzVt100Parser._get_matchh   sZ   € ô ×!Ñ! &Ô)Ü×#Ñ#Ð#ä×"Ñ" 6Ô*Ü×'Ñ'Ð'ð	Ü! &Ñ)Ð)øÜò 	Ùð	ús   ÁA Á	A!Á A!c              #  ó¼  K  — d}d}d}	 d}|rd}nd–—}t        |t        «      rd}n||z  }|r¬t        |   }| j                  |«      }|s|s|r| j	                  ||«       d}nw|s|ss|sqd}d}t        t        |«      dd«      D ]5  }| j                  |d| «      }|sŒ| j	                  ||d| «       ||d }d}Œ7 |s| j	                  |d   |d   «       |dd }ŒÒ­w)zA
        Coroutine (state machine) for the input parser.
        Ú FTNr   éÿÿÿÿr
   )Ú
isinstancer   Ú _IS_PREFIX_OF_LONGER_MATCH_CACHErA   Ú_call_handlerÚrangeÚlen)	r'   r    ÚretryÚflushÚcÚis_prefix_of_longer_matchr#   ÚfoundÚis	            r   r7   z#Vt100Parser._input_parser_generator{   s  è ø€ ð ˆØˆØˆàØˆEáØ‘ò �ä˜a¤Ô(Ø ‘Eà˜a‘K�Fñ Ü,LÈVÑ,TÐ)ØŸ™¨Ó/�ñ Ñ!:ÁØ×&Ñ& u¨fÔ5Ø‘Fñ Ñ#<ÁeØ!�EØ �Eô #¤3 v£;°°2Ö6˜Ø $§¡°°r¸°
Ó ;˜Ú Ø ×.Ñ.¨u°f¸R¸a°jÔAØ%+¨A¨B Z˜FØ$(™Eð 7ñ !Ø×*Ñ*¨6°!©9°f¸Q±iÔ@Ø!'¨¨ ˜ðQ ùs   ‚BCÂ>Cc                óø   — t        |t        «      r-t        |«      D ]  \  }}| j                  ||dk(  r|nd«       Œ  y|t        j
                  k(  rd| _        d| _        y| j                  t        ||«      «       y)z&
        Callback to handler.
        r   rC   TN)
rE   ÚtupleÚ	enumeraterG   r	   ÚBracketedPaster3   Ú_paste_bufferr/   r   )r'   ÚkeyÚinsert_textrO   r   s        r   rG   zVt100Parser._call_handler­   so   € ô �cœ5Ô!ô
 " #ž‘��1Ø×"Ñ" 1°Q¸!²V¡kÀÕDñ 'ð ”d×)Ñ)Ò)Ø+/�Ô(Ø%'�Õ"à×&Ñ&¤x°°[Ó'AÕBr   c                ó$  — | j                   r´| xj                  |z  c_        d}|| j                  v rŽ| j                  j                  |«      }| j                  d| }| j                  t	        t
        j                  |«      «       d| _         | j                  |t        |«      z   d }d| _        | j                  |«       yyt        |«      D ]B  \  }}| j                   r| j                  ||d «        y| j                  j                  |«       ŒD y)zV
        Feed the input stream.

        :param data: Input string (unicode).
        z[201~NFrC   )r3   rT   Úindexr/   r   r	   rS   rI   ÚfeedrR   r8   r9   )r'   ÚdataÚend_markÚ	end_indexÚpaste_contentÚ	remainingrO   rL   s           r   rY   zVt100Parser.feedÁ   sý   € ð ×#Ò#Ø×Ò $Ñ&ÕØ"ˆHà˜4×-Ñ-Ñ-Ø ×.Ñ.×4Ñ4°XÓ>�	ð !%× 2Ñ 2°:°IÐ >�Ø×&Ñ&¤x´×0CÑ0CÀ]Ó'SÔTð ,1�Ô(Ø ×.Ñ.¨y¼3¸x»=Ñ/HÐ/JÐK�	Ø%'�Ô"à—	‘	˜)Õ$ð .ô  " $ž‘��1Ø×+Ò+ð —I‘I˜d 1 2˜hÔ'Ùà×&Ñ&×+Ñ+¨AÕ.ñ (r   c                óJ   — | j                   j                  t        «       «       y)a=  
        Flush the buffer of the input stream.

        This will allow us to handle the escape key (or maybe meta) sooner.
        The input received by the escape key is actually the same as the first
        characters of e.g. Arrow-Up, so without knowing what follows the escape
        sequence, we don't know whether escape has been pressed, or whether
        it's something else. This flush function should be called after a
        timeout, and processes everything that's still in the buffer as-is, so
        without assuming any characters will follow.
        N)r8   r9   r   r:   s    r   rK   zVt100Parser.flushç   s   € ð 	×Ñ×Ñ¤£Õ)r   c                óF   — | j                  |«       | j                  «        y)z8
        Wrapper around ``feed`` and ``flush``.
        N)rY   rK   )r'   rZ   s     r   Úfeed_and_flushzVt100Parser.feed_and_flushõ   s   € ð 	�	‰	�$ŒØ�
‰
�r   N)r/   zCallable[[KeyPress], None]r+   ÚNone)F)r5   r,   r+   rb   )r+   rb   )r    r*   r+   zNone | Keys | tuple[Keys, ...])r+   z#Generator[None, str | _Flush, None])rU   zstr | Keys | tuple[Keys, ...]rV   r*   r+   rb   )rZ   r*   r+   rb   )r   r   r   r   r1   r0   r4   rA   r7   rG   rY   rK   ra   r   r   r   r   r   F   sR   „ ñó$ôó&óó&0,ðdCØ0ðCØ?BðCà	óCó($/óL*ôr   )r   Ú
__future__r   ÚreÚtypingr   r   r   Úkey_binding.key_processorr   Úkeysr	   Úansi_escape_sequencesr   Ú__all__ÚcompileÚescaper<   r>   r"   r$   r   r*   r,   r   rF   r   r   r   r   Ú<module>rl      s  ðñõ #ã 	ß ,Ñ ,å 0Ý Ý 1ð ð€ð �2—:‘:˜c I B§I¡I¨gÓ$6Ñ6¸ÑFÓGÐ ð �"—*‘*˜S 9 2§9¡9¨WÓ#5Ñ5Ð8PÑPÓQ€ð
 %˜"Ÿ*™* S¨9¨2¯9©9°WÓ+=Ñ%=ÀÑ%KÓLÐ à#˜Ÿ™ C¨)¨"¯)©)°GÓ*<Ñ$<Ð?VÑ$VÓWÐ ÷	ñ 	ô $ s¨D y¡/ô ñ2 $?Ó#@Ð  ÷tò tr   