Ë
    äU.j|  ã                  ó   — d Z ddlm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 dd	lmZmZ dd
lmZmZmZmZmZ ddlmZmZ ddlmZmZmZ  G d„ dej>                  «      Z  G d„ de
«      Z!dd„Z"	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Z#	 	 	 	 	 	 	 	 	 	 	 	 d d„Z$	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!d„Z%	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d"d„Z&	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!d„Z'ddddddddœ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d#d„Z(y)$z*This is a python implementation of clip().é    )ÚannotationsN)Úislice)ÚLiteralÚCallableÚOptionalÚ
NamedTupleé   )Úwidth)Úiter_graphemes)Ú	HyperlinkÚHyperlinkParams)Ú_SGR_STATE_DEFAULTÚ	_SGRStateÚ_sgr_state_updateÚ_sgr_state_is_activeÚ_sgr_state_to_sequence)Ú
TextSizingÚTextSizingParams)Ú_SEQUENCE_CLASSIFYÚ_HORIZONTAL_CURSOR_MOVEMENTÚINDETERMINATE_EFFECT_SEQUENCEc                  ó˜   — 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© ó    úOC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\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_widthÚ ÚstrÚopen_seqÚclipped_innerÚ	close_seqÚclipped_widthÚ
hl_col_endN)r   r   r   r   Ú__annotations__r+   r,   r/   r0   r1   r2   r3   r$   r%   r&   r(   r(   "   sU   … ñð ÓØ€IˆsÓØ€K�ÓØ€HˆcÓØ€M�3ÓØ€IˆsÓØ€M�3ÓØ€J�Ôr%   r(   c                óN   — |�"t        |«      x}r|| z   } t        |«      r| dz  } | S )zà
    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 are active.
    z[0m)r   r   )ÚresultÚcaptured_styleÚprefixs      r&   Ú_apply_sgr_wrapr9   3   s:   € ð Ð!Ü+¨NÓ;Ð;ˆ6Ð;Ø˜f‘_ˆFÜ Ô/Ø�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).
    )éÿÿÿÿr;   )Úcontrol_codesÚtabsizeÚambiguous_widthÚterm_programr   )r+   )r+   r,   F)Úfillcharr=   r>   r?   Úpropagate_sgrr<   )r+   r,   r/   r0   r1   r2   r3   )r   Ú
find_closer(   r   r    r
   r!   r"   ÚmaxÚclipr#   Ú	make_openÚ
make_close)ÚtextÚstartÚendr@   r=   r>   r?   r<   ÚparamsÚ	match_endÚcolÚclose_startr+   Ú
inner_textr,   r3   Úinner_clip_startÚinner_clip_endr0   r2   s                       r&   Ú_process_hyperlinkrQ   B   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                  |«       ||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*.
    r;   r   r$   r	   r-   )
Ú
setdefaultÚappendÚvaluesÚsortrC   ÚkeysÚminÚgetÚsortedÚjoin)ÚcellsÚ	sequencesrH   rI   r@   Ú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_painterrm   ˆ   sŽ  € ð 57€KÛ$-Ñ ˆ�˜Ø×Ñ˜w¨Ó+×2Ñ2°E¸8Ð3DÕEð %.à×%Ñ%Ö'ˆØ�‰�ð (ñ ).”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˜Õ"ð 9ð �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               ó¦	  ‡— g }
d}d}d}|rt         nd}|t        | «      k  �r�| |   }||k\  r'|dvr#|��n‹| j                  d|dz   «      }|dk(  r�no|}Œ@|dk(  �r1t        j                  | |«      }|s|
j                  |«       |dz  }Œu|j                  d«      �/|r-|�+t        ||j                  «       «      }|j                  «       }Œµt        j                  |j                  «       «      x}�rEt        | |||||||	||j                  «       |¬«      }|j                  t        j                  u r0|
j                  |j                  «       «       |j                  «       }nÓ|j                  t        j                  u r|j                   }nª|j                  t        j"                  u r||j$                  z  }|j                   }nr|
j                  |j&                  «       |
j                  |j(                  «       |
j                  |j*                  «       |r|€|}||j$                  z  }|j                   }�Œ |j                  d	«      x}�é|j                  d
«      }|j                  d«      }|�|€J ‚t-        t/        j0                  ||	¬«      ||«      }|j3                  |«      }||k\  r3||z   |k  r+|
j                  |j5                  «       «       |r|€|}||z  }nD||k  r:||z   |kD  r2g Šdˆfd„}t7        ||||||||«      }|
j9                  ‰«       |r
|€|}n||z  }|j                  «       }�Œ|j                  «       }|r&t;        j                  |«      rt=        d|› d|›�«      ‚|
j                  |«       |j                  «       }�Œw|dk(  r^|dkD  rA||||z  z
  z   }||k  rB||cxk  r|k  rn n|
j                  d«       |r|€|}|dz  }||k  rŒ0n|
j                  d«       |dz  }�ŒÚt?        tA        | |¬«      «      }tC        |||¬«      }|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                  |tE        |||z   «      tG        ||«      z
  z  «       |r|€|}||z  }|t        |«      z  }|t        | «      k  r�Œ�djI                  |
«      |fS )z˜
    Clip text without cursor movement (simple append-to-output path).

    Returns ``(result, captured_style)``.  The caller applies SGR wrapping.
    r   Nz	Úr	   r;   Ú
sgr_params©rJ   rK   rL   Úts_metaÚts_textÚts_term©r<   c                ó(   •— ‰j                  | «       y )N)rT   )ÚsÚ_wÚ_colÚts_partss      €r&   Ú	_ts_writez_clip_simple.<locals>._ts_write-  s   ø€ Ø Ÿ™¨Õ*r%   ú*Indeterminate cursor sequence at position ú, Ú	Ú ©rH   ©r>   r?   r-   )rw   r.   rx   r*   ry   r*   ÚreturnÚNone)%r   ÚlenÚfindr   ÚmatchrT   Úgroupr   rI   r   ÚparserQ   r)   r   r    r!   r+   r"   r,   r/   r0   r1   r   r   Úfrom_paramsÚdisplay_widthÚmake_sequenceÚ_text_sizing_clipÚextendr   Ú
ValueErrorÚnextr   r
   rX   rC   r[   )rG   rH   rI   rA   r>   r?   r@   r=   Ústrictr<   ÚoutputrL   Úidxr7   Úcurrent_styleÚcharÚnext_escÚmÚhl_stateÚrrr   rs   rt   ÚtsÚts_widthr{   ÚseqÚnext_tabÚgraphemeÚ
grapheme_wrz   s                                 @r&   Ú_clip_simplerŸ   ¿   sá  ø€ ð, €FØ
€CØ
€Cð +/€NÙ*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�Ø—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˜Ø˜1Ÿ=™=Ñ(�CØŸ+™+�CÙð Ÿ7™7 9Ó-Ð-�Ð:ØŸ'™' )Ó,�ØŸ'™' )Ó,�ØÐ*¨wÐ/BÐBÐBÜÜ$×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‹}ÑˆðM ”�D“	Œ/ðP �7‰7�6‹?˜NÐ*Ð*r%   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¡M˜q�a˜•d¡Mùs   ‚r-   )Úsumr   rJ   r
   r„   Ú	numeratorÚdenominatorÚvertical_alignÚhorizontal_alignr   r[   Ú
terminatorr‹   Úclear)	Ú	flush_colr¤   ÚtextsÚtotal_wrJ   Ú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­   r*   r‚   rƒ   )rŠ   r‹   rC   rX   rJ   r±   r
   r   r   rG   rT   Úranger„   )r™   rL   rH   rI   r@   r>   r?   r²   rš   Ú	rel_startÚrel_endÚunitsÚgri   r³   Úflush_col_posÚunit_posÚ	unit_textÚunit_wÚunit_endÚoverlapÚ	abs_startÚir°   r±   s   `      `               @@r&   rŒ   rŒ   n  sA  û€ ð" ×Ñ Ó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˜Õ$ð Bä�r—y‘y—‘¬¨U«Ñ3Ö4ˆAØ�L‰L˜"˜e˜Õ%ñ 5ô   §¡Ö(ˆ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–^�Ù˜H a¨°Q©Õ7ð $à‰ð% #ñ( 
ˆ-ÔØ�‰>Ðr%   c               óØ  ‡‡‡$‡%‡&‡'— i Š%t        «       Š'g }
d}d}d}dŠ$‰rt        ndŠ&	 d	 	 	 dˆ$ˆ%ˆ&ˆˆ'ˆfd„}|t        | «      k  �r•| |   }||k\  r	‰$�|dk7  r�n‚|dk(  �rt        j                  | |«      }|s%|
j                  |||f«       |dz  }‰r‰$€‰&Š$|dz  }Œe|j                  d«      �/‰r-‰&�+t        ‰&|j                  «       «      Š&|j                  «       }Œ¥t        j                  |j                  «       «      x}�rtt        | ||‰||||	||j                  «       |¬«      }|j                  t        j                  u r>|
j                  |||j                  «       f«       |dz  }‰r‰$€‰&Š$|j                  «       }nô|j                  t        j                  u r|j                   }nË|j                  t        j"                  u r||j$                  z  }|j                   }n“|
j                  |||j&                  f«       |dz  }‰r‰$€‰&Š$ ||j(                  |j*                  |d¬	«       ||j*                  z  }|
j                  |||j,                  f«       |dz  }|j.                  }|j                   }�Œ?|j                  d
«      x}�t|j                  d«      }|j                  d«      }|�|€J ‚t1        t3        j4                  ||	¬«      ||«      }t7        ||||‰|||«      }‰r‰$€‰&Š$|j                  «       }�ŒÆ|j                  «       }|r&t9        j                  |«      rt;        d|› d|›�«      ‚|j                  d«      x}�$|rt=        |«      dz
  nd}|j                  «       }�Œ5|j                  d«      x}�a|rt=        |«      nd}||z   }||k  r4||kD  r/t?        tA        ||«      tC        ||«      «      D ]  } |‰d|«       Œ |}|j                  «       }�Œ©|j                  d«      x}�I|rt=        |«      nd}|r||kD  rt;        d|› d|› d|› d�«      ‚||z  }|dk  rd}|j                  «       }�Œ|
j                  |||j                  «       f«       |dz  }‰r‰$€‰&Š$|j                  «       }�ŒD|dk(  r	d}|dz  }�ŒR|dk(  r|dkD  r|dz  }|dz  }�Œh|dk(  r_|dkD  r4||||z  z
  z   }||k  rC||cxk  r|k  rn n
 |‰d|«       |dz  }||k  rŒ#n|
j                  ||df«       |dz  }‰r‰$€‰&Š$|dz  }�ŒÌtE        tG        | |¬«      «      } tI        | ||¬«      }!|!dk(  r.||cxk  r|k  r�n n~|
j                  ||| f«       |dz  }‰rc‰$€a‰&Š$n^||k\  r||!z   |k  r || |!|«       nF||k  rA||!z   |kD  r9tA        ||«      }"t?        tC        |||!z   «      |"z
  «      D ]  }# |‰d|"|#z   «       Œ ||!z  }|t        | «      z  }|t        | «      k  r�Œ•tK        ‰%|
||‰«      ‰$fS )z‘
    Clip text with cursor movement (painter's algorithm path).

    Returns ``(result, captured_style)``.  The caller applies SGR wrapping.
    r   Nc                óÈ  •— 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	   )r-   r   é   N)r´   rY   ÚdiscardÚpopÚadd)rw   ÚwÚ	write_colÚis_hyperlinkÚoffsetÚsrc_colr7   r\   r“   r@   Úhyperlink_cellsrA   s         €€€€€€r&   Ú_write_cellsz#_clip_painter.<locals>._write_cellsí  s  ø€ ô ˜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ÑÙÜ ž(�Ø×#Ñ# I°Ñ$6Õ7ð #á˜^Ð3Ø*‰Nð 4ˆ=r%   ro   r	   rp   rq   T)rÉ   rr   rs   rt   ru   r|   r}   Úhpa_nÚ
cforward_nÚcbackward_nz!Cursor left movement at position z would move z cells left from column z, exceeding string startÚÚr~   r€   r�   )F)
rw   r.   rÇ   r*   rÈ   r*   rÉ   Úboolr‚   rƒ   )&Úsetr   r„   r   r†   rT   r‡   r   rI   r   rˆ   rQ   r)   r   r    r!   r+   r"   r,   r/   r0   r2   r1   r3   r   r   r‰   rŒ   r   rŽ   r*   r´   rC   rX   r�   r   r
   rm   )(rG   rH   rI   rA   r>   r?   r@   r=   r�   r<   r]   Ú	seq_orderrL   r’   rÍ   r”   r–   r—   r˜   rr   rs   rt   r™   r›   rÎ   rÏ   Ú	n_forwardÚmove_endrÀ   rÐ   Ú
n_backwardrœ   r�   rž   Ú
clip_startrÊ   r7   r\   r“   rÌ   s(      `  `                             @@@@r&   Ú_clip_painterrÚ   Æ  s¨  ý€ ð, )+€EÜ #£€OØ,.€IØ€Ià
€CØ
€Cð +/€NÙ*7Õ&¸T€Mð +0ð+Ø#'ð+Ø48÷+ò +ð* ”�D“	‹/Ø�C‰yˆð �#Š:˜.Ð4¸ÀºÙà�6‹>Ü"×(Ñ(¨¨sÓ3ˆAÙà× Ñ  # y°$Ð!7Ô8Ø˜Q‘�	Ù  ^Ð%;Ø%2�NØ�q‘�Øð �w‰w�|Ó$Ð0±]À}ÐG`Ü 1°-ÀÇÁÃÓ K�Ø—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Ù$¨Ð)?Ø)6˜ØŸ%™%›'‘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Ù$¨Ð)?Ø)6˜Ù  §¡°!·/±/À3Ø.2õ4à˜1Ÿ?™?Ñ*�CØ×$Ñ$ c¨9°a·k±kÐ%BÔCØ ‘N�IØŸ,™,�CØŸ+™+�CÙð Ÿ7™7 9Ó-Ð-�Ð:ØŸ'™' )Ó,�ØŸ'™' )Ó,�ØÐ*¨wÐ/BÐBÐBÜÜ$×0Ñ0°ÈÔVØ˜Wó&�ô (Ø˜˜U C¨°?Ø Ø ó"�ñ ! ^Ð%;Ø%2�NØ—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˜Ù$ X¨q°!Õ4ð Hà�Ø—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Ù Ð!7Ø!.�Ø—%‘%“'ˆCÙð �4Š<ØˆCØ�1‰HˆCÙð �6Š>Ø�QŠwØ�q‘�Ø�1‰HˆCÙð �4Š<Ø˜Š{Ø '¨S°7©]Ñ";Ñ<�Ø˜H’nØ Ô) cÕ)Ù$ X¨q°#Ô6Ø˜1‘H�Cð ˜H”nð
 × Ñ  # y°$Ð!7Ô8Ø˜Q‘�	Ù  ^Ð%;Ø%2�NØ�1‰HˆCÙô œ t°3Ô7Ó8ˆÜ˜8°_Ø(4ô6ˆ
ð ˜Š?Ø˜Ô!˜cÕ!Ø× Ñ  # y°(Ð!;Ô<Ø˜Q‘�	Ù  ^Ð%;Ø%2‘NØ�EŠ\˜c JÑ.°#Ò5Ù˜ :¨sÕ3Ø�3ŠY˜3 Ñ+¨eÒ3Ü˜U C›ˆJÜ¤ C¨¨zÑ)9Ó :¸ZÑ GÖH�Ù˜X q¨*°vÑ*=Õ>ð Ið 	ˆzÑˆØŒs�8‹}ÑˆðW ”�D“	Œ/ôZ    y°%¸¸hÓGÈÐWÐWr%   r   é   Trˆ   F)r@   r=   r>   rA   r<   Ú
overtypingr?   c               óX  — t        |d«      }||k  ry| j                  «       r| j                  «       r| || S 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        nt        }t         || |||||	|||dk(  |¬	«
      Ž S )
ua  
    Clip text to display columns (start, end) while preserving all terminal sequences.

    This function extracts a substring based on visible column positions rather than
    character indices. Terminal escape sequences are preserved in the output since
    they have zero display width. If a wide character (width 2) is split at
    either 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, cursor movements actively change the write
    position, allowing cursor-left and carriage return to overwrite previously
    written cells. It is assumed that ``text`` begins at column 0.

    **OSC 8 hyperlinks** are handled specially: the visible text inside a hyperlink
    is clipped to the requested column range, and the hyperlink is rebuilt around
    the clipped text.  Empty hyperlinks (those with no remaining visible text after
    clipping) are removed::

        >>> 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).
    :param end: Absolute ending column (exclusive).
    :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. The result begins with any active style at the start
        position and ends with a reset sequence if styles are active.
    :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 ``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'

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

    .. 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).

    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   r-   ro   FÚignorerÒ   rÑ   r�   )
rG   rH   rI   rA   r>   r?   r@   r=   r�   r<   )	rC   ÚisasciiÚisprintablerÓ   r   ÚsearchrÚ   rŸ   r9   )rG   rH   rI   r@   r=   r>   rA   r<   rÜ   r?   Úhas_escÚfn_clips               r&   rD   rD   ²  sñ   € ôZ ��q‹M€EØ
ˆe‚|Øð ‡|�|„~˜$×*Ñ*Ô,Ø�E˜#ˆÐð ˜ˆn€GÙ™WØˆð Ðð ˜XÑ%ò KØ�tˆ^ò J˜t t˜|ò JØÒHœ$Ô:×AÑAÀ$ÓGÓHñ 	ñ
 
˜¨Ò1Øˆ
Ù)�m¬|€Gä™GØØØØ#Ø'Ø!ØØØ Ñ)Ø#ôð ð r%   )r6   r.   r7   zOptional[_SGRState]r‚   r.   )rG   r.   rH   r*   rI   r*   r@   r.   r=   r*   r>   r*   r?   ú
bool | strr<   ú$Literal['parse', 'strict', 'ignore']rJ   r   rK   r*   rL   r*   r‚   r(   )r\   zdict[int, tuple[str, int]]r]   zlist[tuple[int, int, str]]rH   r*   rI   r*   r@   r.   r‚   r.   )rG   r.   rH   r*   rI   r*   rA   rÓ   r>   r*   r?   rä   r@   r.   r=   r*   r�   rÓ   r<   rå   r‚   ztuple[str, Optional[_SGRState]])r™   r   rL   r*   rH   r*   rI   r*   r@   r.   r>   r*   r?   rä   r²   zCallable[[str, int, int], None]r‚   r*   )rG   r.   rH   r*   rI   r*   r@   r.   r=   r*   r>   r*   rA   rÓ   r<   rå   rÜ   zOptional[bool]r?   rä   r‚   r.   ))r   Ú
__future__r   r   Ú	itertoolsr   Útypingr   r   r   r   Ú_widthr
   r�   r   Ú	hyperlinkr   r   Ú	sgr_stater   r   r   r   r   Útext_sizingr   r   Úescape_sequencesr   r   r   ÚEnumr   r(   r9   rQ   rm   rŸ   rŒ   rÚ   rD   r$   r%   r&   Ú<module>rï      s  ðÙ 0Ý "ó Ý ç :Ó :õ Ý $ß 1÷0õ 0÷
 6÷>ñ >ô
�t—y‘yô ô�zô ó"ðCØ
ðCàðCð 
ðCð ð	Cð
 ðCð ðCð ðCð 8ðCð ðCð ðCð 
ðCð óCðL4Ø%ð4à)ð4ð ð4ð 
ð	4ð
 ð4ð 	ó4ðnl+Ø
ðl+àðl+ð 
ðl+ð
 ðl+ð ðl+ð ðl+ð ðl+ð ðl+ð ðl+ð 8ðl+ð %ól+ð^UØðUà	ðUð ðUð 
ð	Uð
 ðUð ðUð ðUð 1ðUð 	óUðpiXØ
ðiXàðiXð 
ðiXð
 ðiXð ðiXð ðiXð ðiXð ðiXð ðiXð 8ðiXð %óiXðb ØØØØ:AØ!%Ø$ñQØ
ðQàðQð 
ðQð
 ðQð ðQð ðQð ðQð 8ðQð ðQð ðQð 	ôQr%   