
    j~                    |    S SK Jr  S SKJr  S SKrS SKJr  SSKJ	r	  SSKJ
r
  S
S jr " S S	\R                  5      rg)    )annotationsN)contextmanager   )_ansi_re)term_lenc                    US::  a  gSnSnSn[        U 5      nX5:  aD  [        R                  " X5      nUb  UR                  5       nM0  US-  nUS-  nUnX!:  a  OX5:  a  MD  U SU $ )zReturn the longest prefix of ``text`` containing at most ``n`` visible
characters.

ANSI escape sequences inside the prefix are kept intact and do not count
toward the visible width. A cut is never placed inside an escape sequence.
r    Nr   )lenr   matchend)textnvisibleicutr   ms          L/var/www/reloj-farallon/venv/lib/python3.13/site-packages/click/_textwrap.py_truncate_visibler      s     	AvG	A
C
d)C
'NN4#=A1	Q< ' :    c                  ^    \ rS rSrSr          S	S jrS
S jr\SS j5       rSS jr	Sr
g)TextWrapper&   ar  ``textwrap.TextWrapper`` variant that measures widths by visible
character count.

ANSI escape sequences embedded in chunks, indents, or the placeholder are
excluded from the width budget. Without this, styled help text (a styled
``Usage:`` prefix, a colorized option name, ...) would be wrapped earlier
than its visible length warrants and tokens would split mid-word.
c                    [        XC-
  S5      nU R                  (       a4  US   n[        Xe5      nU[        U5      S  nUR	                  U5        XS'   g U(       d   UR	                  UR                  5       5        g g )Nr   )maxbreak_long_wordsr   r
   appendpop)	selfreversed_chunkscur_linecur_lenwidth
space_leftlastr   ress	            r   _handle_long_wordTextWrapper._handle_long_word0   sp     !,
  "2&D#D5Cs3xz"COOC "%BOOO//12 r   c                   / nU R                   S::  a  [        SU R                   < S35      eU R                  bq  U R                  S:  a  U R                  nOU R                  n[        U5      [        U R                  R                  5       5      -   U R                   :  a  [        S5      eUR                  5         U(       Ga	  / nSnU(       a  U R                  nOU R                  nU R                   [        U5      -
  nU R                  (       a!  US   R                  5       S:X  a
  U(       a  US	 U(       aD  [        US   5      nXW-   U::  a$  UR                  UR                  5       5        XW-  nOO	U(       a  MD  U(       a=  [        US   5      U:  a+  U R                  XXV5        [        [        [
        U5      5      nU R                  (       a2  U(       a+  US   R                  5       S:X  a  U[        US   5      -  nUS	 U(       Ga  U R                  b`  [!        U5      S-   U R                  :  dD  U(       a8  U R                  (       aQ  [!        U5      S:X  aB  US   R                  5       (       d*  XV::  a%  UR                  USR#                  U5      -   5        GO%U(       a  US   R                  5       (       a^  U[        U R                  5      -   U::  aB  UR                  U R                  5        UR                  USR#                  U5      -   5          U$ U[        US   5      -  nUS	 U(       a  M  U(       aV  US   R%                  5       n[        U5      [        U R                  5      -   U R                   ::  a  XR                  -   US'    U$ UR                  X0R                  R                  5       -   5         U$ U(       a  GM	  U$ )aA  Wrap chunks counting widths in visible characters.

Mirrors the algorithm of :meth:`textwrap.TextWrapper._wrap_chunks`
with every width measurement routed through
:func:`click._compat.term_len` instead of :func:`len`, so ANSI escape
bytes in chunks, indents, or the placeholder do not inflate the count.

.. seealso::
    :class:`textwrap.TextWrapper` in the Python standard library documentation:
    https://docs.python.org/3/library/textwrap.html#textwrap.TextWrapper

    Reference implementation in CPython:
    https://github.com/python/cpython/blob/main/Lib/textwrap.py
r   zinvalid width z (must be > 0)r   z#placeholder too large for max widthr   r	   )r#   
ValueError	max_linessubsequent_indentinitial_indentr   placeholderlstripreversedrop_whitespacestripr   r   r'   summapr
   joinrstrip)	r   chunkslinesindentr!   r"   r#   r   	prev_lines	            r   _wrap_chunksTextWrapper._wrap_chunksB   s+    ::?~djj^>JKK>>%~~!//,,(4+;+;+B+B+D"EE

R !FGG"$HG//,,JJ&!11E##r
(8(8(:b(@U2JVBZ(;%'OOFJJL1LG  & (6":.6&&vHc(H56##Xb\5G5G5IR5O8HRL11RLNN*5zA~6"//K1, &q	 1 1(LL"''(*;!;<"$RL..00 '(43C3C*D D M$OOD,<,<=!LL"''(2C)CD!   8HRL#99$RL #( !(-b	(8(8(:I ( 3ht?O?O6P P#'::!. -68H8H,Hb	 %  V.>.>.E.E.G%GHI fH r   c              #     #    U R                   nU R                  nU =R                   U-  sl         U =R                  U-  sl         S v   X l         X0l        g ! X l         X0l        f = f7f)Nr-   r,   )r   r9   old_initial_indentold_subsequent_indents       r   extra_indentTextWrapper.extra_indent   sb     !00 $ 6 6v%&(	;"4%:" #5%:"s   AA(A 
A(A%%A(c                    / n[        UR                  5       5       H8  u  p4U R                  nUS:  a  U R                  nUR	                  U U 35        M:     SR                  U5      $ )Nr   
)	enumerate
splitlinesr-   r,   r   r5   )r   r   rvidxliner9   s         r   indent_onlyTextWrapper.indent_only   sa    "4??#45IC((FQw//II'( 6 yy}r   r>   N)
r    	list[str]r!   rL   r"   intr#   rM   returnNone)r7   rL   rN   rL   )r9   strrN   zcabc.Iterator[None])r   rP   rN   rP   )__name__
__module____qualname____firstlineno____doc__r'   r;   r   rA   rJ   __static_attributes__ r   r   r   r   &   s\    3"3 3 	3
 3 
3$`D 
; 
;r   r   )r   rP   r   rM   rN   rP   )
__future__r   collections.abcabccabctextwrap
contextlibr   _compatr   r   r   r   rW   r   r   <module>r_      s0    "   %  6V(&& Vr   