Ë
    ˜Qj~  ã                  óØ   — d Z ddlmZ ddlZddlZddlmZ ddlmZ  ej                  d«      Z
 ej                  d«      Z G d	„ d
ej                  «      Z G d„ dej                  «      Zy)zC
OSC 8 hyperlink parsing and measurement.

.. versionadded:: 0.7.0
é    )ÚannotationsNé   )Úwidth)Ú_SEQUENCE_CLASSIFYz*\x1b]8;([^;]*);([^\x07\x1b]*)(\x07|\x1b\\)z\x1b]8;;(\x07|\x1b\\)c                  óZ   — e Zd ZU dZded<   dZded<   dZded<   edd„«       Zdd	„Z	dd
„Z
y)ÚHyperlinkParamszí
    Parsed parameters from an OSC 8 hyperlink open sequence.

    :param url: The hyperlink URL.
    :param params: Colon-separated metadata string (often empty).
    :param terminator: Sequence terminator (``\x07`` or ``\x1b\\``).
    ÚstrÚurlÚ ÚparamsúÚ
terminatorc                ó¢   — t         j                  |«      }|€y | |j                  d«      |j                  d«      |j                  d«      ¬«      S )a%  
        Parse an OSC 8 open sequence string.

        Returns ``None`` if *seq* is not a valid OSC 8 open.

        Example::

            >>> HyperlinkParams.parse('\x1b]8;;http://example.com\x07')
            HyperlinkParams(url='http://example.com', params='', terminator='\\x07')
        Né   r   é   )r
   r   r   )ÚHYPERLINK_OPEN_REÚmatchÚgroup)ÚclsÚseqÚms      úM/var/www/html/truck-me/venv/lib/python3.12/site-packages/wcwidth/hyperlink.pyÚparsezHyperlinkParams.parse#   sC   € ô ×#Ñ# CÓ(ˆØˆ9ØÙ�q—w‘w˜q“z¨!¯'©'°!«*ÀÇÁÈÃÔLÐLó    c                óR   — d| j                   › d| j                  › | j                  › �S )z(Generate the OSC 8 open escape sequence.z]8;ú;)r   r
   r   ©Úselfs    r   Ú	make_openzHyperlinkParams.make_open4   s&   € à˜Ÿ™˜ Q t§x¡x j°·±Ð0AÐBÐBr   c                ó    — d| j                   › �S )z)Generate the OSC 8 close escape sequence.z]8;;)r   r   s    r   Ú
make_closezHyperlinkParams.make_close8   s   € à˜$Ÿ/™/Ð*Ð+Ð+r   N)r   r	   ÚreturnzHyperlinkParams | None©r"   r	   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   Úclassmethodr   r   r!   © r   r   r   r      sA   … ñð 
ƒHØ€FˆCÓØ€J�ÓàòMó ðMó Cô,r   r   c                  ót   — e Zd ZU dZded<   ded<   edd„«       Zddd	d
œ	 	 	 	 	 	 	 dd„Zeddd„«       Zdd„Z	y)Ú	Hyperlinkz·
    A complete OSC 8 hyperlink with target and inner text.

    :param params: Parsed open sequence parameters.
    :param text: Inner text between the open and close sequences.
    r   r   r	   Útextc                ót   — t         j                  ||«      }|€y|j                  «       |j                  «       fS )añ  
        Find the matching OSC 8 close sequence.

        Searches 'text' starting at 'open_end', the position just past the open
        sequence.  Returns position of close sequence ``(close_start,
        close_end)`` or ``(-1, -1)`` if not found.

        Per the OSC 8 specification, terminal emulators treat hyperlinks as a
        state attribute, not as nested HTML anchors.  A close sequence closes
        the current hyperlink regardless of how many open sequences preceded it.
        ©éÿÿÿÿr0   )ÚHYPERLINK_CLOSE_REÚsearchÚstartÚend)r   r-   Úopen_endr   s       r   Ú
find_closezHyperlink.find_closeH   s5   € ô ×%Ñ% d¨HÓ5ˆØˆ9ØØ—‘“	˜1Ÿ5™5›7Ð#Ð#r   r   é   r   ©Úcontrol_codesÚtabsizeÚambiguous_widthc               ó4   — t        | j                  |||¬«      S )a1  
        Measure the display width of the hyperlink's inner text.

        Delegates to :func:`wcwidth.width` with the given parameters.

        Example::

            >>> hl = Hyperlink.parse('\x1b]8;;http://example.com\x07Hello\x1b]8;;\x07', 0)
            >>> hl.display_width()
            5
        r8   )Ú_widthr-   )r   r9   r:   r;   s       r   Údisplay_widthzHyperlink.display_widthZ   s!   € ô$ Ø�I‰IØ'ØØ+ô	
ð 	
r   c                ó  — t        j                  ||«      }|€yt        j                  |j	                  «       «      }|€y| j                  ||j                  «       «      \  }}||fdk(  ry | |||j                  «       | ¬«      S )a  
        Parse a complete OSC 8 hyperlink unit from *text* at position *start*.

        Locates the open sequence, finds the matching close, and returns a
        ``Hyperlink`` containing the parsed parameters and inner text.  Returns
        ``None`` if the text at *start* is not a complete OSC 8 hyperlink.

        Example::

            >>> Hyperlink.parse('\x1b]8;;http://example.com\x07Hello\x1b]8;;\x07')
            Hyperlink(params=HyperlinkParams(url='http://example.com', ...), text='Hello')
        Nr/   )r   r-   )r   r   r   r   r   r6   r4   )r   r-   r3   r   r   Úclose_startÚ	close_ends          r   r   zHyperlink.parses   s�   € ô ×$Ñ$ T¨5Ó1ˆØˆ9ØÜ ×&Ñ& q§w¡w£yÓ1ˆØˆ>ØØ!$§¡°°a·e±e³gÓ!>Ñˆ�YØ˜Ð# xÒ/ØÙ˜& t¨A¯E©E«G°KÐ'@ÔAÐAr   c                ó†   — | j                   j                  «       | j                  z   | j                   j                  «       z   S )z5Rebuild the complete OSC 8 hyperlink escape sequence.)r   r   r-   r!   r   s    r   Úmake_sequencezHyperlink.make_sequenceŒ   s0   € à�{‰{×$Ñ$Ó&¨¯©Ñ2°T·[±[×5KÑ5KÓ5MÑMÐMr   N)r-   r	   r5   Úintr"   ztuple[int, int])r9   z+typing.Literal['parse', 'strict', 'ignore']r:   rD   r;   rD   r"   rD   )r   )r-   r	   r3   rD   r"   zHyperlink | Noner#   )
r$   r%   r&   r'   r(   r)   r6   r>   r   rC   r*   r   r   r,   r,   =   s}   … ñð ÓØ
ƒIàò$ó ð$ð( FMØØ ñ
ð Cð
ð ð	
ð
 ð
ð 
ó
ð2 óBó ðBô0Nr   r,   )r'   Ú
__future__r   ÚreÚtypingr=   r   Úescape_sequencesr   Úcompiler   r1   Ú
NamedTupler   r,   r*   r   r   ú<module>rK      sl   ðñõ #ó 
ã õ $Ý 0à�B—J‘JÐLÓMÐ Ø�R—Z‘ZÐ 8Ó9Ð ô$,�f×'Ñ'ô $,ôNQN�×!Ñ!õ QNr   