
    kjC              	          d dl Zd dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
mZmZmZmZmZmZmZ d dlmZ d dlmZ erddlmZmZ d dlZd dlmZ d d	lmZmZmZmZm Z  d
dlm!Z!m"Z" d dl#m$Z$m%Z% ee&ee&e	e'ge&f         f         f         Z( ej)                     G d d                      Z* G d dej+                  Z+dee(         de'deee&e&f                  fdZ,dS )    N)chain)
AnyCallableDictIterableIteratorOptionalSequenceTYPE_CHECKINGTupleUnion)click_version_ge_8_1unstyled_len   )RowSepPolicySepGenerator)	wrap_text)check_positive_intidentityindent_lines	make_reprpick_non_missing   )MISSINGPossibly)	HelpThemeIStylec                   n    e Zd ZU dZeed<   	 ee         ed<   	 dZe	e         ed<   	 dZ
e	e         ed<   dS )HelpSectionz$A container for a help section data.headingdefinitionsNhelp
constraint)__name__
__module____qualname____doc__str__annotations__r
   
Definitionr#   r	   r$        V/home/agentuser/manim-venv/lib/python3.11/site-packages/cloup/formatting/_formatter.pyr    r       sh         ..LLL*%%%%Z D(3-5 $J$$$99r-   r    c                       e Zd ZdZddddddd e            fdedee         dee         d	ed
ededededdf         def fdZ	e
eeeeeeeeddeee                  deee                  dee         d	ee         d
ee         dee         deededdf                  dee         deeef         fd            Zedefd            ZdeddfdZ	 d<dededee         ddf fdZdee         ddfdZdej        ddfdZd=d!ed"eddfd#Z	 d=d$ee         d%eddfd&Zd$ee         ddfd'Zd>d(ed)ee         ddfd*Zefd+ed,e ddfd-Z!d.e"e#         dedefd/Z$	 	 	 d?d.ee#         d0ee         dee         d)ee         ddf
d1Z%d2eee                  d3ee         dedee         fd4Z&d.ee#         d)eded5eddf
d6Z'd7ee#         ddfd8Z(d9eddfd:Z)defd;Z* xZ+S )@HelpFormattera=  
    A custom help formatter. Features include:

    - more attributes for controlling the output of the formatter
    - a ``col1_width`` parameter in :meth:`write_dl` that allows Cloup to align
      multiple definition lists without resorting to hacks
    - a "linear layout" for definition lists that kicks in when the available
      terminal width is not enough for the standard 2-column layout
      (see argument ``col2_min_width``)
    - the first column width, when not explicitly given in ``write_dl`` is
      computed excluding the rows that exceed ``col1_max_width``
      (called ``col_max`` in ``write_dl`` for compatibility with Click).

    .. versionchanged:: 0.9.0
        the ``row_sep`` parameter now:

        - is set to ``None`` by default and ``row_sep=""`` corresponds to an
          empty line between rows
        - must not ends with ``\n``; the formatter writes a newline just after
          it (when it's not ``None``), so a newline at the end is always enforced
        - accepts instances of :class:`~cloup.formatting.sep.SepGenerator` and
          :class:`~cloup.formatting.sep.RowSepPolicy`.

    .. versionadded:: 0.8.0

    :param indent_increment:
        width of each indentation increment.
    :param width:
        content line width, excluding the newline character; by default it's
        initialized to ``min(terminal_width - 1, max_width)`` where
        ``max_width`` is another argument.
    :param max_width:
        maximum content line width (equivalent to ``Context.max_content_width``).
        Used to compute ``width`` when it is not provided, ignored otherwise.
    :param col1_max_width:
        the maximum width of the first column of a definition list; as in Click,
        if the text of a row exceeds this threshold, the 2nd column is printed
        on a new line.
    :param col2_min_width:
        the minimum width for the second column of a definition list; if the
        available space is less than this value, the formatter switches from the
        standard 2-column layout to the "linear layout" (that this decision
        is taken for each definition list). If you want to always use the linear
        layout, you can set this argument to a very high number (or ``math.inf``).
        If you never want it (not recommended), you can set this argument to zero.
    :param col_spacing:
        the number of spaces between the column boundaries of a definition list.
    :param row_sep:
        an "extra" separator to insert between the rows of a definition list (in
        addition to the normal newline between definitions). If you want an empty
        line between rows, pass ``row_sep=""``.
        Read :ref:`Row separators <row-separators>` for more.
    :param theme:
        an :class:`~cloup.HelpTheme` instance specifying how to style the various
        elements of the help page.
    r   N   #   indent_incrementwidth	max_widthcol1_max_widthcol2_min_widthcol_spacingrow_sepr   r   themec	                    t          |d           t          |d           t          |t                    r$|                    d          rt	          d          |pd}|p:t
          j        j        p)t          |t          j
        d          j        dz
            }t                                          |||           || _        || _        || _        || _        || _        || _        d S )	Nr6   r8   
zsince v0.9, row_sep must not end with '\n'. The formatter writes a '\n' after it; no other newline is allowed.
If you want an empty line between rows, set row_sep=''.P   )r=   d   r   )r4   r5   r3   )r   
isinstancer)   endswith
ValueErrorclick
formattingFORCED_WIDTHminshutilget_terminal_sizecolumnssuper__init__r4   r6   r7   r8   r:   r9   )
selfr3   r4   r5   r6   r7   r8   r9   r:   	__class__s
            r.   rJ   zHelpFormatter.__init__j   s    	>+;<<<;666gs## 	K(8(8(>(> 	KJK K K
 O	
  O,O9f6yAAIAMNN 	
 	9?O 	 	
 	
 	
  
,,&
r-   r4   r5   r3   r6   r7   r8   r9   r:   returnc                 8    t          t                                S )aR  A utility method for creating a ``formatter_settings`` dictionary to
        pass as context settings or command attribute. This method exists for
        one only reason: it enables auto-complete for formatter options, thus
        improving the developer experience.

        Parameters are described in :class:`HelpFormatter`.
        )r   localsrM   s           r.   settingszHelpFormatter.settings   s    $  )))r-   c                      | j         | j        z
  S N)r4   current_indentrK   s    r.   available_widthzHelpFormatter.available_width   s    zD///r-   stringsc                 &    | xj         |z  c_         d S rS   )buffer)rK   rW   s     r.   writezHelpFormatter.write   s    wr-    progargsprefixc                     |dn|}| j                             |          dz   }| j                             |          }t                                          |||           d S )NzUsage: )r:   r!   invoked_commandrI   write_usage)rK   r\   r]   r^   rL   s       r.   rb   zHelpFormatter.write_usage   sc     $^##F++c1z))$//D$/////r-   aliasesc                                            dd           d                     fd|D                       }                     d| d           d S )NAliasesFnewlinez, c              3   L   K   | ]}j                             |          V  d S rS   )r:   col1).0aliasrK   s     r.   	<genexpr>z.HelpFormatter.write_aliases.<locals>.<genexpr>   s1      KK%tzu55KKKKKKr-   r`   r<   )write_headingjoinrZ   )rK   rc   
alias_lists   `  r.   write_aliaseszHelpFormatter.write_aliases   sf    9e444YYKKKK7KKKKK


%z%%%&&&&&r-   cmdc                 h   |j         pd}|r4t          r-t          j        |                              d          d         }|j        rd|z   }|rd|                                  |                                 5  |                     || j	        j
                   d d d            d S # 1 swxY w Y   d S d S )Nr[   r   z(Deprecated) )style)r#   r   inspectcleandoc	partition
deprecatedwrite_paragraphindentation
write_textr:   command_help)rK   rq   	help_texts      r.   write_command_help_textz%HelpFormatter.write_command_help_text   s$   HN	 	G- 	G(33==dCCAFI> 	4 ()3I 	J  """!!## J J	1HIIIJ J J J J J J J J J J J J J J J J J	J 	Js   6"B%%B),B)Tr!   rg   c                     | j         r|                     d| j         z             |                     | j                            |dz                        |r|                     d           d S d S )Nr`   :r<   )rT   rZ   r:   r!   )rK   r!   rg   s      r.   rm   zHelpFormatter.write_heading   sw     	2JJsT00111

4:%%gm44555 	JJt	 	r-   sectionsalignedc                 h    |r|                      |          S |D ]}|                     |           d S rS   )write_aligned_sectionswrite_section)rK   r   r   ss       r.   write_many_sectionsz!HelpFormatter.write_many_sections   sP      	9..x888 	" 	"Aq!!!!	" 	"r-   c                     t          j        d |D                       }|                     || j                  }|D ]}|                     ||           dS )z(Write multiple aligned definition lists.c              3   $   K   | ]}|j         V  d S rS   )r"   )rj   dls     r.   rl   z7HelpFormatter.write_aligned_sections.<locals>.<genexpr>   s$      &I&I"r~&I&I&I&I&I&Ir-   
col1_widthN)r   from_iterablecompute_col1_widthr6   r   )rK   r   all_rowsr   r   s        r.   r   z$HelpFormatter.write_aligned_sections   sn    &&I&I&I&I&III,,Xt7JKK
 	9 	9AqZ8888	9 	9r-   r   r   c                    | j         }|                     d           |                     |j        |j                    |j        rd|j         d}| j        t          |j                  z
  t          d          z
  }t          |          |k    r+|                     d|                    |          d           n\|                     d           |                                 5  |                     ||j                   d d d            n# 1 swxY w Y   |                                 5  |j	        r |                     |j	        |j
                   |                     |j        |           d d d            d S # 1 swxY w Y   d S )Nr<   rf   []z: r`   r   )r:   rZ   rm   r!   r$   rV   lenrz   r{   r#   section_helpwrite_dlr"   )rK   r   r   r:   constraint_textrV   s         r.   r   zHelpFormatter.write_section   s   


419!,.>???< 	G1!,111O"2S^^Cc$iiOO?##66

3 0 0 A A4HHHH

4   %%'' G GOOOU5EFFFG G G G G G G G G G G G G G G  	@ 	@v <(:;;;MM!-JM???	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@s%   $DDD+AE<<F F textrt   c                 Z   t          || j        | j        z
  d          }|t          u rt	          j        |d| j        z            }nMt          ||                                          }t          || j                  }d	                    |          }| 
                    |d           d S )NTpreserve_paragraphsr`   )r^   )r4   r<   )r   r4   rT   r   textwrapindentmap
splitlinesr   rn   rZ   )rK   r   rt   wrappedwrapped_textstyled_linesliness          r.   r{   zHelpFormatter.write_text   s    $*t22N N NH#?73AT;TUUULLug&8&8&:&:;;L T5HIIIE99U++L

<&&&&&r-   rowsc                 Z    d |D             }fd|D             }t          |d          S )Nc              3   @   K   | ]}t          |d                    V  dS )r   Nr   )rj   rs     r.   rl   z3HelpFormatter.compute_col1_width.<locals>.<genexpr>   s.      99qQqT**999999r-   c              3   (   K   | ]}|k    |V  d S rS   r,   )rj   lengthr5   s     r.   rl   z3HelpFormatter.compute_col1_width.<locals>.<genexpr>   s-      XX&FiDWDWvDWDWDWDWXXr-   r   )default)max)rK   r   r5   col1_lengthslengths_under_limits     `  r.   r   z HelpFormatter.compute_col1_width   sD    99D999XXXXLXXX&2222r-   col_maxc                 *   t          |p| j        | j                  }t          |p|                     ||          |          }|p| j        }| j        |z
  |z
  }|| j        k     r|                     |           dS |                     ||||           dS )a  Write a definition list into the buffer. This is how options
        and commands are usually formatted.

        If there's enough space, definition lists are rendered as a 2-column
        pseudo-table: if the first column text of a row doesn't fit in the
        provided/computed ``col1_width``, the 2nd column is printed on the
        following line.

        If the available space for the 2nd column is below ``self.col2_min_width``,
        the 2nd "column" is always printed below the 1st, indented with a minimum
        of 3 spaces (or one ``indent_increment`` if that's greater than 3).

        :param rows:
            a list of two item tuples for the terms and values.
        :param col_max:
            the maximum width for the 1st column of a definition list; this
            argument is here to not break compatibility with Click; if provided,
            it overrides the attribute ``self.col1_max_width``.
        :param col_spacing:
            number of spaces between the first and second column;
            this argument is here to not break compatibility with Click;
            if provided, it overrides ``self.col_spacing``.
        :param col1_width:
            the width to use for the first column; if not provided, it's
            computed as the length of the longest string under ``self.col1_max_width``;
            useful when you need to align multiple definition lists.
        N)rE   r6   rV   r   r8   r7   write_linear_dlwrite_tabular_dl)rK   r   r   r8   r   r6   
col2_widths          r.   r   zHelpFormatter.write_dl   s    J *t* 
 
 G$11$GG
 

 "5T%5)J6D
+++  &&&&&!!$
KLLLLLr-   	text_rows
col_widthsc                 0   | j         t          | j         t                    r| j         S ddlm} t          | j         |          r|                      |||          S t          | j                   r|                      | j                  S t          d          )Nr   )r   r9   )r9   r?   r)   sepr   callablerV   	TypeError)rK   r   r   r8   r   s        r.   _get_row_sep_forzHelpFormatter._get_row_sep_for3  s    
 <:dlC#@#@<%%%%%%dlL11 	'<<	:{CCCdl## 	'<< 4555I&&&r-   r   c           	         	
 |z   	d j         t           j        	          z   z  d j         z  t          t	          |                    }                     |f|          } j        j         j        j        c
dt          t          t          f         ddf	
 fd} ||d                    |dd         D ]&}|                     |d            ||           'dS )	a  Format a definition list as a 2-column "pseudo-table". If the first
        column of a row exceeds ``col1_width``, the 2nd column is written on
        the subsequent line. This is the standard way of formatting definition
        lists and it's the default if there's enough space.r`   rowrN   Nc                 `   | \  }}                      	|                     |s                     d           d S t          |          }|
k    r|z
  }                     d|z             n                     d           t          |          k    r!                      |          d           d S t          |d          }fd|                                D             }                     |d         d           |dd          D ]}                     |d           d S )Nr<   r`   Tr   c                 &    g | ]} |          S r,   r,   )rj   linecol2_stylers     r.   
<listcomp>zEHelpFormatter.write_tabular_dl.<locals>.write_row.<locals>.<listcomp>h  s#    UUU4[[..UUUr-   r   r   )rZ   r   r   r   r   )r   firstsecondfirst_display_lengthspaces_to_col2r   r   r   col1_plus_spacingcol1_stylerr   col2_indentationr   r   rz   rK   s           r.   	write_rowz1HelpFormatter.write_tabular_dl.<locals>.write_rowW  sd   ME6JJ{KK$6$6777 A

4     '3E':':$':55%69M%MNJJs^34444JJt%5666v;;*,,JJ{{622D99999#,VZUY#Z#Z#ZLUUUU<;R;R;T;TUUUEJJuQx... %abb	 A A

#3T4@@@@A Ar-   r   r   r<   )rT   r   r3   list	iter_defsr   r:   ri   col2r   r)   rZ   )rK   r   r   r8   r   r   r9   r   r   r   r   r   r   rz   s   ` ` `    @@@@@r.   r   zHelpFormatter.write_tabular_dlC  s[    '4#d&;=N"O"OO
 D// 44455	''	J
3K[YY#':?DJO [	A5c? 	At 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A, 		)A,QRR= 	 	C"

;666IcNNNN	 	r-   r   c                    t          d| j                  }| j        |z   }| j        |z
  }d| j        z  }| j        j        }| j        j        }t          ||          D ]v\  }}	|                     | ||          z   dz              |	r6| xj        |z  c_        | 	                    |	|           | xj        |z  c_        |                     d           w| j
                                         dS )zFormat a definition list as a "linear list". This is the default when
        the available width for the definitions (2nd column) is below
        ``self.col2_min_width``.   r`   r<   N)r   r3   rT   r4   r:   ri   r   r   rZ   r{   rY   pop)
rK   r   help_extra_indenthelp_total_indenthelp_max_widthcurrent_indentationr   r   namesr#   s
             r.   r   zHelpFormatter.write_linear_dls  s
     4#899 /2CC&77!D$77jojo$R88 	 	KE4JJ*[[-?-??$FGGG 9##'88##k222##'88##JJtr-   epilogc                 F    |                      || j        j                   d S rS   )r{   r:   r   )rK   r   s     r.   write_epilogzHelpFormatter.write_epilog  s!    
 122222r-   c                 R    t          | | j        | j        | j        | j                  S )N)r4   r3   r6   r8   )r   r4   r3   r6   r8   rU   s    r.   __repr__zHelpFormatter.__repr__  s0    
T5J.D<L
 
 
 	
r-   )r[   N)TrS   )NNN),r%   r&   r'   r(   r   intr	   r   r)   rJ   staticmethodr   r   r   r   rQ   propertyrV   rZ   rb   r
   rp   rB   Commandr~   boolrm   r    r   r   r   r   r   r{   r   r+   r   r   r   r   r   r   r   __classcell__)rL   s   @r.   r0   r0   0   s       7 7t '(##'  DH$9;;# # ##}# C=# 	#
 # # tS..@A# # # # # # #J ,3-4*1(/(/%,NU%,* * *8C=)*HSM** #3-* !	*
 !* c]* %c>> IJK* 	"* 
c3h* * * \*& 0 0 0 0 X0c d     BF0 00"019#0	0 0 0 0 0 0'Xc] 't ' ' ' '
J5= JT J J J J S 4 4     " " -"" 
" " " "9x/D 9 9 9 9 9@ @{ @ @QU @ @ @ @& 5= 	' 	's 	'6 	' 	' 	' 	' 	'3x
'; 3 3PS 3 3 3 3 "&%)$(	3M 3MZ(3M#3M c]3M SM	3M
 
3M 3M 3M 3Mj'!(3-0'SM' ' 
#	' ' ' ' .Z(..&).7:. 
. . . .`(:"6 4    *33 34 3 3 3 3
# 
 
 
 
 
 
 
 
r-   r0   r   r   rN   c              #   ,  K   | D ]}t          |          dk    r|d         dfV  "t          |          dk    r;t          |d                   r |d         |          n|d         }|d         |fV  pt          dt          |                     d S )Nr   r   r[   r   zinvalid row length: )r   r   rA   )r   r   r   r   s       r.   r   r     s       @ @s88q==a&"*XX]]+3CF+;+;GVSVJ'''QFa&&.    >CHH>>???@ @r-   )-dataclassesdcru   rF   r   	itertoolsr   typingr   r   r   r   r   r	   r
   r   r   r   cloup._utilr   cloup.formatting._utilr   r   r   r   rB   click.formattingr   r   r   r   r   r   r   r   cloup.stylingr   r   r)   r   r+   	dataclassr    r0   r   r,   r-   r.   <module>r      st                                      
 - , , , , , / / / / / / 0////////  & & & & & &              ' & & & & & & & + + + + + + + +3c8SE3J#77889
 : : : : : : : :"_
 _
 _
 _
 _
E' _
 _
 _
D@HZ( @c @huSRUX>W @ @ @ @ @ @r-   