Z-j~dZddlmZddlZddlZddlmZddlmZej dZ ej dZ Gd d ej Z Gd d ej ZdS) 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\\)cbeZdZUdZded<dZded<dZded<edd Zdd Z dd Z dS)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\\``). strurlparams terminatorseqreturnHyperlinkParams | Nonect|}|dS||d|d|dS)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') Nr)r r r)HYPERLINK_OPEN_REmatchgroup)clsrms i/home/jenkins/jenkins/workspace/simtester-sanitize/venv/lib/python3.11/site-packages/wcwidth/hyperlink.pyparsezHyperlinkParams.parse#sV  # #C ( ( 94sqwwqzz!''!**LLLLc4d|jd|j|jS)z(Generate the OSC 8 open escape sequence.z]8;;)r r rselfs r make_openzHyperlinkParams.make_open4s#BBBtxBBBBrcd|jS)z)Generate the OSC 8 close escape sequence.z]8;;)rrs r make_closezHyperlinkParams.make_close8s+$/+++rN)rr rrrr ) __name__ __module__ __qualname____doc____annotations__r r classmethodrr!r#rrrrs HHHFJMMM[M CCCC,,,,,,rrcteZdZUdZded<ded<edd Zd d d dddZedddZddZ dS) 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. rr r textopen_endintrtuple[int, int]ct||}|dS||fS)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. Nr4)HYPERLINK_CLOSE_REsearchstartend)rr.r/rs r find_closezHyperlink.find_closeHs>  % %dH 5 5 98 15577##rrr control_codestabsizeambiguous_widthr<+typing.Literal['parse', 'strict', 'ignore']r=r>c2t|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_widthzHyperlink.display_widthZs)$ I'+     rrr7Hyperlink | NonecLtj||}|dSt|}|dS|||\}}||fdkrdS|||||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.)rrrrrr9r8)rr.r7rr close_start close_ends rrzHyperlink.parsess  $T5 1 1 94 &&qwwyy11 >4!$aeegg!>!> Y  #x / /4s&tAEEGGK,?'@AAAArcx|j|jz|jzS)z5Rebuild the complete OSC 8 hyperlink escape sequence.)r r!r.r#rs r make_sequencezHyperlink.make_sequences0{$$&&2T[5K5K5M5MMMrN)r.r r/r0rr1)r<r?r=r0r>r0rr0)r)r.r r7r0rrCr$) r%r&r'r(r)r*r9rBrrHr+rrr-r-=s III$$$[$(FM       2BBBB[B0NNNNNNrr-)r( __future__rretypingrArescape_sequencesrcompilerr5 NamedTuplerr-r+rrrOs #""""" $#####000000BJLMMRZ 899$,$,$,$,$,f'$,$,$,NQNQNQNQNQN!QNQNQNQNQNr