a
    )ñ»jaœ  ã                   @   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;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.d/¡ e= ?d0d1d2¡ e=j?d3d4d5d6d%d7� e= ?d8d9d:¡ e@d;d<œd=d>„ZAe-ƒ Z,e:ƒ ZBeAd?ƒ e,jCe=d@dA� d%e=_DeAdBƒ e, Ce=¡ dCe=_EeAdDƒ e,jCe=d@dA� d;e=_EdEe=_DdFdGge=_FeAdHƒ e,jCe=d@dA� d;e=_EdEe=_DdFdGge=_Fde=_GeAdIƒ e,jCe=d@dA� d;e=_EdEe=_DdFdGge=_Fd%e=_Hd e=_GeAdJƒ e,jCe=d@dA� W d;  ƒ n1 �s0    Y  d;S )Ké    )Ú	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.
        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   ú0E:\soccer\ml_env\Lib\site-packages\rich/table.pyÚcopyt   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   Úcellsx   s    zColumn.cellsc                 C   s
   | j du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   Ú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u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_count1  s    zTable.row_countr!   )ÚconsoleÚindexr>   c                 C   sR   t  ¡ }| jr,|| | j|t| jƒ  ¡7 }| j| j}|durN|| |¡7 }|S )zGet the current row style.N)r   Únullre   Ú	get_stylers   rV   r-   )rA   r{   r|   r-   Ú	row_stylerB   rB   rC   Úget_row_style6  s    zTable.get_row_styler"   )r{   Úoptionsr>   c                    s¾   ˆj ‰| jd ur| j‰ˆdk r(tddƒS | j}t|  ˆˆ ˆ| ¡¡ƒ‰| j‰ ‡ ‡‡‡fdd„| jD ƒ}tdd„ |D ƒƒ| }| jd u ržtdd„ |D ƒƒ| n| j}t||ƒ}| 	| j
¡}|S )Nr   c                    s   g | ]}ˆ ˆˆ  ˆ¡|ƒ‘qS rB   )Úupdate_width©Ú.0Úcolumn©Ú_measure_columnr{   r6   r�   rB   rC   Ú
<listcomp>Q  s   ÿz*Table.__rich_measure__.<locals>.<listcomp>c                 s   s   | ]}|j V  qd S ©N)Úminimum©r„   ÚmeasurementrB   rB   rC   Ú	<genexpr>V  ó    z)Table.__rich_measure__.<locals>.<genexpr>c                 s   s   | ]}|j V  qd S r‰   ©Úmaximumr‹   rB   rB   rC   r�   Y  rŽ   )r6   r4   r   ry   ÚsumÚ_calculate_column_widthsr‚   r‡   rU   Úclampr5   )rA   r{   r�   Úextra_widthÚmeasurementsÚminimum_widthÚmaximum_widthrŒ   rB   r†   rC   Ú__rich_measure__@  s0    

ÿÿþÿÿý
zTable.__rich_measure__c                 C   s   | j S )zGet cell padding.)rm   r@   rB   rB   rC   r\   a  s    zTable.padding)r\   r>   c                 C   s   t  |¡| _| S )zSet cell padding.)r   rl   rm   )rA   r\   rB   rB   rC   r\   f  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u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   l  s$    'ñzTable.add_column©r-   rQ   )Úrenderablesr-   rQ   r>   c                G   s  t dddœdd„}t|ƒ}| j}t|ƒt|ƒk rNg |¢dgt|ƒt|ƒ  ¢}t|ƒD ]’\}}|t|ƒkr t || jd�}	| jD ]}
||	tdƒƒ q~| j |	¡ n|| }	|du r¼||	dƒ qVt	|ƒrÐ||	|ƒ qVt
 dt|ƒj› d	�¡‚qV| 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   ÚNotRenderableErrorÚtyperG   rP   )rA   r-   rQ   rš   r›   Úcell_renderablesrU   r|   rS   r…   Ú_rB   rB   rC   Úadd_row¦  s0    ÿþ
ÿ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 u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   Ú
render_strÚrenderÚupdate)r¦   r-   r/   Úrender_text©r{   Úrender_optionsrB   rC   Úrender_annotationñ  s    ÿýÿz1Table.__rich_console__.<locals>.render_annotationztable.title)r-   r/   ztable.caption)rX   )rU   r   r6   r4   ry   r’   r‚   r‘   rª   r9   r    r   rY   r   Ú
pick_firstrg   ri   Ú_renderrZ   rh   rj   )rA   r{   r�   r6   r”   ÚwidthsÚtable_widthr®   rB   r¬   rC   Ú__rich_console__Û  s@    

ÿÿ ÿþýý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u�rÈ|ˆj| k �rÈˆjdu �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ƒ   ©r{   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ˆ     rŽ   c                 S   s   g | ]}|j r|jpd ‘qS ©r   )rF   r7   )r„   ÚcolrB   rB   rC   rˆ     rŽ   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 u o|j ‘qS r‰   )r4   r8   rƒ   rB   rB   rC   rˆ   /  rŽ   r   c                    s$   g | ]\}}ˆ  ˆ ˆ |¡|¡‘qS rB   )r‡   r‚   )r„   r4   r…   r´   rB   rC   rˆ   9  s   ÿc                 S   s   g | ]}|j pd ‘qS r¸   r�   r¶   rB   rB   rC   rˆ   =  rŽ   Nc                 S   s   g | ]\}}|| ‘qS rB   rB   )r„   Ú_widthÚpadrB   rB   rC   rˆ   H  rŽ   )r6   rU   Ú_get_padding_widthry   r_   ÚanyÚzipr‘   r   Úiterrœ   rF   ÚnextÚ_collapse_widthsr   rs   r5   Úmin)rA   r{   r�   r6   rU   Úwidth_rangesr±   r”   ÚratiosÚfixed_widthsÚflex_minimumÚflexible_widthÚflex_widthsÚiter_flex_widthsr|   r…   r²   Úexcess_widthÚ
_max_widthÚ
pad_widthsrB   )r{   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   Ú
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Ï   ©Ú
max_columnrB   rC   r�   a  s   ÿc                    s$   g | ]\}}|ˆ kr|rd nd‘qS )r   r   rB   rÏ   rÑ   rB   rC   rˆ   f  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_reducerB   rÑ   rC   rÂ   L  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\   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   r{   rØ   r…   Úany_paddingrã   Ú	raw_cellsÚ_appendr~   r+   Ú
cell_styleÚcellr,   Ú_PaddingÚfirstÚlastr-   rS   rB   rß   rC   Ú
_get_cellss  sL    ,ÿ
ÿýýzTable._get_cells)rØ   r>   c                 C   sT   | j \}}}}| jr$d}t|| ƒ}| jsL|dkr6d}|t| jƒd krLd}|| S )zGet extra width from padding.r   r   )r\   r]   Úabsr^   rs   rU   )rA   rØ   r    Ú	pad_rightÚpad_leftrB   rB   rC   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urJt|j| |j| ƒ |¡S g }g }|j}|j}	tj}
|  ||j|¡D ]&}|
|||j	ƒ\}}||ƒ |	|ƒ qtt|rªt
|ƒnd|r¸t
|ƒn|ƒ |¡}| |jdu rÖdn|j| |j du rìdn|j | ¡}|S )z0Get the minimum and maximum width of the column.r   r   N)r6   r   r½   r:   r4   Úwith_maximumro   rÛ   rí   rS   rÓ   r“   r5   )rA   r{   r�   r…   r6   Úpadding_widthÚ
min_widthsÚ
max_widthsÚ
append_minÚ
append_maxÚget_render_widthré   Ú_minÚ_maxrŒ   rB   rB   rC   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 ]^\}}}|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…   )r{   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�   N  rŽ   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_heightrB   rC   Ú
align_cellP  s    z!Table._render.<locals>.align_cellc              
      s8   g | ]0\}}}}ˆ   ˆ||j|ˆ|jƒˆ ƒ|ˆ¡‘qS rB   )Ú	set_shaper1   r-   )r„   r4   Ú_cellré   r…   )r   r  r~   Ú
max_heightr   rB   rC   rˆ   a  s   
öüøz!Table._render.<locals>.<listcomp>Úfoot)Úedger   rx   ÚheadÚmidÚrow)6r~   r-   rf   rœ   rU   rN   r¿   r   Ú
substituter   r[   r`   Úget_plain_headed_boxr   Úlinera   rb   rc   rd   Ú	head_leftÚ
head_rightÚhead_verticalÚmid_leftÚ	mid_rightÚmid_verticalÚ	foot_leftÚ
foot_rightÚfoot_verticalÚget_topr€   r   rV   r   r}   rª   r/   r8   r3   r9   Úrender_linesrS   rÓ   rs   ro   r   rL   Úget_rowr¦   ÚstripÚbackground_styleÚranger   rQ   Ú
get_bottom)%rA   r{   r�   r±   Útable_stylerf   Ú_column_cellsÚ	row_cellsÚ_boxÚnew_linerU   r`   ra   rb   rc   rd   Úbox_segmentsr€   r|   rë   rì   Úrow_cellr  rE   r4   ré   r…   r­   Úlinesr.   rÝ   Ú_dividerÚdividerÚline_noÚ	last_cellÚrendered_cellrQ   rB   )
r   r  r{   r  r~   r  r  r  r   rA   rC   r°   ó  s   þýÿû


ý


ý


ýõ

ÿÿý
ÿúý

ûõÿ"ÿÿý

ÿÿþþýýþÿ
zTable._render)r(   r(   ),rG   rH   rI   rJ   r   r'   rK   rP   r   Ú
HEAVY_HEADr   rq   r
   r    rL   ÚBoxrM   r   r   r   ru   Úclassmethodrw   rO   r_   Úsetterry   rz   r€   r   r˜   r   r\   rr   r¡   r£   r³   r’   rÂ   rR   rí   r½   r‡   r°   rB   rB   rB   rC   rT   ™   s*  
å

ä@ú
ù 	þ!  ýðï=üû/þ1þAþ'þIû(
þrT   Ú__main__)r!   )ÚReprHighlighter)ÚtimerzTable renderzStar Wars MovieszRich example tablerÝ   )rY   rZ   rj   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Úruler9   )r¦   rB   rB   rC   r)   Ð  s    r)   zExample TablerX   r§   zexpand=Trueé2   zwidth=50FÚdimrW   zrow_styles=['dim', 'none']z%leading=1, row_styles=['dim', 'none']z+show_lines=True, row_styles=['dim', 'none'])IÚ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'   rP   rR   rT   rG   Zrich.consoleZrich.highlighterr2  Z_timerr3  Útablerr   r¡   rq   r)   r9   r8  r_   r4   re   rd   rc   rB   rB   rB   rC   Ú<module>   s²   , 
\
      
ýÿýûý



