o
    Ú­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:¡ d;e@d<d=fd>d?„ZAe-ƒ Z,e:ƒ ZBeAd@ƒ e,jCe=dAdB� d%e=_DeAdCƒ e, Ce=¡ dDe=_EeAdEƒ e,jCe=dAdB� d=e=_EdFe=_DdGdHge=_FeAdIƒ e,jCe=dAdB� d=e=_EdFe=_DdGdHge=_Fde=_GeAdJƒ e,jCe=dAdB� d=e=_EdFe=_DdGdHge=_Fd%e=_Hd e=_GeAdKƒ e,jCe=dAdB� W d=  ƒ d=S 1 �s�w   Y  d=S 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 „Zeded fd!d"„ƒZedef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© rA   úG/var/www/html/CropPilot/venv/lib/python3.10/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?   rA   rA   rB   Úcellsx   s   €zColumn.cellsc                 C   s
   | j duS )z!Check if this column is flexible.N)r7   r?   rA   rA   rB   Úflexible}   ó   
zColumn.flexible)r=   r'   )!Ú__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   rC   Úpropertyr   rD   rE   rA   rA   rA   rB   r'   &   sL   
 
r'   c                   @   s0   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   rA   rA   rA   rB   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   rA   rA   rA   rB   rR   Ž   s   
 rR   c                7   @   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œde
eef dee dee dee dee deej dee dededededededededededeee  d ee d!ee d"ee d#ee d$ee d%d&d'd&d(ed)df6d*d+„Zeddddd,œde
eef dedededed)d fd-d.„ƒZed)efd/d0„ƒZejded)dfd1d0„ƒZed)efd2d3„ƒZed)efd4d5„ƒZd6d7d8ed)efd9d:„Zd6d7d;d<d)efd=d>„Zed)eeeeef fd?d@„ƒZ e jded)d fdAd@„ƒZ 	B	BdndddddCdDdEddddddFœdGdHdIdHd ee d(ee d!ee dee dJd&dKdLdMdNdee dee dOee dPee dQed)dfdRdS„Z!dddTœdUedH dee dVed)dfdWdX„Z"dodYdZ„Z#	6	7	;	<	)	[dpd\d]„Z$d6d7d;d<d)ee fd^d_„Z%ed`ee daee dOed)ee fdbdc„ƒZ&d6d7ddedeed)ee' fdfdg„Z(dded)efdhdi„Z)d6d7d;d<deed)efdjdk„Z*d6d7d;d<d`ee d)d[fdldm„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   ÚheadersrY   rZ   r4   r5   r   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   r-   re   r+   r,   rf   rg   rh   ri   r#   rj   r9   r=   c                G   sú   g | _ g | _|| _|| _|| _|| _|| _|| _t 	|¡| _
|	| _|
| _|| _|| _|| _|| _|| _|| _|| _|p<d| _|pAd| _|| _|| _|| _|| _|| _|| _t|pYg ƒ| _| j j}|D ]}t|t ƒrp| j!|d� qbt"| j ƒ|_#||ƒ qbd 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:   )r@   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)   rA   rA   rB   Ú__init__¼   sD   



ûzTable.__init__)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_   rA   )Úclsr\   r]   r^   r_   rk   rA   rA   rB   Úgridü   s   ÷z
Table.gridc                 C   s   | j p| jduS )z-Setting a non-None self.width implies expand.N)rn   r4   r?   rA   rA   rB   r_     s   zTable.expandc                 C   s
   || _ dS )zSet expand.N)rn   )r@   r_   rA   rA   rB   r_   "  rF   c                 C   s4   d}| j r| jr|d7 }| j r|t| jƒd 7 }|S )z'Get extra width to add to cell content.r   é   r   )r   rb   rs   rU   )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   rV   r?   rA   rA   rB   Ú	row_count1  rF   zTable.row_countÚconsoler!   Úindexc                 C   sR   t  ¡ }| jr|| | j|t| jƒ  ¡7 }| j| j}|dur'|| |¡7 }|S )zGet the current row style.N)r   Únullre   Ú	get_stylers   rV   r-   )r@   r{   r|   r-   Ú	row_stylerA   rA   rB   Úget_row_style6  s   zTable.get_row_styleÚ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 rOt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>Q  s    ÿÿz*Table.__rich_measure__.<locals>.<listcomp>c                 s   ó   � | ]}|j V  qd S ©N)Úminimum©r„   ÚmeasurementrA   rA   rB   Ú	<genexpr>V  ó   € z)Table.__rich_measure__.<locals>.<genexpr>c                 s   r‰   rŠ   ©ÚmaximumrŒ   rA   rA   rB   rŽ   Y  r�   )r6   r4   r   ry   ÚsumÚ_calculate_column_widthsr‚   r‡   rU   Úclampr5   )r@   r{   r�   Úextra_widthÚmeasurementsÚminimum_widthÚmaximum_widthr�   rA   r†   rB   Ú__rich_measure__@  s0   

ÿÿþÿ
ÿý
zTable.__rich_measure__c                 C   s   | j S )zGet cell padding.)rm   r?   rA   rA   rB   r\   a  s   zTable.paddingc                 C   s   t  |¡| _| S )zSet cell padding.)r   rl   rm   )r@   r\   rA   rA   rB   r\   f  s   r(   r.   r0   r2   )r+   r9   r,   r-   r/   r1   r3   r4   r5   r6   r7   r8   r)   r%   r*   r/   r1   r   r3   r$   r6   r7   r8   c                C   sV   t t| jƒ|||p
d|dur|n| j|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.
            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   )r@   r)   r*   r+   r9   r,   r-   r/   r1   r3   r4   r5   r6   r7   r8   r…   rA   rA   rB   rr   l  s$   'ñzTable.add_column©r-   rQ   ÚrenderablesrQ   c                G   s  dt ddddfdd„}t|ƒ}| j}t|ƒt|ƒk r)g |¢dgt|ƒt|ƒ  ¢}t|ƒD ]H\}}|t|ƒkrRt || jd�}	| jD ]	}
||	td	ƒƒ qA| j |	¡ n|| }	|du r`||	d	ƒ q-t	|ƒrj||	|ƒ q-t
 d
t|ƒj› d�¡‚| 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…   rS   r%   r=   Nc                 S   s   | j  |¡ d S rŠ   )r<   ro   )r…   rS   rA   rA   rB   Ú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   )r@   r-   rQ   r›   rœ   Úcell_renderablesrU   r|   rS   r…   Ú_rA   rA   rB   Úadd_row¦  s0   ÿþ
ÿzTable.add_rowc                 C   s   | j rd| j d _dS dS )z2Add a new section (draw a line after current row).TéÿÿÿÿN)rV   rQ   r?   rA   rA   rB   Ú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dt
dtdddd	f‡ ‡fd
d„}| jrY|| jt | jd¡| jd�E d H  |  ˆ ˆ|¡E d H  | jry|| jt | jd¡| jd�E d H  d S d S )NÚ
)r4   r9   ÚheightrX   Útextr-   r/   r#   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_optionsrA   rB   Ú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   )r@   r{   r�   r6   r•   ÚwidthsÚtable_widthr¯   rA   r­   rB   Ú__rich_console__Û  sN   €

ÿÿÿÿÿÿþýýÿzTable.__rich_console__c                    s¾  ˆj }ˆj}‡ ‡‡fdd„|D ƒ}dd„ |D ƒ}ˆj‰ˆj}ˆjredd„ |D ƒ}t|ƒredd„ t||ƒD ƒ}	‡fdd„|D ƒ}
|t|	ƒ }t|||
ƒ}t	|ƒ}t
|ƒD ]\}}|jrd|	| t|ƒ ||< qSt|ƒ}||krªˆ |dd„ |D ƒ|¡}t|ƒ}||kr•|| }t|dgt|ƒ ||ƒ}t|ƒ}‡ ‡‡fd	d„t||ƒD ƒ}d
d„ |D ƒ}||k r±ˆ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 rA   )r‡   rƒ   ©r{   r�   r@   rA   rB   rˆ     s    ÿz2Table._calculate_column_widths.<locals>.<listcomp>c                 S   ó   g | ]}|j pd ‘qS ©r   r�   ©r„   Ú_rangerA   rA   rB   rˆ     ó    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   r:   rƒ   )Úget_padding_widthrA   rB   rˆ     s    ýÿc                 S   s   g | ]}|j d u 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ˆ   9  ó    ÿÿc                 S   r¶   r»   r�   r¸   rA   rA   rB   rˆ   =  rº   Nc                 S   s   g | ]\}}|| ‘qS rA   rA   )r„   Ú_widthÚpadrA   rA   rB   rˆ   H  s    )r6   rU   Ú_get_padding_widthry   r_   ÚanyÚzipr’   r   Úiterr�   rE   ÚnextÚ_collapse_widthsr   rs   r5   Úmin)r@   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_widthsrA   )r{   r½   r�   r@   rB   r“     sb   ÿþ
þ€ýþ
ÿýzTable._calculate_column_widthsr²   Úwrapablec           
         sÌ   t |ƒ}|| }t|ƒrd|rd|dkrdtdd„ t||ƒD ƒƒ‰ t‡ fdd„t||ƒD ƒƒ}ˆ | }‡ fdd„t||ƒD ƒ}t|ƒrB|sE	 |S t||ƒgt|ƒ }	t|||	|ƒ}t |ƒ}|| }|rd|dks|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Ž   ^  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Ž   a  s
   € ÿ
ÿc                    s$   g | ]\}}|ˆ kr|rd nd‘qS )r   r   rA   rÓ   rÕ   rA   rB   rˆ   f  r¾   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Æ   L  s.   ÿþ
þûízTable._collapse_widthsÚcolumn_indexr…   c              
   #   sr  � | j ‰| j‰| j‰tˆƒ}|dk‰|t| jƒd k‰i ‰ dtdtdtttttf f‡ ‡‡‡‡‡fdd„}g }|j	}|j
}| jrS|| jpEdƒ||jƒ }	||	|jfƒ ||jpXdƒ}
|jD ]}||
|fƒ q]| jr||| jpndƒ||jƒ }|||jfƒ |r¢t}t|ƒD ]\}}\}}t||||||ƒƒt|d	d
ƒpœ|jƒV  q„d
S |D ]\}}t||t|d	d
ƒp³|jƒV  q¤d
S )z3Get all the cells with padding and optional header.r   r   Ú	first_rowÚlast_rowr=   c                    sŠ   ˆ   | |f¡}|r|S ˆ\}}}}ˆr%ˆstd|| ƒ}|s%td|| ƒ}ˆs7ˆr+d}ˆr/d}| r3d}|r7d}||||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   rU   rM   r   rL   ro   r~   r`   r+   r)   r-   rD   ra   r,   r*   r   r   rR   Úgetattrr1   )r@   r{   rÜ   r…   Úany_paddingrç   Ú	raw_cellsÚ_appendr~   r+   Ú
cell_styleÚcellr,   Ú_PaddingÚfirstÚlastr-   rS   rA   rã   rB   Ú
_get_cellss  sR   €0ÿ
ÿýÿýÿzTable._get_cellsc                 C   sT   | j \}}}}| jrd}t|| ƒ}| js&|dkrd}|t| jƒd kr&d}|| S )zGet extra width from padding.r   r   )r\   r]   Úabsr^   rs   rU   )r@   rÜ   r¡   Ú	pad_rightÚpad_leftrA   rA   rB   rÁ   ¼  s   zTable._get_padding_widthc                 C   s  |j }|dk rtddƒS |  |j¡}|jdur%t|j| |j| ƒ |¡S g }g }|j}|j}	tj}
|  ||j|¡D ]}|
|||j	ƒ\}}||ƒ |	|ƒ q:t|rUt
|ƒnd|r\t
|ƒn|ƒ |¡}| |jdu rkdn|j| |j du ryd¡}|S |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   )r@   r{   r�   r…   r6   Úpadding_widthÚ
min_widthsÚ
max_widthsÚ
append_minÚ
append_maxÚget_render_widthrí   Ú_minÚ_maxr�   rA   rA   rB   r‡   Ì  sB   

ÿþ
þýþþþzTable._measure_columnc           %      #   sœ  � ˆ  ˆ	jpd¡}|ˆ  ˆ	jpd¡ }‡‡	fdd„tˆ	jƒD ƒ}tt|Ž ƒ}ˆ	jr6ˆ	jj|t	ˆ	j
ˆj
ƒd�nd }|rAˆ	jsA| ¡ n|}t ¡ }	ˆ	j}
ˆ	j}ˆ	j}ˆ	j}ˆ	j}ˆ	j}t‰ |ržˆ |j|ƒˆ |j|ƒˆ |j|ƒfˆ |j|ƒˆ |j|ƒˆ |j|ƒfˆ |j|ƒˆ |j|ƒˆ |j|ƒfg}|r�ˆ | |¡|ƒV  |	V  ng }ˆ	j}ˆj ‰tt|ƒƒD �]ˆ\}\}}}|o·|‰|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 ƒƒ‰d	t,t,t  d
ddt-dt dt,t,t  f
‡ ‡‡‡fdd„‰‡ ‡‡‡‡fdd„t||||
ƒD ƒ|d d …< |�r½|�rk|�rkˆ |j.|d|d�|ƒV  |	V  ||�rqdn|�rvdnd \}}}|j/ 0¡ �r„|n	ˆ |j/ˆj1|j ƒ} t2ˆƒD ])}!|�rš|V  t3|ƒD ]\}"}#|#|! E d H  |"�s¯| V  �qž|�r·|V  |	V  �q’nt2ˆƒD ]}!|D ]
}#|#|! E d H  �qÅ|	V  �qÁ|�rí|�rí|�ríˆ |j.|d|d�|ƒV  |	V  |�oò|j4}$|�r5|�sÿ|�sÿ|$�r5|�s5|�r|t*|ƒd k�s5|�rˆ�s5|�r&ˆ |j.|d|d�| |ƒV  nˆ |j.|d|d�|ƒV  |	V  q¬|�rJ|�rLˆ | 5|¡|ƒV  |	V  d S d S 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¦   r9   ©r-   c                 s   s   � | ]}t |ƒV  qd S rŠ   )rs   )r„   rí   rA   rA   rB   rŽ   N  s   € rí   r1   r   r4   r-   r=   c                    sR   ˆrd}nˆr	d}|dkrˆ   | |ˆ|¡S |dkr!ˆ  | |ˆ|¡S ˆ  | |ˆ|¡S )Nrâ   r0   Úmiddle)Ú	align_topÚalign_middleÚalign_bottom)rí   r1   r4   r-   )Ú_SegmentÚ
footer_rowÚ
header_rowÚ
row_heightrA   rB   Ú
align_cellP  s   z!Table._render.<locals>.align_cellc              
      s8   g | ]\}}}}ˆ   ˆ||j|ˆ|jƒˆ ƒ|ˆ¡‘qS rA   )Ú	set_shaper1   r-   )r„   r4   Ú_cellrí   r…   )r  r  r~   Ú
max_heightr   rA   rB   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)%r@   r{   r�   r²   Útable_stylerf   Ú_column_cellsÚ	row_cellsÚ_boxÚnew_linerU   r`   ra   rb   rc   rd   Úbox_segmentsr€   r|   rï   rð   Úrow_cellr  rD   r4   rí   r…   r®   Úlinesr.   rá   Ú_dividerÚdividerÚline_noÚ	last_cellÚrendered_cellrQ   rA   )
r  r  r{   r  r~   r  r  r  r   r@   rB   r±   ó  s*  €þýÿû


ý


ý


ýõ€ÿÿý
ÿúý
ÿþýü
ûõÿ"ÿÿý€
÷
ÿÿþÿÿþÿ€
þzTable._render)r(   r(   )r=   N)r{   r!   r�   r"   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±   rA   rA   rA   rB   rT   ™   sÐ  
 å
þýüûúùø	÷
öõôóòñðïî
íìëêéèçæå
ä@ú
þýüûúù 	
ÿÿ
þ!ýðþýûúùø	÷
öõôóòñð
ï=üþýü
û
/ÿÿ
þ0ÿÿ
þAÿÿÿþ&ÿÿÿ
þIþýü
û'ÿÿÿþrT   Ú__main__)r!   )ÚReprHighlighter)ÚtimerzTable renderzStar Wars MovieszRich example tablerá   )rY   rZ   rj   ÚReleasedÚbright_cyanÚcyanT)r+   r-   r8   Ú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,889r§   r=   Nc                 C   s"   t  ¡  t  t| ƒ¡ t  ¡  d S rŠ   )r{   ÚprintÚruler9   )r§   rA   rA   rB   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   Úrich.consoleÚrich.highlighterr6  Ú_timerr7  Útablerr   r¢   rq   r)   r9   r>  r_   r4   re   rd   rc   rA   rA   rA   rB   Ú<module>   s¸    , 
\
      

ýÿýûý



$¹ú