a c%@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 ]/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/click/formatting.py z 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\durt|} |}| t||q\|g} D]`\} }|d 6| r| | |n| ||Wdq1s0Yqd | 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&wrapperr3lineZorig_lenrvrawr r/r wrap_texts>     2r<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}||_|durd}|durHt}|durHtt|j|dd}||_d|_g|_ dS)NrPr>2) shutilr?rrminget_terminal_sizecolumnsr"current_indentbuffer)selfr?r"r@rCr r r__init__rszHelpFormatter.__init__)stringr cCs|j|dS)z1Writes a unicode string into the internal buffer.N)rHr-)rIrKr r rwriteszHelpFormatter.writer(cCs|j|j7_dS)zIncreases the indentation.NrGr?rIr r rr1szHelpFormatter.indentcCs|j|j8_dS)zDecreases the indentation.NrMrNr r rdedentszHelpFormatter.dedentr)progargsprefixr cCs|durtdd}|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*)_rGr"rrLr<r)rIrPrQrRZ usage_prefix text_widthr1r r r write_usages.     zHelpFormatter.write_usage)headingr cCs"|dd|j|ddS)z!Writes a heading into the buffer.rrSz: N)rLrG)rIrYr r r write_headingszHelpFormatter.write_headingcCs|jr|ddS)z#Writes a paragraph into the buffer.r*N)rHrLrNr 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)rGrLr<r")rIr!r1r 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 listrrrSr*r+ T)r%rN) listrr TypeErrorrDrrLrGrrr"r<r6) rIrr^r_rZ first_colfirstsecondrWZ wrapped_textlinesr9r r rwrite_dls,   (zHelpFormatter.write_dl)namer ccs<||||zdVW|n |0dS)zHelpful context manager that writes a paragraph, a heading, and the indents. :param name: the section name that is written as heading. N)r[rZr1rO)rIrgr r rsections  zHelpFormatter.sectionccs*|zdVW|n |0dS)z1A context manager that increases the indentation.N)r1rOrNr r r indentation szHelpFormatter.indentationcCs d|jS)zReturns the buffer contents.r)r.rHrNr r rgetvalueszHelpFormatter.getvalue)r>NN)rN)r]r>)__name__ __module__ __qualname____doc__inttOptionalrJstrrLr1rOrXrZr[r\SequenceTuplerfrIteratorrhrirjr r r rr=fsD    ( ,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,rzjoin_options..)keyz, css|]}|dVqdS)rNr )r r r r rr-rzjoin_options..)rr-rsortr.)rvr:Zany_prefix_is_slashoptrRr r r join_optionss r|)r rrF)typingrp contextlibrrrV_compatrparserrrrqro__annotations__Iterablertrrrrurboolr<r=rsr|r r r rs0     *   I6