B x `A$ã@sjddlmZddlmZddlmZddlmZdZdd„Z d d „Z ddd„Z Gdd„de ƒZ dd„ZdS)é)Úcontextmanageré)Úterm_len)Ú split_opt)Úget_terminal_sizeNcCs\i}x<|D]4}x.t|ƒD]"\}}t| |d¡t|ƒƒ||<qWq Wtdd„t| ¡ƒDƒƒS)Nrcss|]\}}|VqdS)N©)Ú.0ÚxÚyrrú4/tmp/pip-unpacked-wheel-za9e8r29/click/formatting.pyú sz measure_table..)Ú enumerateÚmaxÚgetrÚtupleÚsortedÚitems)ÚrowsÚwidthsÚrowÚidxÚcolrrr Ú measure_table s  "rccs0x*|D]"}t|ƒ}|d|t|ƒVqWdS)N)Ú)rÚlen)rZ col_countrrrr Ú iter_rowss réNrFc sddlm}| ¡}||||dd}|s2| |¡Sg‰g‰d‰‡‡‡fdd„}xN| ¡D]B}|sl|ƒd‰qXˆdkrt|ƒ} | ¡}| t|ƒ‰ˆ |¡qXW|ƒg} xRˆD]J\‰} }| dˆ¡,| rÞ|  |  |¡¡n|  | |¡¡WdQRXq®Wd   | ¡S) a²A 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)Úinitial_indentÚsubsequent_indentÚreplace_whitespaceNc sdˆsdSˆd ¡dkr<ˆ ˆp"ddd ˆdd…¡f¡nˆ ˆpFddd ˆ¡f¡ˆdd…=dS)NrúTÚ rFú )ÚstripÚappendÚjoinr)ÚbufÚindentÚprr Ú _flush_par>s $zwrap_text.._flush_parr#z ) Z _textwraprÚ expandtabsÚfillÚ splitlinesrÚlstripr%Z extra_indentZ indent_onlyr&) ÚtextÚwidthrrÚpreserve_paragraphsrÚwrapperr*ÚlineZorig_lenÚrvÚrawr)r'r(r)r Ú wrap_texts<    r6c@s~eZdZdZddd„Zdd„Zdd „Zd d „Zd dd„Zdd„Z dd„Z dd„Z d!dd„Z e dd„ƒZe dd„ƒZdd„ZdS)"Ú HelpFormattera¾This 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. éNcCsV||_|dkrd}|dkr@t}|dkr@tttƒd|ƒddƒ}||_d|_g|_dS)NéPrr8é2)Úindent_incrementÚ FORCED_WIDTHrÚminrr0Úcurrent_indentÚbuffer)Úselfr;r0Ú max_widthrrr Ú__init__jszHelpFormatter.__init__cCs|j |¡dS)z1Writes a unicode string into the internal buffer.N)r?r%)r@Ústringrrr ÚwritevszHelpFormatter.writecCs|j|j7_dS)zIncreases the indentation.N)r>r;)r@rrr r(zszHelpFormatter.indentcCs|j|j8_dS)zDecreases the indentation.N)r>r;)r@rrr Údedent~szHelpFormatter.dedentrúUsage: cCs¢dj|||jd}|j|j}|t|ƒdkrRdt|ƒ}| t||||d¡nB| |¡| d¡dt|jt|ƒƒd}| t||||d¡| d¡dS) zÈWrites 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. z {:>{w}}{} )Úwér#)rrr"éN)Úformatr>r0rrDr6r)r@ÚprogÚargsÚprefixZ usage_prefixÚ text_widthr(rrr Ú write_usage‚s"     zHelpFormatter.write_usagecCs| djd||jd¡dS)z!Writes a heading into the buffer.z {:>{w}}{}: r)rGN)rDrJr>)r@Úheadingrrr Ú write_heading¤szHelpFormatter.write_headingcCs|jr| d¡dS)z#Writes a paragraph into the buffer.r"N)r?rD)r@rrr Úwrite_paragraph¨szHelpFormatter.write_paragraphc CsBt|j|jdƒ}d|j}| t||||dd¡| d¡dS)zaWrites re-indented text into the buffer. This rewraps and preserves paragraphs. é r#T)rrr1r"N)rr0r>rDr6)r@r/rNr(rrr Ú write_text­s  zHelpFormatter.write_textéc Csdt|ƒ}t|ƒ}t|ƒdkr$tdƒ‚t|d|ƒ|}x&t|t|ƒƒD]\}}| djd||jd¡|sz| d¡qHt |ƒ||kr¢| d|t |ƒ¡n| d¡| d||j¡t |j |dd ƒ}t ||d d } |   ¡} | rR| d  | d¡¡x2| d d…D]"} | djd| ||jd¡qWt| ƒd kr\| d¡qH| d¡qHWdS)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. r8z(Expected two columns for definition listrz {:>{w}}{}r)rGr"r#é T)r1z{} rNz {:>{w}}{} )ÚlistrrÚ TypeErrorr=rrDrJr>rrr0r6r-) r@rZcol_maxZ col_spacingrZ first_colÚfirstÚsecondrNZ wrapped_textÚlinesr3rrr Úwrite_dl¾s4     zHelpFormatter.write_dlccs4| ¡| |¡| ¡z dVWd| ¡XdS)z Helpful context manager that writes a paragraph, a heading, and the indents. :param name: the section name that is written as heading. N)rRrQr(rE)r@Únamerrr Úsectionís   zHelpFormatter.sectionccs"| ¡z dVWd| ¡XdS)z1A context manager that increases the indentation.N)r(rE)r@rrr Ú indentationüs zHelpFormatter.indentationcCs d |j¡S)zReturns the buffer contents.r)r&r?)r@rrr ÚgetvalueszHelpFormatter.getvalue)r8NN)rrF)rUr8)Ú__name__Ú __module__Ú __qualname__Ú__doc__rBrDr(rErOrQrRrTr\rr^r_r`rrrr r7^s   " /  r7cCslg}d}x6|D].}t|ƒd}|dkr*d}| t|ƒ|f¡qW|jdd„dd d d „|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ú/TcSs|dS)Nrr)r rrr Úózjoin_options..)Úkeyz, css|]}|dVqdS)rNr)rr rrr r szjoin_options..)rr%rÚsortr&)Úoptionsr4Zany_prefix_is_slashÚoptrMrrr Ú join_options s  rl)rrrF)Ú contextlibrÚ_compatrÚparserrZtermuirr<rrr6Úobjectr7rlrrrr Ús     D-