U
    ƒIÀd›  ã                	   @   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< 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 (bool, 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_wrapr   Ú_index)Údefault_factoryÚ_cells©Úreturnc                 C   s   t | g d�S )zReturn a copy of this Column.©r;   )r   ©Úself© rA   úO/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/pip/_vendor/rich/table.pyÚcopyr   s    zColumn.copyc                 c   s   | j E dH  dS )z2Get all cells in the column, not including header.Nr>   r?   rA   rA   rB   Úcellsv   s    zColumn.cellsc                 C   s
   | j dk	S )z!Check if this column is flexible.N)r7   r?   rA   rA   rB   Ú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   Úlistr;   r   rC   Úpropertyr   rD   rE   rA   rA   rA   rB   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)
rF   rG   rH   rI   r-   r
   r   rJ   rP   rL   rA   rA   rA   rB   rO   �   s   
rO   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)rF   rG   rH   rI   r   rJ   r   rA   rA   rA   rB   rQ   Œ   s
   
rQ   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/œd0d0e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 (bool, 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_justifyÚ	highlightr#   )ÚheadersrX   rY   r4   r5   r   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   r-   rd   r+   r,   re   rf   rg   rh   ri   rj   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)   )$rT   rU   rX   rY   r4   r5   r   rZ   r   ÚunpackÚ_paddingr]   Ú_expandr_   r`   ra   rb   rc   r\   r-   r+   r,   re   rf   rg   rh   ri   rj   rM   rd   ÚappendÚ
isinstanceÚstrÚ
add_columnÚlenr9   )r@   rX   rY   r4   r5   r   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   r-   rd   r+   r,   re   rf   rg   rh   ri   rj   rk   Úappend_columnr)   rA   rA   rB   Ú__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_   r`   ra   r]   r^   rA   )Úclsr[   r\   r]   r^   rk   rA   rA   rB   Ú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?   rA   rA   rB   r^     s    zTable.expand)r^   r=   c                 C   s
   || _ dS )zSet expand.N)rn   )r@   r^   rA   rA   rB   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   ra   rs   rT   )r@   r4   rA   rA   rB   Ú_extra_width&  s    zTable._extra_widthc                 C   s
   t | jƒS )zGet the current number of rows.)rs   rU   r?   rA   rA   rB   Ú	row_count0  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   Únullrd   Ú	get_stylers   rU   r-   )r@   r{   r|   r-   Ú	row_stylerA   rA   rB   Úget_row_style5  s    zTable.get_row_styler"   )r{   Ú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 rA   )Úupdate_width©Ú.0Úcolumn©Ú_measure_columnr{   r6   r�   rA   rB   Ú
<listcomp>P  s   ÿz*Table.__rich_measure__.<locals>.<listcomp>c                 s   s   | ]}|j V  qd S ©N)Úminimum©r„   ÚmeasurementrA   rA   rB   Ú	<genexpr>U  s     z)Table.__rich_measure__.<locals>.<genexpr>c                 s   s   | ]}|j V  qd S r‰   ©Úmaximumr‹   rA   rA   rB   r�   X  s     )r6   r4   r   ry   ÚsumÚ_calculate_column_widthsr‚   r‡   rT   Úclampr5   )r@   r{   r�   Úextra_widthÚmeasurementsÚminimum_widthÚmaximum_widthrŒ   rA   r†   rB   Ú__rich_measure__?  s2    

 ÿÿþÿÿý
zTable.__rich_measure__c                 C   s   | j S )zGet cell padding.)rm   r?   rA   rA   rB   r[   `  s    zTable.padding)r[   r=   c                 C   s   t  |¡| _| S )zSet cell padding.)r   rl   rm   )r@   r[   rA   rA   rB   r[   e  s    r(   r.   r0   r2   )r+   r,   r-   r/   r1   r3   r4   r5   r6   r7   r8   r%   r   r$   )r)   r*   r+   r,   r-   r/   r1   r3   r4   r5   r6   r7   r8   r=   c                C   sF   t t| jƒ|||pd|pd|p d||||	|
|||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.
            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(   )r9   r)   r*   r+   r,   r-   r/   r1   r3   r4   r5   r6   r7   r8   N)r'   rs   rT   ro   )r@   r)   r*   r+   r,   r-   r/   r1   r3   r4   r5   r6   r7   r8   r…   rA   rA   rB   rr   k  s"    %òzTable.add_column©r-   rP   )Úrenderablesr-   rP   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 |d�}	| jD ]}
||	tdƒƒ qv| 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…   rR   r=   c                 S   s   | j  |¡ d S r‰   )r;   ro   )r…   rR   rA   rA   rB   Úadd_cell´  s    zTable.add_row.<locals>.add_cell)r9   r(   zunable to render z1; a string or other renderable object is requiredr˜   )r'   rM   rT   rs   Ú	enumeraterU   r   ro   r   r   ÚNotRenderableErrorÚtyperF   rO   )r@   r-   rP   r™   rš   Úcell_renderablesrT   r|   rR   r…   Ú_rA   rA   rB   Ú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)rU   rP   r?   rA   rA   rB   Ú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   rj   ÚheightrW   r#   r&   )Útextr-   r/   r=   c                    s4   t | tƒrˆ j| |dd�n| }ˆ j|ˆj|d�d�S )NF)r-   rj   ©r/   )r�   )rp   rq   Ú
render_strÚrenderÚupdate)r¥   r-   r/   Úrender_text©r{   Úrender_optionsrA   rB   Úrender_annotationí  s    ÿý 
ÿz1Table.__rich_console__.<locals>.render_annotationztable.title)r-   r/   ztable.caption)rW   )rT   r   r6   r4   ry   r‘   r‚   r�   r©   rj   r    r   rX   r   Ú
pick_firstrf   rh   Ú_renderrY   rg   ri   )r@   r{   r�   r6   r“   ÚwidthsÚtable_widthr­   rA   r«   rB   Ú__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 rA   )r‡   rƒ   ©r{   r�   r@   rA   rB   rˆ     s    z2Table._calculate_column_widths.<locals>.<listcomp>c                 S   s   g | ]}|j pd ‘qS ©r   rŽ   ©r„   Ú_rangerA   rA   rB   rˆ     s     c                 S   s   g | ]}|j r|jpd ‘qS ©r   )rE   r7   )r„   ÚcolrA   rA   rB   rˆ     s      c                 S   s    g | ]\}}|j rd n|j‘qS r·   )rE   r�   )r„   r¶   r…   rA   rA   rB   rˆ     s   ÿc                    s&   g | ]}|j r|jpd ˆ |jƒ ‘qS r´   )rE   r4   r9   rƒ   )Úget_padding_widthrA   rB   rˆ     s   þc                 S   s   g | ]}|j d ko|j ‘qS r‰   )r4   r8   rƒ   rA   rA   rB   rˆ   *  s     r   c                    s$   g | ]\}}ˆ  ˆ ˆ |¡|¡‘qS rA   )r‡   r‚   )r„   r4   r…   r³   rA   rB   rˆ   4  s   ÿc                 S   s   g | ]}|j pd ‘qS r·   rŽ   rµ   rA   rA   rB   rˆ   8  s     Nc                 S   s   g | ]\}}|| ‘qS rA   rA   )r„   Ú_widthÚpadrA   rA   rB   rˆ   C  s     )r6   rT   Ú_get_padding_widthry   r^   ÚanyÚzipr�   r   Úiterr›   rE   ÚnextÚ_collapse_widthsr   rs   r5   Úmin)r@   r{   r�   r6   rT   Úwidth_rangesr°   r“   ÚratiosÚfixed_widthsÚflex_minimumÚflexible_widthÚflex_widthsÚiter_flex_widthsr|   r…   r±   Úexcess_widthÚ
_max_widthÚ
pad_widthsrA   )r{   r¹   r�   r@   rB   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‰   rA   ©r„   r4   Ú
allow_wraprA   rA   rB   r�   Y  s     z)Table._collapse_widths.<locals>.<genexpr>c                 3   s&   | ]\}}|r|ˆ kr|nd V  qdS )r   NrA   rÎ   ©Ú
max_columnrA   rB   r�   \  s   ÿc                    s$   g | ]\}}|ˆ kr|rd nd‘qS )r   r   rA   rÎ   rÐ   rA   rB   rˆ   a  s   ÿz*Table._collapse_widths.<locals>.<listcomp>)r�   r½   Úmaxr¾   rÂ   rs   r   )
rv   r°   rÍ   r6   Útotal_widthrÊ   Úsecond_max_columnÚcolumn_differencerÄ   Ú
max_reducerA   rÐ   rB   rÁ   G  s*    ÿþ
þ
zTable._collapse_widths)r{   Ú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   ©Ú_padding_cacher\   Úfirst_columnÚlast_columnr]   r[   rA   rB   Úget_padding}  s*    z%Table._get_cells.<locals>.get_paddingr(   r1   N)r\   r]   r[   r½   rs   rT   rL   r   rK   ro   r~   r_   r+   r)   r-   rD   r`   r,   r*   r   r   rQ   Úgetattrr1   )r@   r{   r×   r…   Úany_paddingrâ   Ú	raw_cellsÚ_appendr~   r+   Ú
cell_styleÚcellr,   Ú_PaddingÚfirstÚlastr-   rR   rA   rÞ   rB   Ú
_get_cellsn  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Ò   )r@   r×   rŸ   Ú	pad_rightÚpad_leftrA   rA   rB   r¼   ·  s
    zTable._get_padding_width)r{   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¼   r9   r4   Úwith_maximumro   rÚ   rì   rR   rÒ   r’   r5   )r@   r{   r�   r…   r6   Úpadding_widthÚ
min_widthsÚ
max_widthsÚ
append_minÚ
append_maxÚget_render_widthrè   Ú_minÚ_maxrŒ   rA   rA   rB   r‡   ¿  s>    

 ÿþ
þýþzTable._measure_column)r{   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 ]Z\}}}|j"||j#|j$|j%d 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. /¡ �r|nˆ |j.ˆj0|j ƒ} t1ˆƒD ]R}!|�r:|V  t2|ƒD ]$\}"}#|#|! E d H  |"�sB| V  �qB|�rt|V  |	V  �q*n0t1ˆƒD ]&}!|D ]}#|#|! E d H  �q�|	V  �qˆ|�rà|�rà|�ràˆ |j-|d|d�|ƒV  |	V  |�oê|j3}$|�rZ|�s|�s|$�rZ|�sZ|�r"|t)|ƒd k�sZ|�r.ˆ�sZ|�rRˆ |j-|d|d�| |ƒV  nˆ |j-|d|d�|ƒV  |	V  �qZ|�r˜|�r˜ˆ | 4|¡|ƒV  |	V  d S )Nr(   c                 3   s    | ]\}}ˆ  ˆ ||¡V  qd S r‰   )rì   )r„   r×   r…   )r{   r@   rA   rB   r�   í  s   ÿz Table._render.<locals>.<genexpr>)Úsafer   )r4   r/   r8   r3   r¤   ©r-   c                 s   s   | ]}t |ƒV  qd S r‰   )rs   )r„   rè   rA   rA   rB   r�   @  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   Úmiddle)Ú	align_topÚalign_middleÚalign_bottom)rè   r1   r4   r-   )Ú_SegmentÚ
footer_rowÚ
header_rowÚ
row_heightrA   rB   Ú
align_cellB  s    z!Table._render.<locals>.align_cellc              
      s8   g | ]0\}}}}ˆ   ˆ||j|ˆ|jƒˆ ƒ|ˆ¡‘qS rA   )Ú	set_shaper1   r-   )r„   r4   Ú_cellrè   r…   )rþ   r  r~   Ú
max_heightr   rA   rB   rˆ   S  s   
öüøz!Table._render.<locals>.<listcomp>Úfoot)Úedger   rx   ÚheadÚmidÚrow)5r~   r-   re   r›   rT   rM   r¾   r   Ú
substituter   rZ   r_   Úget_plain_headed_boxr   Úliner`   ra   rb   rc   Ú	head_leftÚ
head_rightÚhead_verticalÚ	foot_leftÚ
foot_rightÚfoot_verticalÚmid_leftÚ	mid_rightÚmid_verticalÚget_topr€   r   rU   r   r}   r©   r/   r8   r3   Úrender_linesrR   rÒ   rs   ro   r   rK   Úget_rowr¥   ÚstripÚbackground_styleÚranger   rP   Ú
get_bottom)%r@   r{   r�   r°   Útable_stylere   Ú_column_cellsÚ	row_cellsÚ_boxÚnew_linerT   r_   r`   ra   rb   rc   Úbox_segmentsr€   r|   rê   rë   Úrow_cellr
  rD   r4   rè   r…   r¬   Úlinesr.   rÜ   Ú_dividerÚdividerÚline_noÚ	last_cellÚrendered_cellrP   rA   )
rþ   r  r{   rÿ   r~   r   r  r  r   r@   rB   r¯   ç  s   þý ÿû


ý


ý


ýõ

ÿÿý
ÿûý

ûõ ÿ"ÿ 
ÿý

 ÿÿþþýýþ ÿ
zTable._render)r(   r(   ),rF   rG   rH   rI   r   r'   rJ   rO   r   Ú
HEAVY_HEADr   rq   r
   r    rK   ÚBoxrL   r   r   r   ru   Úclassmethodrw   rN   r^   Úsetterry   rz   r€   r   r—   r   r[   rr   r    r¢   r²   r‘   rÁ   rQ   rì   r¼   r‡   r¯   rA   rA   rA   rB   rS   —   s8  
å

äAú
ù 	 þ!  ýñð:üû/ þ1 þ@  þ'  þI
û)  þrS   Ú__main__)r!   )ÚReprHighlighter)rS   )ÚtimerzTable renderzStar Wars MovieszRich example tablerÜ   )rX   rY   ri   ZReleasedÚbright_cyanÚcyanT)r+   r-   r8   ZTitleÚmagentarù   z
Box OfficeÚ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‰   )r{   ÚprintÚrulerj   )r¥   rA   rA   rB   r)   Ã  s    r)   zExample TablerW   r¦   zexpand=Trueé2   zwidth=50FÚdimrV   zrow_styles=['dim', 'none']z%leading=1, row_styles=['dim', 'none']z+show_lines=True, row_styles=['dim', 'none'])JÚdataclassesr   r   r   Útypingr   r   r   r   r	   r
   r   r   r   r(   r   r   Ú_loopr   r   Ú_pickr   Ú_ratior   r   Úalignr   Újupyterr   Úmeasurer   r[   r   r   Úprotocolr   Úsegmentr   r-   r   r   r¥   r   r    r{   r!   r"   r#   r$   r%   r&   r'   rO   rQ   rS   rF   Úpip._vendor.rich.consoleZpip._vendor.rich.highlighterr0  Úpip._vendor.rich.tableZ_timerr1  Útablerr   r    rq   r)   rj   r6  r^   r4   rd   rc   rb   rA   rA   rA   rB   Ú<module>   sº   , 
Z
      
ý   ÿýûý



