ó
    Ð]j~  ã                  óØ   • S r SSKJr  SSKrSSKrSSKJr  SSKJr  \R                  " S5      r
\R                  " S5      r " S	 S
\R                  5      r " S S\R                  5      rg)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                  óh   • \ rS rSr% SrS\S'   SrS\S'   SrS\S'   \SS	 j5       r	SS
 jr
SS jrSrg)ÚHyperlinkParamsé   zÙ
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                óž   • [         R                  U5      nUc  gU " UR                  S5      UR                  S5      UR                  S5      S9$ )zõ
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      ÚN/home/mande/repo/quber/.venv/lib/python3.13/site-packages/wcwidth/hyperlink.pyÚparseÚHyperlinkParams.parse#   sC   € ô ×#Ñ# CÓ(ˆØ‰9ØÙ�q—w‘w˜q“z¨!¯'©'°!«*ÀÇÁÈÃÑLÐLó    c                óR   • SU R                    SU R                   U R                   3$ )z(Generate the OSC 8 open escape sequence.z]8;Ú;)r   r   r   ©Úselfs    r   Ú	make_openÚHyperlinkParams.make_open4   s&   € à˜Ÿ™˜ Q t§x¡x j°·±Ð0AÐBÐBr   c                ó    • SU R                    3$ )z)Generate the OSC 8 close escape sequence.z]8;;)r   r   s    r   Ú
make_closeÚHyperlinkParams.make_close8   s   € à˜$Ÿ/™/Ð*Ð+Ð+r   © N)r   r
   ÚreturnzHyperlinkParams | None©r'   r
   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r   r   Úclassmethodr   r!   r$   Ú__static_attributes__r&   r   r   r   r      sA   ‡ ñð 
ƒHØ€FˆCÓØ€J�ÓàóMó ðMô C÷,r   r   c                  óˆ   • \ rS rSr% SrS\S'   S\S'   \SS j5       rSS	S
S.       SS jjr\SSS jj5       r	SS jr
Srg)Ú	Hyperlinké=   z§
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   • [         R                  X5      nUc  gUR                  5       UR                  5       4$ )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.
©éÿÿÿÿr7   )ÚHYPERLINK_CLOSE_REÚsearchÚstartÚend)r   r4   Úopen_endr   s       r   Ú
find_closeÚHyperlink.find_closeH   s3   € ô ×%Ñ% dÓ5ˆØ‰9ØØ—‘“	˜1Ÿ5™5›7Ð#Ð#r   r   é   r   ©Úcontrol_codesÚtabsizeÚambiguous_widthc               ó.   • [        U R                  UUUS9$ )zù
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@   )Ú_widthr4   )r    rA   rB   rC   s       r   Údisplay_widthÚHyperlink.display_widthZ   s!   € ô$ Ø�I‰IØ'ØØ+ñ	
ð 	
r   c                ó  • [         R                  " X5      nUc  g[        R                  UR	                  5       5      nUc  gU R                  XR                  5       5      u  pVXV4S:X  a  gU " XAUR                  5       U S9$ )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')
Nr6   )r   r4   )r   r   r   r   r   r=   r;   )r   r4   r:   r   r   Úclose_startÚ	close_ends          r   r   ÚHyperlink.parses   sw   € ô ×$Ò$ TÓ1ˆØ‰9ØÜ ×&Ñ& q§w¡w£yÓ1ˆØ‰>ØØ!$§¡°·e±e³gÓ!>ÑˆØÐ# xÓ/ØÙ˜&¨A¯E©E«G°KÐ'@ÑAÐAr   c                ó†   • U R                   R                  5       U R                  -   U R                   R                  5       -   $ )z5Rebuild the complete OSC 8 hyperlink escape sequence.)r   r!   r4   r$   r   s    r   Úmake_sequenceÚHyperlink.make_sequenceŒ   s0   € à�{‰{×$Ñ$Ó&¨¯©Ñ2°T·[±[×5KÑ5KÓ5MÑMÐMr   r&   N)r4   r
   r<   Úintr'   ztuple[int, int])rA   z+typing.Literal['parse', 'strict', 'ignore']rB   rO   rC   rO   r'   rO   )r   )r4   r
   r:   rO   r'   zHyperlink | Noner(   )r)   r*   r+   r,   r-   r.   r/   r=   rF   r   rM   r0   r&   r   r   r2   r2   =   s}   ‡ ñð ÓØ
ƒIàó$ó ð$ð( FMØØ ñ
ð Cð
ð ð	
ð
 ð
ð 
õ
ð2 õBó ðB÷0Nr   r2   )r-   Ú
__future__r   ÚreÚtypingrE   r   Úescape_sequencesr   Úcompiler   r8   Ú
NamedTupler   r2   r&   r   r   Ú<module>rV      sh   ðñõ #ó 
ã õ $Ý 0à—J’JÐLÓMÐ Ø—Z’ZÐ 8Ó9Ð ô$,�f×'Ñ'ô $,ôNQN�×!Ñ!õ QNr   