U a%@sUddlZddlmZddlmZddlmZddlm Z dZ ej e e d<ejejeefeje dfd d d Zejejeefe ejejedfd d dZdee eeeedddZGdddZejeejeefdddZdS)N)contextmanager)gettext)term_len) split_opt FORCED_WIDTH.)rowsreturncCsTi}|D]0}t|D]"\}}t||dt|||<qqtddt|DS)Nrcss|]\}}|VqdS)N).0xyr r QC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-s9fh6ldx\click\formatting.py sz measure_table..) enumeratemaxgetrtuplesorteditems)rwidthsrowidxcolr r r measure_table s r)r col_countr ccs$|D]}|d|t|VqdS)N))len)rrrr r r iter_rowssrNrF)textwidthinitial_indentsubsequent_indentpreserve_paragraphsr c sddlm}|}||||dd}|s2||Sggdddfdd }|D]B}|sp|dq\dkrt|} |}| t||q\|g} D]J\} }|d ,| r| | |n| ||W5QRXqd | 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 c sdsdSddkr<p"dddddfnpFdddfdd=dS)NrT rF )stripappendjoinr bufindentpr r _flush_parFs $zwrap_text.._flush_parr*z ) Z _textwrapr% expandtabsfill splitlinesrlstripr,Z extra_indentZ indent_onlyr-) r r!r"r#r$r%wrapperr2lineZorig_lenrvrawr r.r wrap_texts>     r;c@seZdZdZd&eejeejeddddZedddd Z dd d d Z dd d dZ d'eeejeddddZ eddddZ dd ddZeddddZd(ejejeefeeddddZeeejddd d!Zeejdd d"d#Zed d$d%ZdS)) 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. N)indent_incrementr! max_widthr cCs^ddl}||_|dkrd}|dkrHt}|dkrHtt|j|dd}||_d|_g|_ dS)NrPr=2) shutilr>rrminget_terminal_sizecolumnsr!current_indentbuffer)selfr>r!r?rBr r r__init__rszHelpFormatter.__init__)stringr cCs|j|dS)z1Writes a unicode string into the internal buffer.N)rGr,)rHrJr r rwriteszHelpFormatter.writer'cCs|j|j7_dS)zIncreases the indentation.NrFr>rHr r rr0szHelpFormatter.indentcCs|j|j8_dS)zDecreases the indentation.NrLrMr r rdedentszHelpFormatter.dedentr)progargsprefixr cCs|dkrtdd}|d|j|d}|j|j}|t|dkrndt|}|t||||dnB|||ddt|jt|d}|t||||d|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:r*>)r"r#r))_rFr!rrKr;r)rHrOrPrQZ usage_prefix text_widthr0r r r write_usages4     zHelpFormatter.write_usage)headingr cCs"|dd|j|ddS)z!Writes a heading into the buffer.rrRz: N)rKrF)rHrXr r r write_headingszHelpFormatter.write_headingcCs|jr|ddS)z#Writes a paragraph into the buffer.r)N)rGrKrMr r rwrite_paragraphszHelpFormatter.write_paragraph)r r c Cs2d|j}|t||j||dd|ddS)zaWrites re-indented text into the buffer. This rewraps and preserves paragraphs. r*T)r"r#r$r)N)rFrKr;r!)rHr r0r r r write_texts  zHelpFormatter.write_text)rcol_max col_spacingr c CsLt|}t|}t|dkr$tdt|d||}t|t|D]\}}|dd|j||sz|dqDt|||kr|d|t|n|d|d||jt |j |dd}t ||d d } | } | r<|| dd| d d D](} |dd||j| dqqD|dqDd 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. r=z(Expected two columns for definition listrrrRr)r* T)r$rN) listrr TypeErrorrCrrKrFrrr!r;r5) rHrr]r^rZ first_colfirstsecondrVZ wrapped_textlinesr8r r rwrite_dls,   (zHelpFormatter.write_dl)namer ccs4||||z dVW5|XdS)zHelpful context manager that writes a paragraph, a heading, and the indents. :param name: the section name that is written as heading. N)rZrYr0rN)rHrfr r rsections   zHelpFormatter.sectionccs"|z dVW5|XdS)z1A context manager that increases the indentation.N)r0rNrMr r r indentation s zHelpFormatter.indentationcCs d|jS)zReturns the buffer contents.r)r-rGrMr r rgetvalueszHelpFormatter.getvalue)r=NN)rN)r\r=)__name__ __module__ __qualname____doc__inttOptionalrIstrrKr0rNrWrYrZr[SequenceTuplererIteratorrgrhrir r r rr<fsJ   ( ,r<)optionsr cCsdg}d}|D].}t|d}|dkr(d}|t||fq |jddddd 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 r r r,zjoin_options..)keyz, css|]}|dVqdS)rNr )r r r r rr-szjoin_options..)rr,rsortr-)rur9Zany_prefix_is_slashoptrQr r r join_optionss r|)rrrF)typingro contextlibrrrU_compatrparserrrrprn__annotations__Iterablersrqrrtrboolr;r<rrr|r r r rs4    *   I6