;i&UddlmZddlmZddlmZddlmZddl m Z ddl m Z dZ ded <d$dZd%dZ d&d'dZGddZd(d#ZdS))) annotationsN)contextmanager)gettext)term_len) _split_opt int | None FORCED_WIDTHrowscabc.Iterable[tuple[str, str]]returntuple[int, ...]ci}|D]K}t|D]9\}}t||dt|||<:Lt dt |DS)Nrc3 K|] \}}|V dS)N).0xys DC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\click/formatting.py z measure_table..s&66tq!666666) enumeratemaxgetrtuplesorteditems)r widthsrowidxcols r measure_tabler"sFAA!# A AHCfjja00(3--@@F3KK A 66vfllnn55666 6 66r col_countintcabc.Iterator[tuple[str, ...]]c#HK|D]}|d|t|z zzVdS)N))len)r r#rs r iter_rowsr)sE33EYS122222233rNr'Ftextstrwidthinitial_indentsubsequent_indentpreserve_paragraphsboolc ddlm}|}||||d}|s||Sgg d d fd }|D]]}|s |d  5t |} |}| t |z |^|g} D]\ } }|d z5| r)| | |n(| ||dddn #1swxYwYd | S) aA helper function that intelligently wraps text. By default, it assumes that it operates on a single paragraph of text but if the `preserve_paragraphs` parameter is provided it will intelligently handle paragraphs (defined by two empty lines). If paragraphs are handled, a paragraph can be prefixed with an empty line containing the ``\b`` character (``\x08``) to indicate that no rewrapping should happen in that block. :param text: the text that should be rewrapped. :param width: the maximum width for the text. :param initial_indent: the initial indent that should be placed on the first line as a string. :param subsequent_indent: the indent string that should be placed on each consecutive line. :param preserve_paragraphs: if this flag is set then the wrapping will intelligently handle paragraphs. r) TextWrapperF)r.r/replace_whitespaceNr Nonec sdSddkr6pdddddfn-pdddfdd=dS)NrT rF )stripappendjoin)bufindentpsr _flush_parzwrap_text.._flush_parHs  F q6<<>>T ! ! HHfk43qrr7););< = = = = HHfk5#((3--8 9 9 9 FFFrr9z r r5) _textwrapr3 expandtabsfill splitlinesrlstripr; extra_indent indent_onlyr<)r+r-r.r/r0r3wrapperr@lineorig_lenrvrawr=r>r?s @@@r wrap_textrNs2'&&&&& ??  Dk %+ G "||D!!!%'AC F!!    JLLLFF~#D>>{{}}!HTNN2 JJt    JLLL B..T  ! !#, / / . . . '--d334444 ',,t,,---  . . . . . . . . . . . . . . . ;;r??s0AEE E ceZdZdZ d'd(d Zd)dZd*dZd*dZd+d,dZd-dZ d*dZ d.dZ d/d0d!Z e d1d$Ze d2d%Zd3d&ZdS)4 HelpFormatteraThis class helps with formatting text-based help pages. It's usually just needed for very special internal cases, but it's also exposed so that developers can write their own fancy outputs. At present, it always writes into memory. :param indent_increment: the additional increment for each level. :param width: the width for the text. This defaults to the terminal width clamped to a maximum of 78. Nindent_incrementr$r-r max_widthr r5c||_|d}|Eddl}t}|8tt |j|dz d}||_d|_g|_ dS)NPrrQ2) rRshutilr rminget_terminal_sizecolumnsr-current_indentbuffer)selfrRr-rSrWs r__init__zHelpFormatter.__init__tsx !1  I = MMM E}C 8 8 : : BINNQRRTVWW #$!# rstringr,c:|j|dS)z1Writes a unicode string into the internal buffer.N)r\r;)r]r_s rwritezHelpFormatter.writes 6"""""rc0|xj|jz c_dS)zIncreases the indentation.Nr[rRr]s rr>zHelpFormatter.indent t44rc0|xj|jzc_dS)zDecreases the indentation.Nrcrds rdedentzHelpFormatter.dedentrerr'progargsprefix str | Nonec$|tdd}|d|j|d}|j|jz }|t|dzkr9dt|z}|t ||||nx|||ddt |jt|dzz}|t |||||ddS) zWrites a usage line into the buffer. :param prog: the program name. :param args: whitespace separated list of arguments. :param prefix: The prefix for the first line. Defaults to ``"Usage: "``. NzUsage:r9>)r.r/r8)_r[r-rrarNr)r]rhrirj usage_prefix text_widthr>s r write_usagezHelpFormatter.write_usagesE >( &&&F @4#6@@@@@@ Z$"55 (<0025 6 68L111F JJ#/&,      JJ| $ $ $ JJt   C 3Xf5E5EFFJKF JJ*Vv    4rheadingcL|dd|j|ddS)z!Writes a heading into the buffer.r'rmz: N)rar[)r]rts r write_headingzHelpFormatter.write_headings6 b=4.======>>>>>rcB|jr|ddSdS)z#Writes a paragraph into the buffer.r8N)r\rards rwrite_paragraphzHelpFormatter.write_paragraphs. ;  JJt       rr+c d|jz}|t||j||d|ddS)zaWrites re-indented text into the buffer. This rewraps and preserves paragraphs. r9T)r.r/r0r8N)r[rarNr-)r]r+r>s r write_textzHelpFormatter.write_textsdt**  %"($(        4rr cabc.Sequence[tuple[str, str]]col_max col_spacingct|}t|}t|dkrtdt |d||z}t |t|D]_\}}|dd|j||s|d@t|||z kr)|d|t|z zn5|d|d||jzzt|j |z dz d}t||d } | } | rS|| dd| d d D](} |dd||jz| d)J|dad S) anWrites a definition list into the buffer. This is how options and commands are usually formatted. :param rows: a list of two item tuples for the terms and values. :param col_max: the maximum width of the first column. :param col_spacing: the number of spaces between the first and second column. rQz(Expected two columns for definition listrr'rmr8r9 T)r0rN) listr"r( TypeErrorrXr)rar[rrr-rNrE) r]r r}r~r first_colfirstsecondrr wrapped_textlinesrJs rwrite_dlzHelpFormatter.write_dlsDzzt$$ v;;!  FGG Gq 7++k9 &tS[[99 ! !ME6 JJ"???? 4    3)d.A"ABCCCTZ)3a7<rg)r]rs rsectionzHelpFormatter.sectionsl  4      EEE KKMMMMMDKKMMMMs AA1c#K| dV|dS#|wxYw)z1A context manager that increases the indentation.N)r>rgrds r indentationzHelpFormatter.indentation sF   EEE KKMMMMMDKKMMMMs 2Ac6d|jS)zReturns the buffer contents.r')r<r\rds rgetvaluezHelpFormatter.getvalueswwt{###r)rQNN)rRr$r-r rSr r r5)r_r,r r5rA)r'N)rhr,rir,rjrkr r5)rtr,r r5)r+r,r r5)r{rQ)r r|r}r$r~r$r r5)rr,r r)r r)r r,)__name__ __module__ __qualname____doc__r^rar>rgrsrvrxrzrrrrrrrrrPrPhsJ  !" $ $$$$$&####55555555$$$$$L???? & *!*!*!*!*!X   ^ ^$$$$$$rrPoptionscabc.Sequence[str]tuple[str, bool]cg}d}|D]C}t|d}|dkrd}|t||fD|ddd|D|fS) a Given a list of option strings this joins them in the most appropriate way and returns them in the form ``(formatted_string, any_prefix_is_slash)`` where the second item in the tuple is a flag that indicates if any of the option prefixes was a slash. Fr/Tc|dS)Nrr)rs rzjoin_options..,s !A$r)keyz, c3&K|] }|dV dS)rNr)rrs rrzjoin_options..-s&&&aQqT&&&&&&r)rr;r(sortr<)rrLany_prefix_is_slashoptrjs r join_optionsrs B&&C# S=="&  3v;;$%%%%GGG 99&&2&&& & &(; ;;r)r r r r)r r r#r$r r%)r*r'r'F) r+r,r-r$r.r,r/r,r0r1r r,)rrr r) __future__rcollections.abcabccabc contextlibrrrp_compatrparserrr __annotations__r"r)rNrPrrrrrs+"""""""%%%%%%  77773333 % FFFFFRp$p$p$p$p$p$p$p$f<<<<<