Xj~zddlmZddlmZddlZddlmZddlm Z ddlm Z d dZ Gdd ejZ y) ) annotationsN)contextmanager)_ansi_re)term_lenc|dkryd}d}d}t|}||krAtj||}||j}.|dz }|dz }|}||k\rn||krA|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)textnvisibleicutr ms c/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/click/_textwrap.py_truncate_visibler s AvG A C d)C c' NN4 # =A 1  Q a<  c' :cNeZdZdZ ddZddZed dZd dZy) 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. ct||z d}|jr6|d}t||}|t|d}|j |||d<y|s |j |j yy)Nr)maxbreak_long_wordsrr appendpop) selfreversed_chunkscur_linecur_lenwidth space_leftlastrress r_handle_long_wordzTextWrapper._handle_long_word0sv!,  "2&D#D*5Cs3xz"C OOC "%OB  OOO//1 2rcg}|jdkrtd|jd|jo|jdkDr |j}n |j}t |t |j jz|jkDr td|j|rg}d}|r |j}n |j}|jt |z }|jr|djdk(r|r|d=|r?t |d}||z|kr%|j|j||z }nn|r?|r>t |d|kDr-|j||||ttt |}|jr,|r*|djdk(r|t |dz}|d=|r|jOt!|dz|jks4|r-|jrKt!|dk(r=|djs*||kr%|j|dj#|zn|r|djr]|t |j z|krB|j|j |j|dj#|z |S|t |dz}|d=|r|rV|dj%}t |t |j z|jkr||j z|d< |S|j||j jz |S|r|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)rz#placeholder too large for max widthrr )r" ValueError max_linessubsequent_indentinitial_indentr placeholderlstripreversedrop_whitespacestriprrr&summapr joinrstrip) rchunkslinesindentr r!r"r prev_lines r _wrap_chunkszTextWrapper._wrap_chunksBs- ::?~djj^>JK K >> %~~!//,,(4+;+;+B+B+D"EE R !FGG"$HG//,,JJ&!11E##r (8(8(:b(@U2JVBZ(Q;%'OOFJJL1qLG(6":.6&&vx%Hc(H56##Xb\5G5G5IR5O8HRL11RLNN*5zA~6"//K1, &q  15(LL"''(*;!;<"$RL..0 '(43C3C*D D M$OOD,<,<=!LL"''(2C)CD!  8HRL#99$RL#!(-b (8(8(:I ( 3ht?O?O6P P#'::!.-68H8H,Hb %  Vd.>.>.E.E.G%GH IH rc#K|j}|j}|xj|z c_|xj|z c_ d||_||_y#||_||_wxYww)N)r+r*)rr7old_initial_indentold_subsequent_indents r extra_indentzTextWrapper.extra_indentsk!00 $ 6 6 v% &( ; "4D %:D "#5D %:D "sAA,A A,A))A,cg}t|jD]7\}}|j}|dkDr |j}|j ||9dj |S)Nr ) enumerate splitlinesr+r*rr3)rr rvidxliner7s r indent_onlyzTextWrapper.indent_onlysh "4??#45 )IC((FQw// II' (  )yy}rN) r list[str]r rFr!intr"rGreturnNone)r5rFrHrF)r7strrHzcabc.Iterator[None])r rJrHrJ) __name__ __module__ __qualname____doc__r&r9rr=rErrrr&s\3"33 3  3  3$`D ; ; rr)r rJrrGrHrJ) __future__rcollections.abcabccabctextwrap contextlibr_compatrrrrrOrrrWs0"%6V(&&Vr