Ë
    ^ãjè�  ã            	      óÖ  — U d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
mZmZ ddlmZ ddlmZmZ dd	lmZmZmZmZmZmZ dd
lmZ ddlmZmZ ddlmZm Z m!Z! de"d<   ejF                  jI                  dd«      r	ddl%m&Z& dZ'n	 ddl(m)Z* ddl(m&Z& e*Z' G d„ dejX                  «      Z- G d„ de«      Z.	 d$	 	 	 d%d„Z/	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d&d„Z0	 	 	 	 	 	 	 	 	 	 	 	 d'd„Z1	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d(d„Z2	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d)d„Z3	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d(d„Z4	 	 d*ddddd dd!d"œ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d+d#„Z)y# e+$ r ddl%m&Z& dZ'Y ŒÐw xY w),z*This is a python implementation of clip().é    )ÚannotationsN)Úislice)ÚLiteralÚCallableÚOptionalÚ
NamedTupleé   )Úwidth)Ú	HyperlinkÚHyperlinkParams)Ú_SGR_PATTERNÚ_SGR_STATE_DEFAULTÚ	_SGRStateÚ_sgr_state_updateÚ_sgr_state_is_activeÚ_sgr_state_to_sequence)Ú_clamp_ambiguous_width)Ú
TextSizingÚTextSizingParams)Ú_SEQUENCE_CLASSIFYÚ_HORIZONTAL_CURSOR_MOVEMENTÚINDETERMINATE_EFFECT_SEQUENCEz&Optional[Callable[..., Optional[str]]]Ú_c_clipÚWCWIDTH_PYTHONÚ )Úiter_graphemes)Úclipc                  ó˜   — e Zd ZdZ ej
                  «       Z ej
                  «       Z ej
                  «       Z ej
                  «       Z	y)Ú_HyperlinkActionz.Outcome of processing an OSC 8 hyperlink unit.N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚenumÚautoÚNO_CLOSEÚEMPTYÚOUTSIDEÚVISIBLE© ó    úO/var/www/html/metafoliadorv2/venv/lib/python3.12/site-packages/wcwidth/_clip.pyr   r   -   s9   „ Ù8àˆt�y‰y‹{€HØˆD�I‰I‹K€EØˆd�i‰i‹k€GØˆd�i‰i‹k�Gr+   r   c                  ó~   — e Zd ZU dZded<   dZded<   dZded<   dZd	ed
<   dZd	ed<   dZ	d	ed<   dZ
ded<   dZded<   y)Ú_HyperlinkResultzn
    Result of processing an OSC 8 hyperlink.

    Only the fields relevant to each action are populated.
    r   Úactionr   ÚintÚ	close_endÚinner_widthr   ÚstrÚopen_seqÚclipped_innerÚ	close_seqÚclipped_widthÚ
hl_col_endN)r    r!   r"   r#   Ú__annotations__r1   r2   r4   r5   r6   r7   r8   r*   r+   r,   r.   r.   6   sU   … ñð ÓØ€IˆsÓØ€K�ÓØ€HˆcÓØ€M�3ÓØ€IˆsÓØ€M�3ÓØ€J�Ôr+   r.   c                óV   — |�&t        |«      x}r|| z   } t        |€|n|«      r| dz  } | S )aZ  
    Apply SGR prefix/suffix around *result*.

    If an SGR state was captured at the first visible character, prefix the result with the
    corresponding SGR sequence, and suffix with a reset if any styles remain active at the end
    of the clipped region.

    *end_style* is the style in effect after the final SGR sequence emitted within the clip window,
    or ``None`` when no such sequence was emitted, the style at the first visible character is still
    in effect.  This matches :func:`wcwidth.propagate_sgr`, which decides the trailing reset by SGR
    state at the end of each line.
    z[0m)r   r   )ÚresultÚcaptured_styleÚ	end_styleÚprefixs       r,   Ú_apply_sgr_wrapr?   G   sA   € ð Ð!Ü+¨NÓ;Ð;ˆ6Ð;Ø˜f‘_ˆFÜ°)Ð2C¡ÈÔSØ�iÑˆFØ€Mr+   c               ó  — t        j                  | |	«      \  }}||fdk(  rt        t        j                  «      S | |	| }t        |||||¬«      }|dk(  rt        t        j                  |¬«      S |
|z   }||k  s|
|k\  rt        t        j                  ||¬«      S t        d||
z
  «      }||
z
  }t        |||||||d|¬«	      }t        |||||¬«      }t        t        j                  |||j                  «       ||j                  «       ||¬«      S )	zé
    Process an OSC 8 hyperlink unit.

    Finds the matching close sequence, measures the inner text width, and determines whether the
    hyperlink is empty, outside the clip window, or visible (requiring inner-text clipping).
    )éÿÿÿÿrA   )Úcontrol_codesÚtabsizeÚambiguous_widthÚterm_programr   )r1   )r1   r2   F)ÚfillcharrC   rD   rE   Úpropagate_sgrrB   )r1   r2   r4   r5   r6   r7   r8   )r   Ú
find_closer.   r   r&   r
   r'   r(   Úmaxr   r)   Ú	make_openÚ
make_close)ÚtextÚstartÚendrF   rC   rD   rE   rB   ÚparamsÚ	match_endÚcolÚclose_startr1   Ú
inner_textr2   r8   Úinner_clip_startÚinner_clip_endr5   r7   s                       r,   Ú_process_hyperlinkrV   ]   sE  € ô* '×1Ñ1°$¸	ÓBÑ€K�Ø�YÐ 8Ò+ÜÔ 0× 9Ñ 9Ó:Ð:Ø�i Ð,€JÜØ -Ø¨Ø!ô€Kð �aÒÜÔ 0× 6Ñ 6À)ÔLÐLà�{Ñ"€Jà�UÒ˜c SšjÜÔ 0× 8Ñ 8ÀIØ,7ô9ð 	9ô ˜1˜e c™kÓ*ÐØ˜3‘Y€NäØÐ$ nØ 7Ø'Ø!ØØ#ô€Mô Ø ]Ø¨Ø!ô€Mô Ü× Ñ ØØØ×!Ñ!Ó#Ø#Ø×#Ñ#Ó%Ø#Øô	ð 	r+   c                ó  — i }|D ])  \  }}}|j                  |g «      j                  ||f«       Œ+ |j                  «       D ]  }	|	j                  «        Œ | rt	        | j                  «       «      nd}
|rt	        |j                  «       «      nd}t	        |
|«      }g }d}t        ||«      }||k  r‡|j                  |d«      D ]  \  }}|j                  |«       Œ ||k\  r|dz  }Œ;|| v r#| |   \  }}|j                  |«       ||xs dz  }n$||cxk  r|
k  rn n|j                  |«       |dz  }||k  rŒ‡t        |j                  «       «      D ]&  }||kD  sŒ	||   D ]  \  }}|j                  |«       Œ Œ( dj                  |«      S )z»
    Reconstruct the output string from painter's algorithm state.

    Walks columns left-to-right, interleaving escape sequences and cell content, filling gaps with
    *fillchar*.
    rA   r   r*   r	   r   )
Ú
setdefaultÚappendÚvaluesÚsortrI   ÚkeysÚminÚgetÚsortedÚjoin)ÚcellsÚ	sequencesrM   rN   rF   Úseqs_by_colÚcol_posÚorderÚseq_textÚentriesÚmax_cell_colÚmax_seq_colÚmax_colÚpartsÚwalk_colÚ	col_limitÚ_Ú	cell_textÚcell_wÚcs                       r,   Ú_reconstruct_painterrr   £   s­  € ð 57€KØ$-ò FÑ ˆ�˜Ø×Ñ˜w¨Ó+×2Ñ2°E¸8Ð3DÕEðFà×%Ñ%Ó'ò ˆØ�‰�ðñ ).”3�u—z‘z“|Ô$°2€LÙ-8”#�k×&Ñ&Ó(Ô)¸b€KÜ�, Ó,€Gà€EØ€HÜ�G˜SÓ!€IØ
�iÒ
à&Ÿ?™?¨8°RÓ8ò 	#‰KˆAˆxØ�L‰L˜Õ"ð	#ð �sŠ?Ø˜‰MˆHØà�uÑØ % h¡ÑˆI�vØ�L‰L˜Ô#Ø˜š !Ñ#‰Hà˜Ô0 LÕ0Ø—‘˜XÔ&Ø˜‰MˆHð! �iÓ
ô& �K×$Ñ$Ó&Ó'ò 'ˆØˆy‹=Ø*¨1™~ò '‘��8Ø—‘˜XÕ&ñ'ð'ð
 �7‰7�5‹>Ðr+   c               ó°
  ‡ — |dk(  }	g }
d}d}d}d}|rt         nd}|t        | «      k  �r| |   }||k\  r'|dvr#|��n| j                  d|dz   «      }|dk(  r�nì|}Œ@|dk(  �r t        j                  | |«      }|s|
j                  |«       |dz  }Œu|j                  d«      �W|rU|�St        ||j                  «       «      }|�&||k  r!|
j                  |j                  «       «       |}|j                  «       }ŒÝt        j                  |j                  «       «      x}�rŠt        | |||||||||j                  «       |¬	«      }|j                  t        j                  u r1|
j                  |j                  «       «       |j                  «       }�n|j                  t        j                  u r|j                   }nî|j                  t        j"                  u r||j$                  z  }|j                   }n¶|
j                  |j&                  «       |
j                  |j(                  «       |
j                  |j*                  «       |r|€|}|rB|�@t-        j.                  |j(                  «      D ]  }t        ||j                  «       «      }|}Œ  ||j$                  z  }|j                   }�Œ�|j                  d
«      x}�ë|j                  d«      xs d}|j                  d«      }|€J ‚t1        t3        j4                  ||¬«      ||«      }|j7                  |«      }||k\  r3||z   |k  r+|
j                  |j9                  «       «       |r|€|}||z  }nD||k  r:||z   |kD  r2g Š dˆ fd„}t;        ||||||||«      }|
j=                  ‰ «       |r
|€|}n||z  }|j                  «       }�Œ‹|j                  «       }|	r&t?        j                  |«      rtA        d|› d|›�«      ‚|
j                  |«       |j                  «       }�Œæ|dk(  rl|dkD  rA||||z  z
  z   }||k  rP||cxk  r|k  rn n|
j                  d«       |r|€|}|dz  }||k  rŒ0n||cxk  r|k  rn n|
j                  d«       |dz  }�ŒWtC        tE        | |¬«      «      }tG        |||¬«      }|dk(  r ||cxk  r|k  r{n nx|
j                  |«       nf||k\  r ||z   |k  r|
j                  |«       |rF|€D|}nA||k  r<||z   |kD  r4|
j                  |tI        |||z   «      tK        ||«      z
  z  «       |r|€|}||z  }|t        |«      z  }|t        | «      k  r�ŒdjM                  |
«      ||fS )z£
    Clip text without cursor movement (simple append-to-output path).

    Returns ``(result, captured_style, end_style)``.  The caller applies SGR wrapping.
    Ústrictr   Nú	úr	   rA   Ú
sgr_params©rO   rP   rQ   Úts_metaÚts_textr   Úts_term©rB   c                ó(   •— ‰j                  | «       y ©N)rY   )ÚsÚ_wÚ_colÚts_partss      €r,   Ú	_ts_writez_clip_simple.<locals>._ts_writeN  s   ø€ Ø Ÿ™¨Õ*r+   ú*Indeterminate cursor sequence at position ú, ú	ú ©rM   ©rD   rE   )r   r3   r€   r0   r�   r0   ÚreturnÚNone)'r   ÚlenÚfindr   ÚmatchrY   Úgroupr   rN   r   ÚparserV   r/   r   r&   r'   r1   r(   r2   r4   r5   r6   r   Úfinditerr   r   Úfrom_paramsÚdisplay_widthÚmake_sequenceÚ_text_sizing_clipÚextendr   Ú
ValueErrorÚnextr   r
   r]   rI   r`   )!rL   rM   rN   rG   rD   rE   rF   rC   rB   rt   ÚoutputrQ   Úidxr<   r=   Úcurrent_styleÚcharÚnext_escÚmÚhl_stateÚrÚsgr_mry   rz   r{   ÚtsÚts_widthrƒ   ÚseqÚnext_tabÚgraphemeÚ
grapheme_wr‚   s!                                   @r,   Ú_clip_simpler¨   Ú   sa  ø€ ð* ˜hÑ&€Fà€FØ
€CØ
€CØ*.€NØ%)€IÙ*7Õ&¸T€Mà
”�D“	‹/Ø�C‰yˆð �#Š:˜$ nÑ4ØÐ)Ùð
 —y‘y ¨¨q©Ó1ˆHØ˜2Š~ÙØˆCØà�6‹>Ü"×(Ñ(¨¨sÓ3ˆAÙØ—‘˜dÔ#Ø�q‘�Øð �w‰w�|Ó$Ð0±]À}ÐG`Ü 1°-ÀÇÁÃÓ K�Ø!Ð-°#¸²)Ø—M‘M !§'¡'£)Ô,Ø -�IØ—e‘e“g�Øô +×0Ñ0°·±³Ó;Ð;ˆxÑ;Ü&Ø˜%  h°¸Ø Ø!Ø#¨q¯u©u«w¸Cô	�ð —8‘8Ô/×8Ñ8Ñ8Ø—M‘M !§'¡'£)Ô,ØŸ%™%›'’CØ—X‘XÔ!1×!7Ñ!7Ñ7ØŸ+™+‘CØ—X‘XÔ!1×!9Ñ!9Ñ9Ø˜1Ÿ=™=Ñ(�CØŸ+™+‘Cà—M‘M !§*¡*Ô-Ø—M‘M !§/¡/Ô2Ø—M‘M !§+¡+Ô.Ù$¨Ð)?Ø)6˜ñ %¨Ð)BÜ%1×%:Ñ%:¸1¿?¹?Ó%Kò 6˜EÜ,=¸mÈUÏ[É[Ë]Ó,[˜MØ(5™Ið6ð ˜1Ÿ=™=Ñ(�CØŸ+™+�CÙð Ÿ7™7 9Ó-Ð-�Ð:ØŸ'™' )Ó,Ò2°�ØŸ'™' )Ó,�ØÐ*Ð*Ð*ÜÜ$×0Ñ0°ÈÔVØ˜Wó&�ð ×+Ñ+¨OÓ<�à˜%’< C¨(¡N°cÒ$9Ø—M‘M "×"2Ñ"2Ó"4Ô5Ù$¨Ð)?Ø)6˜Ø˜8‘O‘CØ˜3’Y 3¨¡>°EÒ#9Ø*,�Hõ+ä+Ø˜C ¨¨X°Ø$Ø!ó#�Cð —M‘M (Ô+Ù$¨Ð)?Ø)6™à˜8‘O�CØ—e‘e“g�Ùð —'‘'“)ˆCÙÔ7×=Ñ=¸cÔBÜ Ø@ÀÀÀRØ�gðóð ð �M‰M˜#ÔØ—%‘%“'ˆCÙà�4Š<à˜Š{Ø '¨S°7©]Ñ";Ñ<�Ø˜H’nØ Ô) cÕ)ØŸ™ cÔ*Ù(¨^Ð-CØ-:˜NØ˜1‘H�Cð ˜H”nð ˜#Ô# Õ#Ø—‘˜dÔ#Ø�1‰HˆCÙäœ t°3Ô7Ó8ˆÜ˜8°_Ø(4ô6ˆ
ð ˜Š?Ø˜Ô!˜cÕ!Ø—‘˜hÕ'Ø�EŠ\˜c JÑ.°#Ò5Ø�M‰M˜(Ô#Ù Ð!7Ø!.‘Ø�3ŠY˜3 Ñ+¨eÒ3Ø�M‰M˜(¤c¨#¨s°ZÑ/?Ó&@Ä3ÀuÈcÃ?Ñ&RÑSÔTÙ Ð!7Ø!.�àˆzÑˆØŒs�8‹}Ñˆðe ”�D“	Œ/ðh �7‰7�6‹?˜N¨IÐ5Ð5r+   c           	     óT  ‡ ‡‡‡— ‰ j                  |«      }||k\  r%||z   |k  r ‰‰ j                  «       ||«       ||z   S ||k\  s||z   |k  r||z   S t        d||z
  «      }	t        |||z   «      |z
  }
‰ j                  j
                  Šg }‰ j                  j                  dkD  r�t        t        ‰ j                  «      ‰ j                  j                  «      D ]  }|j                  |‰f«       Œ t        ‰ j                  j                  t        |«      z
  «      D ]  }|j                  d‰f«       Œ n<t        ‰ j                  «      D ]$  }|j                  |t        |||¬«      ‰z  f«       Œ& g Šdˆˆˆ ˆfd„}||	z   }d}|D ]—  \  }}||z   }||	k  r|}Œ||
k\  r n€t        ||
«      t        ||	«      z
  }||k(  r*|dkD  r%‰s|t        ||	«      z   }‰j                  ||f«       n4 ||«       |t        ||	«      z   }t        |«      D ]  } ‰|d||z   «       Œ |}Œ™  ||«       ||z   S )zÂ
    Emit tokens for a text-sizing (OSC 66) sequence, clipped to (start, end).

    Calls *write_cells(text, width, col)* for each emitted cell or sequence. Returns new column
    position.
    r   r   r‰   c                óþ  •— ‰sy ‰D �cg c]  }|d   ‘Œ	 }}t        d„ ‰D «       «      }t        ‰‰j                  j                  dkD  rt	        |«      nd‰j                  j
                  ‰j                  j                  ‰j                  j                  ‰j                  j                  «      } ‰t        |dj                  |«      ‰j                  «      j                  «       || «       ‰j                  «        y c c}w )Nr   c              3  ó&   K  — | ]	  }|d    –— Œ y­w)r	   Nr*   )Ú.0Úus     r,   ú	<genexpr>z3_text_sizing_clip.<locals>.flush.<locals>.<genexpr>Á  s   è ø€ Ò2˜q�a˜•dÑ2ùs   ‚r   )Úsumr   rO   r
   rŒ   Ú	numeratorÚdenominatorÚvertical_alignÚhorizontal_alignr   r`   Ú
terminatorr”   Úclear)	Ú	flush_colr­   ÚtextsÚtotal_wrO   Úpending_unitsÚscaler¢   Úwrite_cellss	        €€€€r,   Úflushz _text_sizing_clip.<locals>.flush½  sÌ   ø€ ÙØØ,Ö-˜!��1“Ð-ˆÐ-ÜÑ2 MÔ2Ó2ˆÜ!ØØŸ)™)Ÿ/™/¨AÒ-ŒC�ŒJ°1Ø�I‰I×Ñ §¡×!6Ñ!6Ø�I‰I×$Ñ$ b§i¡i×&@Ñ&@ó	Bˆñ
 	Ü�v˜rŸw™w u›~¨r¯}©}Ó=×KÑKÓMØØô	ð 	×ÑÕùò .s   ‰C:r	   )r¶   r0   rŠ   r‹   )r“   r”   rI   r]   rO   rº   r
   r   r   rL   rY   ÚrangerŒ   )r¢   rQ   rM   rN   rF   rD   rE   r»   r£   Ú	rel_startÚrel_endÚunitsÚgrn   r¼   Úflush_col_posÚunit_posÚ	unit_textÚunit_wÚunit_endÚoverlapÚ	abs_startÚir¹   rº   s   `      `               @@r,   r•   r•   �  sY  û€ ð" ×Ñ Ó0€Hð ˆe‚|˜˜h™¨#Ò-Ù�B×$Ñ$Ó&¨°#Ô6Ø�X‰~Ðà
ˆc‚z�S˜8‘^ uÒ,Ø�X‰~Ðô �A�u˜s‘{Ó#€IÜ�#�s˜X‘~Ó&¨Ñ,€GØ�I‰I�O‰O€Eà#%€EØ	‡y�y‡�˜ÒÜœ r§w¡wÓ/°·±·±ÓAò 	%ˆAØ�L‰L˜!˜U˜Õ$ð	%ä�r—y‘y—‘¬¨U«Ñ3Ó4ò 	&ˆAØ�L‰L˜"˜e˜Õ%ñ	&ô   §¡Ó(ò 	?ˆAØ�L‰LØ”E˜!¨_Ø'3ô5Ø7<ñ=ð >õ?ð	?ð
 ,.€M÷ð ð  ˜)‘O€MØ€HØ"ò Ñˆ	�6Ø˜fÑ$ˆØ�yÒ ØˆHØØ�wÒÙä�h Ó(¬3¨x¸Ó+CÑCˆØ�fÒ ¨!¢Ù Ø #¤c¨(°IÓ&>Ñ >�Ø× Ñ  )¨VÐ!4Õ5á�-Ô Øœc (¨IÓ6Ñ6ˆIÜ˜7“^ò 8�Ù˜H a¨°Q©Õ7ð8à‰ð%ñ( 
ˆ-ÔØ�‰>Ðr+   c               óú  ‡‡‡(‡)‡*‡+‡,‡-— |dk(  }	i Š)t        «       Š+g Š-dŠ,d}
d}dŠ(d}‰rt        ndŠ*d}	 d!	 	 	 d"ˆ(ˆ)ˆ*ˆˆ+ˆˆ,ˆ-fd„}|t        | «      k  �r˜| |   }|
|k\  r¦|dvr¢|�d|cxk  r|k  rmn njt        | j	                  d«      | j	                  d«      | j	                  d«      «      |k  rd	}n*t        j                  | |«      }|€d	n|j                  «       }|dk  r#‰(��n| j                  d|d
z   «      }|d	k(  r�në|}Œ¿|dk(  �rwt        j                  | |«      }|s‰-j                  |
‰,|f«       ‰,d
z  Š,|d
z  }Œü|j                  d«      �`‰r^‰*�\t        ‰*|j                  «       «      Š*‰(�.|
|k  r)‰-j                  |
‰,|j                  «       f«       ‰,d
z  Š,‰*}|j                  «       }�Œmt        j                  |j                  «       «      x}�r®t!        | ||‰||||||j                  «       |
¬«      }|j"                  t$        j&                  u r9‰-j                  |
‰,|j                  «       f«       ‰,d
z  Š,|j                  «       }�n3|j"                  t$        j(                  u r|j*                  }�n	|j"                  t$        j,                  u r|
|j.                  z  }
|j*                  }nÑ‰-j                  |
‰,|j0                  f«       ‰,d
z  Š, ||j2                  |j4                  |
d¬«       |
|j4                  z  }
‰-j                  |
‰,|j6                  f«       ‰,d
z  Š,‰rB‰*�@t9        j:                  |j2                  «      D ]  }t        ‰*|j                  «       «      Š*‰*}Œ  |j<                  }
|j*                  }�ŒA|j                  d«      x}�p|j                  d«      xs d}|j                  d«      }|€J ‚t?        tA        jB                  ||¬«      ||«      }tE        ||
||‰|||«      }
|j                  «       }�ŒÄ|j                  «       }|	r&tG        j                  |«      rtI        d|› d|›�«      ‚|j                  d«      x}�$|rtK        |«      d
z
  nd}
|j                  «       }�Œ3|j                  d«      x}�a|rtK        |«      nd
}|
|z   }|
|k  r4||kD  r/tM        t        |
|«      tO        ||«      «      D ]  } |‰d
|«       Œ |}
|j                  «       }�Œ§|j                  d«      x} �I| rtK        | «      nd
}!|	r|!|
kD  rtI        d|› d|!› d|
› d�«      ‚|
|!z  }
|
dk  rd}
|j                  «       }�Œ‰-j                  |
‰,|j                  «       f«       ‰,d
z  Š,|j                  «       }�Œ<|dk(  r	d}
|d
z  }�ŒJ|dk(  r|
dkD  r|
d
z  }
|d
z  }�Œ`|dk(  rp|dkD  r=|
||
|z  z
  z   }"tM        t        |
|«      tO        |"|«      «      D ]  }# |dd
|#«       Œ |"}
n'||
cxk  r|k  rn n‰-j                  |
‰,df«       ‰,d
z  Š,|d
z  }�ŒÕtQ        tS        | |¬«      «      }$tU        |$||¬ «      }%|%dk(  r(||
cxk  r|k  r{n nx‰-j                  |
‰,|$f«       ‰,d
z  Š,n^|
|k\  r|
|%z   |k  r ||$|%|
«       nF|
|k  rA|
|%z   |kD  r9t        ||
«      }&tM        tO        ||
|%z   «      |&z
  «      D ]  }' |‰d
|&|'z   «       Œ |
|%z  }
|t        |$«      z  }|t        | «      k  r�Œ˜tW        ‰)‰-||‰«      ‰(|fS )#zú
    Clip text, painting cells so that cursor movement can overwrite them.

    Text with no cursor movement to resolve is clipped by _clip_simple() instead.

    Returns ``(result, captured_style, end_style)``.  The caller applies SGR wrapping.
    rt   r   Nc                ó  •— |dk(  r"| r‰j                  |‰| f«       ‰dz  Š‰r‰€‰Šyt        |«      D ]ž  }||z   }|dkD  r9‰j                  |dz
  d«      d   dk(  r‰	df‰|dz
  <   ‰
j                  |dz
  «       ‰j                  |d«      d   dk(  r‰	df‰|dz   <   ‰
j                  |dz   «       ‰j	                  |d«       ‰
j                  |«       Œ  | |f‰|<   |r$t        |«      D ]  }‰
j                  ||z   «       Œ ‰r‰€‰Šyyy)zIWrite *w* cells of text *s* at *write_col*, handling wide-char splitting.r   r	   N)r   r   é   )rY   r½   r^   ÚdiscardÚpopÚadd)r   ÚwÚ	write_colÚis_hyperlinkÚoffsetÚsrc_colr<   ra   r›   rF   Úhyperlink_cellsrG   Ú	seq_orderrb   s         €€€€€€€€r,   Ú_write_cellsz#_clip_painter.<locals>._write_cells  sE  ø€ ð �Š6áØ× Ñ  )¨Y¸Ð!:Ô;Ø˜Q‘�	Ù  ^Ð%;Ø%2�NØÜ˜A“hò 		-ˆFØ &Ñ(ˆGØ˜Š{˜uŸy™y¨°1©°gÓ>¸qÑAÀQÒFØ&.° ]��g ‘kÑ"Ø×'Ñ'¨°!©Ô4Ø�y‰y˜ 'Ó*¨1Ñ-°Ò2Ø&.° ]��g ‘kÑ"Ø×'Ñ'¨°!©Ô4Ø�I‰I�g˜tÔ$Ø×#Ñ# GÕ,ð		-ð ˜q˜6ˆˆiÑÙÜ ›(ò 8�Ø×#Ñ# I°Ñ$6Õ7ð8á˜^Ð3Ø*‰Nð 4ˆ=r+   ru   úúrv   rA   r	   rw   rx   T)rÒ   ry   rz   r   r{   r|   r„   r…   Úhpa_nÚ
cforward_nÚcbackward_nz!Cursor left movement at position z would move z cells left from column z, exceeding string startr†   r‡   rˆ   r‰   )F)
r   r3   rÐ   r0   rÑ   r0   rÒ   ÚboolrŠ   r‹   ),Úsetr   rŒ   rI   Úrfindr   ÚsearchrN   r�   r   rŽ   rY   r�   r   r   r�   rV   r/   r   r&   r'   r1   r(   r2   r4   r5   r7   r6   r   r‘   r8   r   r   r’   r•   r   r—   r0   r½   r]   r˜   r   r
   rr   ).rL   rM   rN   rG   rD   rE   rF   rC   rB   rt   rQ   rš   r=   Únext_movementr×   rœ   Úfoundr�   rž   rŸ   r    r¡   ry   rz   r{   r¢   r¤   rÚ   rÛ   Ú	n_forwardÚmove_endrÉ   rÜ   Ú
n_backwardr¥   Úfill_colr¦   r§   Ú
clip_startrÓ   r<   ra   r›   rÕ   rÖ   rb   s.      `  `                                 @@@@@@r,   Ú_clip_painterrè   ç  sŒ  ÿ€ ð. ˜hÑ&€FØ(*€EÜ #£€OØ,.€IØ€Ià
€CØ
€Cð +/€Nð &*€IÙ*7Õ&¸T€Mà#'€Mð +0ð+Ø#'ð+Ø48÷+ô +ð: ”�D“	‹/Ø�C‰yˆð �#Š:˜$ nÑ4àÐ$¨¨]Ô(@¸SÕ(@ä�t—z‘z &Ó)¨4¯:©:°dÓ+;¸T¿Z¹ZÈÓ=OÓPÐSVÒVØ$&‘Mä7×>Ñ>¸tÀSÓI�EØ*/¨-¡B¸U¿Y¹Y»[�MØ˜qÒ Ø!Ð-ÙØŸ9™9 V¨S°1©WÓ5�Ø˜r’>ÙØ�Øà�6‹>Ü"×(Ñ(¨¨sÓ3ˆAÙà× Ñ  # y°$Ð!7Ô8Ø˜Q‘�	Ø�q‘�Øð �w‰w�|Ó$Ð0±]À}ÐG`Ü 1°-ÀÇÁÃÓ K�Ø!Ð-°#¸²)Ø×$Ñ$ c¨9°a·g±g³iÐ%@ÔAØ ‘N�IØ -�IØ—e‘e“g�Ùô +×0Ñ0°·±³Ó;Ð;ˆxÑ;Ü&Ø˜%  h°¸Ø Ø!Ø#¨q¯u©u«w¸Cô	�ð —8‘8Ô/×8Ñ8Ñ8Ø×$Ñ$ c¨9°a·g±g³iÐ%@ÔAØ ‘N�IØŸ%™%›'’CØ—X‘XÔ!1×!7Ñ!7Ñ7ØŸ+™+’CØ—X‘XÔ!1×!9Ñ!9Ñ9Ø˜1Ÿ=™=Ñ(�CØŸ+™+‘Cà×$Ñ$ c¨9°a·j±jÐ%AÔBØ ‘N�IÙ  §¡°!·/±/À3Ø.2õ4à˜1Ÿ?™?Ñ*�CØ×$Ñ$ c¨9°a·k±kÐ%BÔCØ ‘N�Iñ %¨Ð)BÜ%1×%:Ñ%:¸1¿?¹?Ó%Kò 6˜EÜ,=¸mÈUÏ[É[Ë]Ó,[˜MØ(5™Ið6ð Ÿ,™,�CØŸ+™+�CÙð Ÿ7™7 9Ó-Ð-�Ð:ØŸ'™' )Ó,Ò2°�ØŸ'™' )Ó,�ØÐ*Ð*Ð*ÜÜ$×0Ñ0°ÈÔVØ˜Wó&�ô (Ø˜˜U C¨°?Ø Ø ó"�ð —e‘e“g�Ùð —'‘'“)ˆCÙÔ7×=Ñ=¸cÔBÜ Ø@ÀÀÀRØ�gðóð ð Ÿ™ Ó)Ð)�Ð6Ù(-”c˜%“j 1’n°1�Ø—e‘e“g�Ùð  Ÿg™g lÓ3Ð3�
Ð@Ù/9œC 
œO¸q�	Ø ™?�Ø˜’9 ¨EÒ!1Ü"¤3 s¨E£?´C¸À#Ó4FÓGò 5˜Ù$ X¨q°!Õ4ð5à�Ø—e‘e“g�Ùð  !Ÿw™w }Ó5Ð5�ÐBÙ1<œS Ô-À!�
Ù˜j¨3Ò.Ü$Ø;¸C¸5ÀØ%˜,Ð&>¸s¸eð D1ð2óð ð
 �zÑ!�Ø˜’7Ø�CØ—e‘e“g�Ùð ×Ñ˜c 9¨a¯g©g«iÐ8Ô9Ø˜‰NˆIØ—%‘%“'ˆCÙð �4Š<ØˆCØ�1‰HˆCÙð �6Š>Ø�QŠwØ�q‘�Ø�1‰HˆCÙð �4Š<Ø˜Š{Ø '¨S°7©]Ñ";Ñ<�Ü %¤c¨#¨u£o´s¸8ÀSÓ7IÓ Jò 3�HÙ   a¨Õ2ð3à‘Ø˜#Ô# Õ#Ø× Ñ  # y°$Ð!7Ô8Ø˜Q‘�	Ø�1‰HˆCÙô œ t°3Ô7Ó8ˆÜ˜8°_Ø(4ô6ˆ
ð ˜Š?Ø˜Ô!˜cÕ!Ø× Ñ  # y°(Ð!;Ô<Ø˜Q‘‘	Ø�EŠ\˜c JÑ.°#Ò5Ù˜ :¨sÕ3Ø�3ŠY˜3 Ñ+¨eÒ3Ü˜U C›ˆJÜ¤ C¨¨zÑ)9Ó :¸ZÑ GÓHò ?�Ù˜X q¨*°vÑ*=Õ>ð?ð 	ˆzÑˆØŒs�8‹}Ñˆðq ”�D“	Œ/ôt ! ¨	°5¸#¸xÓHØ˜Ið'ð 'r+   r‡   é   Tr�   F)rF   rC   rD   rG   rB   Ú
overtypingrE   c               ól  — t        |d«      }|dk  r#|dk7  rt        d|› �«      ‚t        j                  }||k  ry| j	                  «       r| j                  «       r| || S t        �D|dk(  r?|dur;|dkD  r6t        |«      dk(  r(|j	                  «       rt        | ||||||||	¬«	      }
|
�|
S t        |«      }d	| v }|r|sd
}|€6|dk7  xr. d| v xs( d| v xs" |xr t        t        j                  | «      «      }n	|r|dk(  rd
}|rt        t        | |||||	|||¬«	      Ž S t        t        | |||||	|||¬«	      Ž S )u÷  
    Clip text to display columns (start, end) while preserving all terminal sequences.

    This function extracts a substring using visible column positions. Terminal escape sequences
    are preserved in output. If a wide character (width of 2) is
    split at a boundary, it is replaced with ``fillchar``.

    TAB characters (``\t``) are expanded to spaces up to the next tab stop, controlled by the
    ``tabsize`` parameter.  When cursor movement is detected, a "painter's algorithm" is used unless
    ``overtyping=False`` is set.  Cursor movement control codes are parsed for their effects instead
    of ignored.  For these operations, it is assumed that ``text`` begins at column 0.

    For text containing **OSC 8 hyperlinks**, the visible text inside a hyperlink is clipped to the
    requested column range and the hyperlink sequence is rebuilt::

        >>> clip('\x1b]8;;http://example.com\x07Click This link\x1b]8;;\x07', 6, 10)
        '\x1b]8;;http://example.com\x07This\x1b]8;;\x07'

    :param text: String to clip, may contain terminal escape sequences.
    :param start: Absolute starting column (inclusive, 0-indexed), default ``0``.
    :param end: Absolute ending column (exclusive).  The default value, ``-1``,
        signifies "to the end of the line", clipping only from *start* without
        requiring the caller to measure the display width of *text*.
    :param fillchar: Character to use when a wide character must be split at
        a boundary (default space). Must have display width of 1.
    :param tabsize: Tab stop width (default 8). Set to 0 to pass tabs through
        as zero-width (preserved in output but don't advance column position).
    :param ambiguous_width: Width to use for East Asian Ambiguous (A)
        characters. Default is ``1`` (narrow). Set to ``2`` for CJK contexts.
    :param propagate_sgr: If True (default), SGR (terminal styling) sequences
        are propagated, matching :func:`propagate_sgr`.  The result begins with
        any style active at the start position, retains any style changes
        occurring within the clipped region at their original position, and
        ends with a reset sequence if styles are active at the end position.
    :param control_codes: How to handle control characters and sequences:

        - ``'parse'`` (default): Track horizontal cursor movement and clip
          hyperlink text.  Cursor overwrite is always allowed, with best effort
          results; indeterminate sequences (home, clear, reset, etc.) are
          preserved as zero-width.
        - ``'strict'``: Like ``parse``, but raises :exc:`ValueError` on
          sequences with indeterminate effects (cursor home, clear screen,
          reset, vertical movement, etc.) matching :func:`width` behavior.
          Also raises on out-of-bounds horizontal cursor movement.
        - ``'ignore'``: All control characters are treated as zero-width.
          Cursor movement is not tracked (fastest path).

    :param overtyping: Whether to use the painter's algorithm for cursor
        movement (``\b`` backspace, ``\r`` carriage return, and CSI cursor
        left/right/position sequences).  When ``None`` (default), auto-detects
        by scanning for these characters in *text*.  Set to ``False`` for improved
        performance when the caller knows *text* contains no cursor movement
        characters.  Set to ``True`` to force the painter's algorithm (useful
        for testing).  Has no effect when ``control_codes='ignore'``.
    :param term_program: Terminal software identifier for table correction.
        ``False`` (default) disables override lookup.  ``True`` reads the
        ``TERM_PROGRAM`` or ``TERM`` environment variable for auto-detection.
        Accepts a canonical terminal name matching :func:`list_term_programs`,
        such as from XTVERSION_, ENQ_, or ``TERM_PROGRAM``.

        .. versionadded:: 0.8.0

    :returns: Substring of ``text`` spanning display columns (start, end),
        with all terminal sequences preserved and wide characters at boundaries
        replaced with ``fillchar``.

    :raises ValueError: If ``end`` is negative and not ``-1``, or if
        ``control_codes='strict'`` and an indeterminate-effect sequence or
        out-of-bounds cursor movement is encountered.

    SGR (terminal styling) sequences are propagated by default. The result
    begins with any active style and ends with a reset::

        >>> clip('\x1b[1;34mHello world\x1b[0m', 6, 11)
        '\x1b[1;34mworld\x1b[0m'
        >>> clip('\x1b[1mbold\x1b[m normal', 1, 9)
        '\x1b[1mold\x1b[m norm'

    Set ``propagate_sgr=False`` to disable this behavior.

    .. note::

       Segmentation follows UAX #29 grapheme clusters. Tamil, Kannada and Sinhala may be clipped
       short of ``end`` and leave a bare virama at the boundary. Correct rendering of these
       languages is not specified by unicode.org standards, and no terminal emulator or editor
       handles them legibly, so this library function makes no attempt at accommodating them.

    .. versionadded:: 0.3.0

    .. versionchanged:: 0.5.0
       Added ``propagate_sgr`` parameter (default True).

    .. versionchanged:: 0.7.0
       Added ``control_codes`` parameter (default 'parse').
       OSC 8 hyperlink-aware clipping.  OSC 66 text sizing protocol support.
       Added ``overtyping`` parameter (default None, auto-detect).

    .. versionchanged:: 0.8.4
       ``start`` now defaults to ``0`` and ``end`` to ``-1``, meaning "to the
       end of the line"::

           >>> clip('\x1b[1;34mHello world\x1b[0m', 6)
           '\x1b[1;34mworld\x1b[0m'

    Example::

        >>> clip('hello world', 0, 5)
        'hello'
        >>> clip('ä¸­æ–‡å­—', 0, 3)  # Wide char split at column 3
        'ä¸­ '
        >>> clip('a\tb', 0, 10)  # Tab expanded to spaces
        'a       b'
    r   rA   z5end must be -1 (to end of line) or non-negative, got r   r�   Tr	   )rF   rC   rD   rG   rB   rE   rv   FÚignorerØ   rÙ   )	rL   rM   rN   rG   rD   rE   rF   rC   rB   )rI   r—   ÚsysÚmaxsizeÚisasciiÚisprintabler   rŒ   r   rÝ   r   rà   r?   rè   r¨   )rL   rM   rN   rF   rC   rD   rG   rB   rê   rE   r;   Úhas_escs               r,   r   r   ñ  s³  € ô| ��q‹M€EØ
ˆQ‚wØ�"Š9ÜØGÈÀuÐMóOð Oô �k‰kˆØ
ˆe‚|Øð ‡|�|„~˜$×*Ñ*Ô,Ø�E˜#ˆÐô 	ÐØ Ò(Ø $Ñ&Ø˜!’Ü�H“ Ò" x×'7Ñ'7Ô'9ÜØ�%˜ x¸Ø+¸=Ø'°lôDˆð ÐØˆMä,¨_Ó=€Oð ˜ˆn€GÙ™WØˆð Ðð ˜XÑ%ò KØ�tˆ^ò J˜t t˜|ò JØÒHœ$Ô:×AÑAÀ$ÓGÓHñ 	ñ
 
˜¨Ò1Øˆ
áÜ¤ØØØØ'Ø+Ø%ØØØ'ô
!
ð 
ð 
	ô œLØØØØ#Ø'Ø!ØØØ#ô
ð 
ð 
r+   r~   )r;   r3   r<   úOptional[_SGRState]r=   rò   rŠ   r3   )rL   r3   rM   r0   rN   r0   rF   r3   rC   r0   rD   r0   rE   ú
bool | strrB   ú$Literal['parse', 'strict', 'ignore']rO   r   rP   r0   rQ   r0   rŠ   r.   )ra   zdict[int, tuple[str, int]]rb   zlist[tuple[int, int, str]]rM   r0   rN   r0   rF   r3   rŠ   r3   )rL   r3   rM   r0   rN   r0   rG   rÝ   rD   r0   rE   ró   rF   r3   rC   r0   rB   rô   rŠ   z4tuple[str, Optional[_SGRState], Optional[_SGRState]])r¢   r   rQ   r0   rM   r0   rN   r0   rF   r3   rD   r0   rE   ró   r»   zCallable[[str, int, int], None]rŠ   r0   )r   rA   )rL   r3   rM   r0   rN   r0   rF   r3   rC   r0   rD   r0   rG   rÝ   rB   rô   rê   zOptional[bool]rE   ró   rŠ   r3   )5r#   Ú
__future__r   Úosrí   r$   Ú	itertoolsr   Útypingr   r   r   r   Ú_widthr
   Ú	hyperlinkr   r   Ú	sgr_stater   r   r   r   r   r   Ú
_constantsr   Útext_sizingr   r   Úescape_sequencesr   r   r   r9   Úenvironr^   r¦   r   r   Ú
_wcwidth_cr   Ú_c_clip_implÚImportErrorÚEnumr   r.   r?   rV   rr   r¨   r•   rè   r*   r+   r,   ú<module>r     su  ðÚ 0Ý "ó 
Û 
Û Ý ç :Ó :õ ß 1÷0÷ 0õ /ß 5÷>ñ >ð 
0Ó /Ø‡:�:‡>�>Ð" BÔ'å(Ø�Gð	å4Ý.ð ˆô�t—y‘yô ô�zô ð$ 6:ðØ2ðØ>Aóð,CØ
ðCàðCð 
ðCð ð	Cð
 ðCð ðCð ðCð 8ðCð ðCð ðCð 
ðCð óCðL4Ø%ð4à)ð4ð ð4ð 
ð	4ð
 ð4ð 	ó4ðnr6Ø
ðr6àðr6ð 
ðr6ð
 ðr6ð ðr6ð ðr6ð ðr6ð ðr6ð 8ðr6ð :ór6ðjUØðUà	ðUð ðUð 
ð	Uð
 ðUð ðUð ðUð 1ðUð 	óUðpG'Ø
ðG'àðG'ð 
ðG'ð
 ðG'ð ðG'ð ðG'ð ðG'ð ðG'ð 8ðG'ð :óG'ðX ØðCð
 ØØØØ:AØ!%Ø$ñCØ
ðCàðCð 
ðCð
 ðCð ðCð ðCð ðCð 8ðCð ðCð ðCð 	ôCøðY ò å,ØŠðús   Â	E ÅE(Å'E(