4V=j~xddlmZddlmZddlZddlmZddlm Z ddlm Z dd Z Gd dej Z dS)) annotationsN)contextmanager)_ansi_re)term_lentextstrnintreturnc|dkrdSd}d}d}t|}||krEtj||}||}2|dz }|dz }|}||krn||kE|d|S)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. rNr)lenrmatchend)rr visibleicutrms =C:\PYTHON\_runtimes\venv\Lib\site-packages\click/_textwrap.py_truncate_visibler s AvvrG A C d))C c'' N4 # # =A 1  Q a<<  c'' :cBeZdZdZdd Zdd ZeddZddZdS) TextWrappera``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. reversed_chunks list[str]cur_linecur_lenr widthr Nonec&t||z d}|jrK|d}t||}|t|d}||||d<dS|s)||dSdS)Nr)maxbreak_long_wordsrrappendpop) selfrrrr space_leftlastrress r_handle_long_wordzTextWrapper._handle_long_word0s!,,   3"2&D#D*55Cs3xxzz"C OOC "%OB    3 OOO//11 2 2 2 2 2 3 3rchunksc:g}|jdkrtd|jd|jh|jdkr|j}n|j}t |t |jz|jkrtd||rg}d}|r|j}n|j}|jt |z }|j r#|d dkr|r|d=|rNt |d}||z|kr-| | ||z }nn|N|rSt |d|kr:| ||||ttt |}|j r;|r9|d dkr|t |dz}|d=|r|jWt!|dz|jks<|r4|j r`t!|dkrM|d s3||kr-| |d|zn!|r|d ra|t |jz|krF| |j| |d|zn|t |dz}|d=||rU|d}t |t |jz|jkr||jz|d<n3| ||jzn||S) aWrap 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 rzinvalid width z (must be > 0)Nrz#placeholder too large for max widthr"r)r ValueError max_linessubsequent_indentinitial_indentr placeholderlstripreversedrop_whitespacestripr%r&r+summaprjoinrstrip) r'r,linesindentrrrr prev_lines r _wrap_chunkszTextWrapper._wrap_chunksBs :??JdjJJJKK K > %~!!/,(4+;+B+B+D+D"E"EE RR !FGGGB "$HG -/,J&!1!11E# r (8(8(:(:b(@(@U(@2J VBZ((Q;%''OOFJJLL111qLGG  7(6":..66&&vx%HHHc(H5566# ! !Xb\5G5G5I5IR5O5O8HRL111RL" N*5zzA~66"7 /7 KK1,, &q  1 1- 5((LL"''(*;*;!;<<<<"I$RL..00" '(43C*D*D D M M$OOD,<===!LL"''(2C2C)CDDD!8HRL#9#99$RL#I!&(-b (8(8(:(:I ( 3 3ht?O6P6P P#':!.!.-68H,Hb % Vd.>.E.E.G.G%GHHHEB H rr<r cabc.Iterator[None]c#K|j}|j}|xj|z c_|xj|z c_ dV||_||_dS#||_||_wxYw)N)r1r0)r'r<old_initial_indentold_subsequent_indents r extra_indentzTextWrapper.extra_indents!0 $ 6 v% &( ; EEE"4D %:D " " "#5D %:D " : : : :s AArcg}t|D]2\}}|j}|dkr|j}|||3d|S)Nr ) enumerate splitlinesr1r0r%r9)r'rrvidxliner<s r indent_onlyzTextWrapper.indent_onlysu "4??#4#455 ) )IC(FQww/ II''' ( ( ( (yy}}rN) rrrrrr rr r r )r,rr r)r<r r r?)rr r r ) __name__ __module__ __qualname____doc__r+r>rrCrKrrrr&s3333$````D ; ; ;^ ;      rr)rr r r r r ) __future__rcollections.abcabccabctextwrap contextlibr_compatrrrrrPrrrXs""""""%%%%%%6VVVVV(&VVVVVr