§
    ‹Ÿj~  ã                  óÊ   — 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dS )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                  ób   — 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
dS )Ú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úÚ
terminatorÚseqÚreturnúHyperlinkParams | Nonec                óÌ   — t                                |¦  «        }|€dS  | |                     d¦  «        |                     d¦  «        |                     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)Úclsr   Úms      ú^/var/www/finuniver-perm.ru/html/student/venv/lib/python3.11/site-packages/wcwidth/hyperlink.pyÚparsezHyperlinkParams.parse#   sV   € õ ×#Ò# CÑ(Ô(ˆØˆ9Ø�4Øˆs�q—w’w˜q‘z”z¨!¯'ª'°!©*¬*ÀÇÂÈÁÄÐLÑLÔLÐLó    c                ó4   — 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#   € àB˜œÐBÐB t¤xÐB°´ÐBÐ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	   r   r   ©r   r	   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   Úclassmethodr   r!   r#   © r   r   r   r      s›   € € € € € € ðð ð €H€H�HØ€FÐÐÐÑØ€JÐÐÐÑàðMð Mð Mñ „[ðMð Cð Cð Cð 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	dS )Ú	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	   ÚtextÚopen_endÚintr   útuple[int, int]c                ó�   — t                                ||¦  «        }|€dS |                     ¦   «         |                     ¦   «         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.
        N©éÿÿÿÿr4   )ÚHYPERLINK_CLOSE_REÚsearchÚstartÚend)r   r.   r/   r   s       r   Ú
find_closezHyperlink.find_closeH   s>   € õ ×%Ò% d¨HÑ5Ô5ˆØˆ9Ø�8Ø—’‘	”	˜1Ÿ5š5™7œ7Ð#Ð#r   r   é   r   ©Úcontrol_codesÚtabsizeÚambiguous_widthr<   ú+typing.Literal['parse', 'strict', 'ignore']r=   r>   c               ó2   — 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
        r;   )Ú_widthr.   )r    r<   r=   r>   s       r   Údisplay_widthzHyperlink.display_widthZ   s)   € õ$ ØŒIØ'ØØ+ð	
ñ 
ô 
ð 	
r   r   r7   úHyperlink | Nonec                óL  — t          j        ||¦  «        }|€dS t                               |                     ¦   «         ¦  «        }|€dS |                      ||                     ¦   «         ¦  «        \  }}||fdk    rdS  | |||                     ¦   «         |…         ¬¦  «        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')
        Nr3   )r   r.   )r   r   r   r   r   r9   r8   )r   r.   r7   r   r   Úclose_startÚ	close_ends          r   r   zHyperlink.parses   s¡   € õ Ô$ T¨5Ñ1Ô1ˆØˆ9Ø�4Ý ×&Ò& q§w¢w¡y¤yÑ1Ô1ˆØˆ>Ø�4Ø!$§¢°°a·e²e±g´gÑ!>Ô!>Ñˆ�YØ˜Ð# xÒ/Ð/Ø�4Øˆs˜& t¨A¯EªE©G¬G°KÐ,?Ô'@ÐAÑAÔAÐAr   c                óx   — | j                              ¦   «         | j        z   | 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Ô5MÑMÐMr   N)r.   r	   r/   r0   r   r1   )r<   r?   r=   r0   r>   r0   r   r0   )r   )r.   r	   r7   r0   r   rC   r$   )
r%   r&   r'   r(   r)   r*   r9   rB   r   rH   r+   r   r   r-   r-   =   sÄ   € € € € € € ðð ð ÐÐÑØ€I€I�Iàð$ð $ð $ñ „[ð$ð( FMØØ ð
ð 
ð 
ð 
ð 
ð 
ð2 ðBð Bð Bð Bñ „[ðBð0Nð Nð Nð Nð Nð Nr   r-   )r(   Ú
__future__r   ÚreÚtypingrA   r   Úescape_sequencesr   Úcompiler   r5   Ú
NamedTupler   r-   r+   r   r   ú<module>rO      sü   ððð ð #Ð "Ð "Ð "Ð "Ð "ð 
€	€	€	à €€€ð $Ð #Ð #Ð #Ð #Ð #Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0à�B”JÐLÑMÔMÐ Ø�R”ZÐ 8Ñ9Ô9Ð ð$,ð $,ð $,ð $,ð $,�fÔ'ñ $,ô $,ð $,ðNQNð QNð QNð QNð QN�Ô!ñ QNô QNð QNð QNð QNr   