U
    ;»{j§œ  ã                	   @   s  d dl mZmZmZ d dlmZmZmZmZm	Z	m
Z
mZmZmZ ddlmZmZ ddlmZmZ ddlmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZ ddlm Z m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z'm(Z( ddl)m*Z*m+Z+ e�rddl,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 eG dd„ dƒƒZ3eG dd„ dƒƒZ4G dd„ de	ƒZ5G dd„ deƒZ6e7dk�rd dl8m-Z- d dl9m:Z: d dl;m6Z6 ddl<m=Z= e=dƒ��~ e6dd d!d"�Z>e>j?d#d$d%d&d'� e>j?d(d)d*� e>j?d+d!d,d-� e> @d.d/d0¡ e> @d1d2d3¡ e>j@d4d5d6d7d&d8� e> @d9d:d;¡ eAd<d=œd>d?„ZBe-ƒ Z,e:ƒ ZCeBd@ƒ e,jDe>dAdB� d&e>_EeBdCƒ e, De>¡ dDe>_FeBdEƒ e,jDe>dAdB� d<e>_FdFe>_EdGdHge>_GeBdIƒ e,jDe>dAdB� d<e>_FdFe>_EdGdHge>_Gde>_HeBdJƒ e,jDe>dAdB� d<e>_FdFe>_EdGdHge>_Gd&e>_Id e>_HeBdKƒ e,jDe>dAdB� W 5 Q R X d<S )Lé    )Ú	dataclassÚfieldÚreplace)	ÚTYPE_CHECKINGÚDictÚIterableÚListÚ
NamedTupleÚOptionalÚSequenceÚTupleÚUnioné   )ÚboxÚerrors)Úloop_first_lastÚ	loop_last)Ú	pick_bool)Úratio_distributeÚratio_reduce)ÚVerticalAlignMethod)ÚJupyterMixin)ÚMeasurement)ÚPaddingÚPaddingDimensions)Úis_renderable)ÚSegment)ÚStyleÚ	StyleType)ÚTextÚTextType)ÚConsoleÚConsoleOptionsÚJustifyMethodÚOverflowMethodÚRenderableTypeÚRenderResultc                   @   s"  e Zd ZU dZdZded< dZded< dZeed< dZ	eed< dZ
eed< d	Zd
ed< dZded< dZded< dZee ed< dZee ed< dZee ed< dZee ed< dZeed< dZeed< dZeed< eed�Zed ed< d dœdd „Zeed dœd!d"„ƒZeedœd#d$„ƒZ dS )%ÚColumna¥
  Defines a column within a ~Table.

    Args:
        title (Union[str, Text], optional): The title of the table rendered at the top. Defaults to None.
        caption (Union[str, Text], optional): The table caption rendered below. Defaults to None.
        width (int, optional): The width in characters of the table, or ``None`` to automatically fit. Defaults to None.
        min_width (Optional[int], optional): The minimum width of the table, or ``None`` for no minimum. Defaults to None.
        box (box.Box, optional): One of the constants in box.py used to draw the edges (see :ref:`appendix_box`), or ``None`` for no box lines. Defaults to box.HEAVY_HEAD.
        safe_box (Optional[bool], optional): Disable box characters that don't display on windows legacy terminal with *raster* fonts. Defaults to True.
        padding (PaddingDimensions, optional): Padding for cells (top, right, bottom, left). Defaults to (0, 1).
        collapse_padding (bool, optional): Enable collapsing of padding around cells. Defaults to False.
        pad_edge (bool, optional): Enable padding of edge cells. Defaults to True.
        expand (bool, optional): Expand the table to fit the available space if ``True``, otherwise the table width will be auto-calculated. Defaults to False.
        show_header (bool, optional): Show a header row. Defaults to True.
        show_footer (bool, optional): Show a footer row. Defaults to False.
        show_edge (bool, optional): Draw a box around the outside of the table. Defaults to True.
        show_lines (bool, optional): Draw lines between every row. Defaults to False.
        leading (int, optional): Number of blank lines between rows (precludes ``show_lines``). Defaults to 0.
        style (Union[str, Style], optional): Default style for the table. Defaults to "none".
        row_styles (List[Union, str], optional): Optional list of row styles, if more than one style is given then the styles will alternate. Defaults to None.
        header_style (Union[str, Style], optional): Style of the header. Defaults to "table.header".
        footer_style (Union[str, Style], optional): Style of the footer. Defaults to "table.footer".
        border_style (Union[str, Style], optional): Style of the border. Defaults to None.
        title_style (Union[str, Style], optional): Style of the title. Defaults to None.
        caption_style (Union[str, Style], optional): Style of the caption. Defaults to None.
        title_justify (str, optional): Justify method for title. Defaults to "center".
        caption_justify (str, optional): Justify method for caption. Defaults to "center".
        highlight (bool, optional): Highlight cell contents (if str). Defaults to False.
    Ú r%   ÚheaderÚfooterÚheader_styleÚfooter_styleÚstyleÚleftr#   ÚjustifyÚtopr   ÚverticalÚellipsisr$   ÚoverflowNÚwidthÚ	min_widthÚ	max_widthÚratioFÚno_wrapÚ	highlightr   Ú_index)Údefault_factoryÚ_cells©Úreturnc                 C   s   t | g d�S )zReturn a copy of this Column.©r<   )r   ©Úself© rB   ú7/tmp/pip-install-zsn1f9xv/pip/pip/_vendor/rich/table.pyÚcopyu   s    zColumn.copyc                 c   s   | j E dH  dS )z2Get all cells in the column, not including header.Nr?   r@   rB   rB   rC   Úcellsy   s    zColumn.cellsc                 C   s
   | j dk	S )z!Check if this column is flexible.N)r7   r@   rB   rB   rC   Úflexible~   s    zColumn.flexible)!Ú__name__Ú
__module__Ú__qualname__Ú__doc__r)   Ú__annotations__r*   r+   r   r,   r-   r/   r1   r3   r4   r
   Úintr5   r6   r7   r8   Úboolr9   r:   r   Úlistr<   r   rD   Úpropertyr   rE   rF   rB   rB   rB   rC   r'   &   s,   
r'   c                   @   s.   e Zd ZU dZdZee ed< dZe	ed< dS )ÚRowzInformation regarding a row.Nr-   FÚend_section)
rG   rH   rI   rJ   r-   r
   r   rK   rQ   rM   rB   rB   rB   rC   rP   „   s   
rP   c                   @   s*   e Zd ZU dZeed< ded< eed< dS )Ú_CellzA single cell in a table.r-   r%   Ú
renderabler1   N)rG   rH   rI   rJ   r   rK   r   rB   rB   rB   rC   rR   �   s
   
rR   c                   @   sð  e Zd ZU dZee ed< ee ed< ddddej	ddddddddddd	dd
ddddddddœe
eef ee ee ee ee eej ee eeeeeeeeeeeee  ee ee ee ee ee ddeddœdd„Zedddddœe
eef eeeed dœdd„ƒZeedœdd„ƒZejeddœdd„ƒZeedœdd„ƒZeedœdd„ƒZdeed œd!d"„Zdd#ed$œd%d&„Zeeeeeef dœd'd(„ƒZ e jed d)œd*d(„ƒZ dPddddd,d-d.dddddd/œd0d0ee ee ee ee dd1d2ee ee ee ee edd3œd4d5„Z!ddd6œed0 ee edd7œd8d9„Z"ddœd:d;„Z#dd#d<d$œd=d>„Z$dd#ee d$œd?d@„Z%eee ee eee dAœdBdC„ƒZ&deeee' dDœdEdF„Z(eedGœdHdI„Z)dd#eedJœdKdL„Z*dd#ee d<dMœdNdO„Z+dS )QÚTablea  A console renderable to draw a table.

    Args:
        *headers (Union[Column, str]): Column headers, either as a string, or :class:`~rich.table.Column` instance.
        title (Union[str, Text], optional): The title of the table rendered at the top. Defaults to None.
        caption (Union[str, Text], optional): The table caption rendered below. Defaults to None.
        width (int, optional): The width in characters of the table, or ``None`` to automatically fit. Defaults to None.
        min_width (Optional[int], optional): The minimum width of the table, or ``None`` for no minimum. Defaults to None.
        box (box.Box, optional): One of the constants in box.py used to draw the edges (see :ref:`appendix_box`), or ``None`` for no box lines. Defaults to box.HEAVY_HEAD.
        safe_box (Optional[bool], optional): Disable box characters that don't display on windows legacy terminal with *raster* fonts. Defaults to True.
        padding (PaddingDimensions, optional): Padding for cells (top, right, bottom, left). Defaults to (0, 1).
        collapse_padding (bool, optional): Enable collapsing of padding around cells. Defaults to False.
        pad_edge (bool, optional): Enable padding of edge cells. Defaults to True.
        expand (bool, optional): Expand the table to fit the available space if ``True``, otherwise the table width will be auto-calculated. Defaults to False.
        show_header (bool, optional): Show a header row. Defaults to True.
        show_footer (bool, optional): Show a footer row. Defaults to False.
        show_edge (bool, optional): Draw a box around the outside of the table. Defaults to True.
        show_lines (bool, optional): Draw lines between every row. Defaults to False.
        leading (int, optional): Number of blank lines between rows (precludes ``show_lines``). Defaults to 0.
        style (Union[str, Style], optional): Default style for the table. Defaults to "none".
        row_styles (List[Union, str], optional): Optional list of row styles, if more than one style is given then the styles will alternate. Defaults to None.
        header_style (Union[str, Style], optional): Style of the header. Defaults to "table.header".
        footer_style (Union[str, Style], optional): Style of the footer. Defaults to "table.footer".
        border_style (Union[str, Style], optional): Style of the border. Defaults to None.
        title_style (Union[str, Style], optional): Style of the title. Defaults to None.
        caption_style (Union[str, Style], optional): Style of the caption. Defaults to None.
        title_justify (str, optional): Justify method for title. Defaults to "center".
        caption_justify (str, optional): Justify method for caption. Defaults to "center".
        highlight (bool, optional): Highlight cell contents (if str). Defaults to False.
    ÚcolumnsÚrowsN)r   r   FTr   Únoneztable.headerztable.footerÚcenter)ÚtitleÚcaptionr4   r5   r   Úsafe_boxÚpaddingÚcollapse_paddingÚpad_edgeÚexpandÚshow_headerÚshow_footerÚ	show_edgeÚ
show_linesÚleadingr-   Ú
row_stylesr+   r,   Úborder_styleÚtitle_styleÚcaption_styleÚtitle_justifyÚcaption_justifyr9   r#   )ÚheadersrY   rZ   r4   r5   r   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   r-   re   r+   r,   rf   rg   rh   ri   rj   r9   r>   c                G   sú   g | _ g | _|| _|| _|| _|| _|| _|| _t 	|¡| _
|	| _|
| _|| _|| _|| _|| _|| _|| _|| _|pxd| _|p‚d| _|| _|| _|| _|| _|| _|| _t|p²g ƒ| _| j j}|D ]0}t|t ƒrà| j!|d� qÄt"| j ƒ|_#||ƒ qÄd S )Nr(   )r)   )$rU   rV   rY   rZ   r4   r5   r   r[   r   ÚunpackÚ_paddingr^   Ú_expandr`   ra   rb   rc   rd   r]   r-   r+   r,   rf   rg   rh   ri   rj   r9   rN   re   ÚappendÚ
isinstanceÚstrÚ
add_columnÚlenr:   )rA   rY   rZ   r4   r5   r   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   r-   re   r+   r,   rf   rg   rh   ri   rj   r9   rk   Zappend_columnr)   rB   rB   rC   Ú__init__½   sB    


zTable.__init__)r\   r]   r^   r_   )rk   r\   r]   r^   r_   r>   c                G   s   | |d||ddd||dœŽS )aÁ  Get a table with no lines, headers, or footer.

        Args:
            *headers (Union[Column, str]): Column headers, either as a string, or :class:`~rich.table.Column` instance.
            padding (PaddingDimensions, optional): Get padding around cells. Defaults to 0.
            collapse_padding (bool, optional): Enable collapsing of padding around cells. Defaults to True.
            pad_edge (bool, optional): Enable padding around edges of table. Defaults to False.
            expand (bool, optional): Expand the table to fit the available space if ``True``, otherwise the table width will be auto-calculated. Defaults to False.

        Returns:
            Table: A table instance.
        NF)r   r\   r]   r`   ra   rb   r^   r_   rB   )Úclsr\   r]   r^   r_   rk   rB   rB   rC   Úgridý   s    ÷z
Table.gridr=   c                 C   s   | j p| jdk	S )z-Setting a non-None self.width implies expand.N)rn   r4   r@   rB   rB   rC   r_     s    zTable.expand)r_   r>   c                 C   s
   || _ dS )zSet expand.N)rn   )rA   r_   rB   rB   rC   r_   #  s    c                 C   s4   d}| j r| jr|d7 }| j r0|t| jƒd 7 }|S )z'Get extra width to add to cell content.r   é   r   )r   rb   rs   rU   )rA   r4   rB   rB   rC   Ú_extra_width(  s    zTable._extra_widthc                 C   s
   t | jƒS )zGet the current number of rows.)rs   rV   r@   rB   rB   rC   Ú	row_count2  s    zTable.row_countr!   )ÚconsoleÚindexr>   c                 C   sR   t  ¡ }| jr,|| | j|t| jƒ  ¡7 }| j| j}|dk	rN|| |¡7 }|S )zGet the current row style.N)r   Únullre   Ú	get_stylers   rV   r-   )rA   rz   r{   r-   Ú	row_stylerB   rB   rC   Úget_row_style7  s    zTable.get_row_styler"   )rz   Úoptionsr>   c                    s¾   ˆj ‰| jd k	r| j‰ˆdk r(tddƒS | j}t|  ˆˆ ˆ| ¡¡ƒ‰| j‰ ‡ ‡‡‡fdd„| jD ƒ}tdd„ |D ƒƒ| }| jd kržtdd„ |D ƒƒ| n| j}t||ƒ}| 	| j
¡}|S )Nr   c                    s   g | ]}ˆ ˆˆ  ˆ¡|ƒ‘qS rB   )Úupdate_width©Ú.0Úcolumn©Ú_measure_columnrz   r6   r€   rB   rC   Ú
<listcomp>R  s   ÿz*Table.__rich_measure__.<locals>.<listcomp>c                 s   s   | ]}|j V  qd S ©N)Zminimum©rƒ   ÚmeasurementrB   rB   rC   Ú	<genexpr>W  s     z)Table.__rich_measure__.<locals>.<genexpr>c                 s   s   | ]}|j V  qd S rˆ   ©Úmaximumr‰   rB   rB   rC   r‹   Z  s     )r6   r4   r   rx   ÚsumÚ_calculate_column_widthsr�   r†   rU   Úclampr5   )rA   rz   r€   Úextra_widthZmeasurementsZminimum_widthZmaximum_widthrŠ   rB   r…   rC   Ú__rich_measure__A  s2    

 ÿÿþÿÿý
zTable.__rich_measure__c                 C   s   | j S )zGet cell padding.)rm   r@   rB   rB   rC   r\   b  s    zTable.padding)r\   r>   c                 C   s   t  |¡| _| S )zSet cell padding.)r   rl   rm   )rA   r\   rB   rB   rC   r\   g  s    r(   r.   r0   r2   )r+   r9   r,   r-   r/   r1   r3   r4   r5   r6   r7   r8   r%   r   r$   )r)   r*   r+   r9   r,   r-   r/   r1   r3   r4   r5   r6   r7   r8   r>   c                C   sV   t t| jƒ|||pd|dk	r |n| j|p*d|p0d|||	|
||||d�}| j |¡ dS )a…  Add a column to the table.

        Args:
            header (RenderableType, optional): Text or renderable for the header.
                Defaults to "".
            footer (RenderableType, optional): Text or renderable for the footer.
                Defaults to "".
            header_style (Union[str, Style], optional): Style for the header, or None for default. Defaults to None.
            highlight (bool, optional): Whether to highlight the text. The default of None uses the value of the table (self) object.
            footer_style (Union[str, Style], optional): Style for the footer, or None for default. Defaults to None.
            style (Union[str, Style], optional): Style for the column cells, or None for default. Defaults to None.
            justify (JustifyMethod, optional): Alignment for cells. Defaults to "left".
            vertical (VerticalAlignMethod, optional): Vertical alignment, one of "top", "middle", or "bottom". Defaults to "top".
            overflow (OverflowMethod): Overflow method: "crop", "fold", "ellipsis". Defaults to "ellipsis".
            width (int, optional): Desired width of column in characters, or None to fit to contents. Defaults to None.
            min_width (Optional[int], optional): Minimum width of column, or ``None`` for no minimum. Defaults to None.
            max_width (Optional[int], optional): Maximum width of column, or ``None`` for no maximum. Defaults to None.
            ratio (int, optional): Flexible ratio for the column (requires ``Table.expand`` or ``Table.width``). Defaults to None.
            no_wrap (bool, optional): Set to ``True`` to disable wrapping of this column.
        r(   N)r:   r)   r*   r+   r9   r,   r-   r/   r1   r3   r4   r5   r6   r7   r8   )r'   rs   rU   r9   ro   )rA   r)   r*   r+   r9   r,   r-   r/   r1   r3   r4   r5   r6   r7   r8   r„   rB   rB   rC   rr   m  s$    'ñzTable.add_column©r-   rQ   )Úrenderablesr-   rQ   r>   c                G   sþ   t dddœdd„}t|ƒ}| j}t|ƒt|ƒk rJ|dgt|ƒt|ƒ  •}t|ƒD ]’\}}|t|ƒkrœt || jd�}	| jD ]}
||	tdƒƒ qz| j |	¡ n|| }	|dkr¸||	dƒ qRt	|ƒrÌ||	|ƒ qRt
 dt|ƒj› d	�¡‚qR| j t||d
�¡ dS )aø  Add a row of renderables.

        Args:
            *renderables (None or renderable): Each cell in a row must be a renderable object (including str),
                or ``None`` for a blank cell.
            style (StyleType, optional): An optional style to apply to the entire row. Defaults to None.
            end_section (bool, optional): End a section and draw a line. Defaults to False.

        Raises:
            errors.NotRenderableError: If you add something that can't be rendered.
        r%   N)r„   rS   r>   c                 S   s   | j  |¡ d S rˆ   )r<   ro   )r„   rS   rB   rB   rC   Úadd_cell¹  s    zTable.add_row.<locals>.add_cell)r:   r9   r(   zunable to render z1; a string or other renderable object is requiredr“   )r'   rN   rU   rs   Ú	enumerater9   rV   r   ro   r   r   ZNotRenderableErrorÚtyperG   rP   )rA   r-   rQ   r”   r•   Zcell_renderablesrU   r{   rS   r„   Ú_rB   rB   rC   Úadd_row§  s,    þ
ÿzTable.add_rowc                 C   s   | j rd| j d _dS )z2Add a new section (draw a line after current row).TéÿÿÿÿN)rV   rQ   r@   rB   rB   rC   Úadd_sectionÖ  s    zTable.add_sectionr&   c                 #   sè   | j stdƒV  d S |j}| jd k	r*| j}| j}|  ˆ | || ¡¡}t|ƒ| }|j|| j	d d�‰dt
tdddœ‡ ‡fdd„}| jr¨|| jt | jd	¡| jd
�E d H  |  ˆ ˆ|¡E d H  | jrä|| jt | jd¡| jd
�E d H  d S )NÚ
)r4   r9   ÚheightrX   r#   r&   )Útextr-   r/   r>   c                    s4   t | tƒrˆ j| |dd�n| }ˆ j|ˆj|d�d�S )NF)r-   r9   ©r/   )r€   )rp   rq   Z
render_strÚrenderÚupdate)rž   r-   r/   Zrender_text©rz   Úrender_optionsrB   rC   Úrender_annotationñ  s    ÿý 
ÿz1Table.__rich_console__.<locals>.render_annotationztable.title)r-   r/   ztable.caption)rX   )rU   r   r6   r4   rx   r�   r�   rŽ   r¡   r9   r    r   rY   r   Z
pick_firstrg   ri   Ú_renderrZ   rh   rj   )rA   rz   r€   r6   r‘   ÚwidthsÚtable_widthr¤   rB   r¢   rC   Ú__rich_console__Ü  sJ    

 ÿ  ÿ ÿ  þýýzTable.__rich_console__c                    sÌ  ˆj }ˆj}‡ ‡‡fdd„|D ƒ}dd„ |D ƒ}ˆj‰ˆj}ˆjrÊdd„ |D ƒ}t|ƒrÊdd„ t||ƒD ƒ}	‡fdd„|D ƒ}
|t|	ƒ }t|||
ƒ}t	|ƒ}t
|ƒD ]"\}}|jr¦|	| t|ƒ ||< q¦t|ƒ}||k�rXˆ |dd„ |D ƒ|¡}t|ƒ}||k�r.|| }t|dgt|ƒ ||ƒ}t|ƒ}‡ ‡‡fd	d„t||ƒD ƒ}d
d„ |D ƒ}||k �rjˆj�s†ˆjdk	�rÈ|ˆj| k �rÈˆjdk�r–|ntˆj| |ƒ}t|| |ƒ}dd„ t||ƒD ƒ}|S )zNCalculate the widths of each column, including padding, not including borders.c                    s   g | ]}ˆ  ˆ ˆ|¡‘qS rB   )r†   r‚   ©rz   r€   rA   rB   rC   r‡     s    z2Table._calculate_column_widths.<locals>.<listcomp>c                 S   s   g | ]}|j pd ‘qS ©r   rŒ   ©rƒ   Ú_rangerB   rB   rC   r‡     s     c                 S   s   g | ]}|j r|jpd ‘qS ©r   )rF   r7   )rƒ   ÚcolrB   rB   rC   r‡     s      c                 S   s    g | ]\}}|j rd n|j‘qS r­   )rF   r�   )rƒ   r¬   r„   rB   rB   rC   r‡     s   ÿc                    s&   g | ]}|j r|jpd ˆ |jƒ ‘qS rª   )rF   r4   r:   r‚   )Úget_padding_widthrB   rC   r‡     s   þc                 S   s   g | ]}|j d ko|j ‘qS rˆ   )r4   r8   r‚   rB   rB   rC   r‡   .  s     r   c                    s$   g | ]\}}ˆ  ˆ ˆ |¡|¡‘qS rB   )r†   r�   )rƒ   r4   r„   r©   rB   rC   r‡   8  s   ÿc                 S   s   g | ]}|j pd ‘qS r­   rŒ   r«   rB   rB   rC   r‡   <  s     Nc                 S   s   g | ]\}}|| ‘qS rB   rB   )rƒ   Ú_widthÚpadrB   rB   rC   r‡   G  s     )r6   rU   Ú_get_padding_widthrx   r_   ÚanyÚziprŽ   r   Úiterr–   rF   ÚnextÚ_collapse_widthsr   rs   r5   Úmin)rA   rz   r€   r6   rU   Zwidth_rangesr¦   r‘   ÚratiosZfixed_widthsZflex_minimumZflexible_widthZflex_widthsZiter_flex_widthsr{   r„   r§   Úexcess_widthZ
_max_widthZ
pad_widthsrB   )rz   r¯   r€   rA   rC   r�     sf    ÿþ
þ
ý
þÿÿÿýzTable._calculate_column_widths)r¦   Úwrapabler6   r>   c           
         s¾   t |ƒ}|| }t|ƒrº|rº|dkrºtdd„ t||ƒD ƒƒ‰ t‡ fdd„t||ƒD ƒƒ}ˆ | }‡ fdd„t||ƒD ƒ}t|ƒrº|s†qºt||ƒgt|ƒ }	t|||	|ƒ}t |ƒ}|| }q|S )aM  Reduce widths so that the total is under max_width.

        Args:
            widths (List[int]): List of widths.
            wrapable (List[bool]): List of booleans that indicate if a column may shrink.
            max_width (int): Maximum width to reduce to.

        Returns:
            List[int]: A new list of widths.
        r   c                 s   s   | ]\}}|r|V  qd S rˆ   rB   ©rƒ   r4   Z
allow_wraprB   rB   rC   r‹   ]  s     z)Table._collapse_widths.<locals>.<genexpr>c                 3   s&   | ]\}}|r|ˆ kr|nd V  qdS )r   NrB   r¼   ©Z
max_columnrB   rC   r‹   `  s   ÿc                    s$   g | ]\}}|ˆ kr|rd nd‘qS )r   r   rB   r¼   r½   rB   rC   r‡   e  s   ÿz*Table._collapse_widths.<locals>.<listcomp>)rŽ   r³   Úmaxr´   r¸   rs   r   )
ru   r¦   r»   r6   Ztotal_widthrº   Zsecond_max_columnZcolumn_differencer¹   Z
max_reducerB   r½   rC   r·   K  s*    ÿþ
þ
zTable._collapse_widths)rz   Úcolumn_indexr„   r>   c                 #   st  | j ‰| j‰| j‰tˆƒ}|dk‰|t| jƒd k‰i ‰ tttttttf dœ‡ ‡‡‡‡‡fdd„}g }|j	}|j
}| jr || jp„dƒ||jƒ }	||	|jfƒ ||jpªdƒ}
|jD ]}||
|fƒ q´| jrò|| jpÖdƒ||jƒ }|||jfƒ |�rBt}t|ƒD ]:\}}\}}t||||||ƒƒt|ddƒ�p6|jƒV  �qn.|D ](\}}t||t|ddƒ�pf|jƒV  �qFdS )	z3Get all the cells with padding and optional header.r   r   )Ú	first_rowÚlast_rowr>   c                    sŠ   ˆ   | |f¡}|r|S ˆ\}}}}ˆrJˆs8td|| ƒ}|sJtd|| ƒ}ˆsnˆrVd}ˆr^d}| rfd}|rnd}||||f}|ˆ | |f< |S )Nr   )Úgetr¾   )rÀ   rÁ   Úcachedr0   ÚrightÚbottomr.   rm   ©Z_padding_cacher]   Zfirst_columnZlast_columnr^   r\   rB   rC   Úget_padding�  s*    z%Table._get_cells.<locals>.get_paddingr(   r1   N)r]   r^   r\   r³   rs   rU   rM   r   rL   ro   r}   r`   r+   r)   r-   rE   ra   r,   r*   r   r   rR   Úgetattrr1   )rA   rz   r¿   r„   Zany_paddingrÇ   Z	raw_cellsÚ_appendr}   r+   Z
cell_styleÚcellr,   Z_PaddingÚfirstÚlastr-   rS   rB   rÆ   rC   Ú
_get_cellsr  sL    ,ÿ
ÿýýzTable._get_cells)r¿   r>   c                 C   s2   | j \}}}}| jr*|dkr*td|| ƒ}|| S )zGet extra width from padding.r   )r\   r]   r¾   )rA   r¿   r˜   Z	pad_rightZpad_leftrB   rB   rC   r²   »  s
    zTable._get_padding_width)rz   r€   r„   r>   c                 C   sü   |j }|dk rtddƒS |  |j¡}|jdk	rJt|j| |j| ƒ |¡S g }g }|j}|j}	tj}
|  ||j|¡D ]&}|
|||j	ƒ\}}||ƒ |	|ƒ qtt|rªt
|ƒnd|r¸t
|ƒn|ƒ |¡}| |jdkrÖdn|j| |j dkrìdn|j | ¡}|S )z0Get the minimum and maximum width of the column.r   r   N)r6   r   r²   r:   r4   Zwith_maximumro   rÂ   rÍ   rS   r¾   r�   r5   )rA   rz   r€   r„   r6   Zpadding_widthZ
min_widthsZ
max_widthsZ
append_minZ
append_maxZget_render_widthrÊ   Z_minZ_maxrŠ   rB   rB   rC   r†   Ã  s>    

 ÿþ
þýþzTable._measure_column)rz   r€   r¦   r>   c           %   
   #   s   ˆ  ˆ	jpd¡}|ˆ  ˆ	jpd¡ }‡‡	fdd„tˆ	jƒD ƒ}tt|Ž ƒ}ˆ	jrjˆ	jj|t	ˆ	j
ˆj
ƒd�nd }|r€ˆ	js€| ¡ n|}t ¡ }	ˆ	j}
ˆ	j}ˆ	j}ˆ	j}ˆ	j}ˆ	j}t‰ |�r>ˆ |j|ƒˆ |j|ƒˆ |j|ƒfˆ |j|ƒˆ |j|ƒˆ |j|ƒfˆ |j|ƒˆ |j|ƒˆ |j|ƒfg}|�rBˆ | |¡|ƒV  |	V  ng }ˆ	j}ˆj ‰tt|ƒƒD �]\}\}}}|�or|‰|�o||‰ˆ�s˜ˆ�s˜ˆ	j||  nd }d‰g }ˆ�s°ˆ�rºt  !¡ ‰nˆ|ˆ|�rÎ|d n|ƒƒ‰t|||
ƒD ]^\}}}|j"||j#|j$|j%d |j&d�}ˆj'|j(|ˆ|jƒˆ d�}t)ˆt*|ƒƒ‰| +|¡ �qât)dd„ |D ƒƒ‰t,t,t  d	t-t t,t,t  d
œ‡ ‡‡‡fdd„‰‡ ‡‡‡‡fdd„t||||
ƒD ƒ|d d …< |�r„|�rà|�ràˆ |j.|d|d�|ƒV  |	V  ||�rìdn|�rödnd \}}}|j/ 0¡ �r|nˆ |j/ˆj1|j ƒ} t2ˆƒD ]R}!|�r>|V  t3|ƒD ]$\}"}#|#|! E d H  |"�sF| V  �qF|�rx|V  |	V  �q.n0t2ˆƒD ]&}!|D ]}#|#|! E d H  �q”|	V  �qŒ|�rä|�rä|�räˆ |j.|d|d�|ƒV  |	V  |�oî|j4}$|�rZ|�s|�s|$�rZ|�sZ|�r&|t*|ƒd k�sZ|�r2ˆ�sZ|�rVˆ |j.|d|d�| |ƒV  nˆ |j.|d|d�|ƒV  |	V  �qZ|�rœ|�rœˆ | 5|¡|ƒV  |	V  d S )Nr(   c                 3   s    | ]\}}ˆ  ˆ ||¡V  qd S rˆ   )rÍ   )rƒ   r¿   r„   )rz   rA   rB   rC   r‹   ñ  s   ÿz Table._render.<locals>.<genexpr>)Úsafer   )r4   r/   r8   r3   r�   r9   ©r-   c                 s   s   | ]}t |ƒV  qd S rˆ   )rs   )rƒ   rÊ   rB   rB   rC   r‹   E  s     r   )rÊ   r1   r4   r-   r>   c                    sR   ˆr
d}nˆrd}|dkr*ˆ   | |ˆ|¡S |dkrBˆ  | |ˆ|¡S ˆ  | |ˆ|¡S )NrÅ   r0   Zmiddle)Z	align_topZalign_middleZalign_bottom)rÊ   r1   r4   r-   )Ú_SegmentÚ
footer_rowÚ
header_rowÚ
row_heightrB   rC   Ú
align_cellG  s    z!Table._render.<locals>.align_cellc              
      s8   g | ]0\}}}}ˆ   ˆ||j|ˆ|jƒˆ ƒ|ˆ¡‘qS rB   )Z	set_shaper1   r-   )rƒ   r4   Z_cellrÊ   r„   )rÐ   rÔ   r}   Ú
max_heightr~   rB   rC   r‡   X  s   
öüøz!Table._render.<locals>.<listcomp>Zfoot)Zedger   rw   ÚheadZmidÚrow)6r}   r-   rf   r–   rU   rN   r´   r   Ú
substituter   r[   r`   Zget_plain_headed_boxr   Úlinera   rb   rc   rd   Z	head_leftZ
head_rightZhead_verticalZmid_leftZ	mid_rightZmid_verticalZ	foot_leftZ
foot_rightZfoot_verticalZget_topr   r   rV   r   r|   r¡   r/   r8   r3   r9   Zrender_linesrS   r¾   rs   ro   r   rL   Zget_rowrž   ÚstripZbackground_styleÚranger   rQ   Z
get_bottom)%rA   rz   r€   r¦   Ztable_stylerf   Z_column_cellsZ	row_cellsZ_boxÚnew_linerU   r`   ra   rb   rc   rd   Zbox_segmentsr   r{   rË   rÌ   Zrow_cellr×   rE   r4   rÊ   r„   r£   Úlinesr.   rÄ   Z_dividerÚdividerZline_noZ	last_cellZrendered_cellrQ   rB   )
rÐ   rÔ   rz   rÑ   r}   rÒ   rÕ   rÓ   r~   rA   rC   r¥   ë  s    þý ÿû


ý


ý


ýõ

ÿÿý
ÿúý

ûõ ÿ"ÿ 
ÿý

 ÿÿþþýýþ ÿ
zTable._render)r(   r(   ),rG   rH   rI   rJ   r   r'   rK   rP   r   Z
HEAVY_HEADr   rq   r
   r    rL   ZBoxrM   r   r   r   rt   Úclassmethodrv   rO   r_   Úsetterrx   ry   r   r   r’   r   r\   rr   r™   r›   r¨   r�   r·   rR   rÍ   r²   r†   r¥   rB   rB   rB   rC   rT   š   s<  
å

ä@ú
ù 	 þ!  ýðï=üû/ þ0 þ@  þ'  þI
û)  þrT   Ú__main__)r!   )ÚReprHighlighter)rT   )ÚtimerzTable renderzStar Wars MovieszRich example tablerÄ   )rY   rZ   rj   ZReleasedZbright_cyanZcyanT)r+   r-   r8   ZTitleZmagentarÏ   z
Box OfficeZgreen)r/   r-   zDec 20, 2019z Star Wars: The Rise of Skywalkerz$952,110,690zMay 25, 2018zSolo: A Star Wars Storyz$393,151,347zDec 15, 2017z!Star Wars Ep. V111: The Last Jediz$1,332,539,889zon blackr“   zDec 16, 2016zRogue One: A Star Wars Storyz$1,332,439,889N)rž   r>   c                 C   s"   t  ¡  t  t| ƒ¡ t  ¡  d S rˆ   )rz   ÚprintZruler9   )rž   rB   rB   rC   r)   È  s    r)   zExample TablerX   rŸ   zexpand=Trueé2   zwidth=50FZdimrW   zrow_styles=['dim', 'none']z%leading=1, row_styles=['dim', 'none']z+show_lines=True, row_styles=['dim', 'none'])JZdataclassesr   r   r   Útypingr   r   r   r   r	   r
   r   r   r   r(   r   r   Z_loopr   r   Z_pickr   Z_ratior   r   Zalignr   Zjupyterr   Zmeasurer   r\   r   r   Úprotocolr   Úsegmentr   r-   r   r   rž   r   r    rz   r!   r"   r#   r$   r%   r&   r'   rP   rR   rT   rG   Zpip._vendor.rich.consoleZpip._vendor.rich.highlighterrâ   Zpip._vendor.rich.tableZ_timerrã   Útablerr   r™   rq   r)   r9   rä   r_   r4   re   rd   rc   rB   rB   rB   rC   Ú<module>   sº   , 
]
      
ý   ÿýûý



