U
    ƒIÀd·6  ã                   @   st  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mZmZmZmZmZmZmZ ddlmZ ddlmZ dd	lmZmZmZmZ dd
l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* e
rød dl+m,Z, G dd„ deƒZ-ede#f Z.ede-f Z/G dd„ de0ƒZ1G dd„ de1ƒZ2G dd„ dƒZ3G dd„ deƒZ4G dd„ de4ƒZ5G dd „ d e4ƒZ6e&G d!d„ dƒƒZ7e8d"k�rpd d#l9mZ eƒ Ze7ƒ Z:e: ;e7d$d%d&�e7dd'd(�e7d)d*d+�¡ e:d'  <e7d,d-�e7d.d/d0�¡ e:d.  <e7d1d/d0�e7d2d-�¡ e:d2  ;e7d3d-�e7d4d-�e7d5d-�¡ e:d,  ;e7e:j=d6d-�e7d7d-�¡ e:d1  >d8¡ e ?e:¡ d9S ):é    )ÚABCÚabstractmethod)Úislice)Ú
itemgetter)ÚRLock)	ÚTYPE_CHECKINGÚDictÚIterableÚListÚ
NamedTupleÚOptionalÚSequenceÚTupleÚUnioné   )Úratio_resolve)ÚAlign)ÚConsoleÚConsoleOptionsÚRenderableTypeÚRenderResult)ÚReprHighlighter)ÚPanel)ÚPretty)ÚRegion)ÚResultÚ	rich_repr)ÚSegment)Ú	StyleType©ÚTreec                   @   s*   e Zd ZU dZeed< eee  ed< dS )ÚLayoutRenderzAn individual layout render.ÚregionÚrenderN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r
   r   © r)   r)   úP/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/pip/_vendor/rich/layout.pyr!       s   
r!   ÚLayoutc                   @   s   e Zd ZdZdS )ÚLayoutErrorzLayout related error.N©r$   r%   r&   r'   r)   r)   r)   r*   r,   +   s   r,   c                   @   s   e Zd ZdZdS )Ú
NoSplitterz"Requested splitter does not exist.Nr-   r)   r)   r)   r*   r.   /   s   r.   c                   @   s<   e Zd ZdZeƒ Zddeddœdd„Zee	e
dœd	d
„ZdS )Ú_Placeholderz4An internal renderable used as a Layout placeholder.Ú r+   N)ÚlayoutÚstyleÚreturnc                 C   s   || _ || _d S ©N)r1   r2   )Úselfr1   r2   r)   r)   r*   Ú__init__8   s    z_Placeholder.__init__©ÚconsoleÚoptionsr3   c                 c   sx   |j }|jp|jj}| j}|jr8|j›d|› d|› d�nd|› d|› d�}ttjt|ƒdd�| j	|  
|¡d|d�V  d S )	Nz (z x ú)ú(Úmiddle)ÚverticalÚblue)r2   ÚtitleÚborder_styleÚheight)Ú	max_widthrA   Úsizer1   Únamer   r   Úcenterr   r2   Úhighlighter)r5   r8   r9   ÚwidthrA   r1   r?   r)   r)   r*   Ú__rich_console__<   s    ÿýûz_Placeholder.__rich_console__)r0   )r$   r%   r&   r'   r   rF   r   r6   r   r   r   rH   r)   r)   r)   r*   r/   3   s    þr/   c                   @   sV   e Zd ZU dZdZeed< eedœdd„ƒZee	d e
eede
f  dœd	d
„ƒZdS )ÚSplitterzBase class for a splitter.r0   rD   ©r3   c                 C   s   dS )z(Get the icon (emoji) used in layout.treeNr)   ©r5   r)   r)   r*   Úget_tree_iconU   s    zSplitter.get_tree_iconr+   ©Úchildrenr"   r3   c                 C   s   dS )zÇDivide a region amongst several child layouts.

        Args:
            children (Sequence(Layout)): A number of child layouts.
            region (Region): A rectangular region to divide.
        Nr)   )r5   rN   r"   r)   r)   r*   ÚdivideY   s    zSplitter.divideN)r$   r%   r&   r'   rD   Ústrr(   r   rL   r   r   r	   r   rO   r)   r)   r)   r*   rI   P   s   
 þrI   c                   @   sD   e Zd ZdZdZedœdd„Zed ee	e
def  dœdd	„Zd
S )ÚRowSplitterz!Split a layout region in to rows.ÚrowrJ   c                 C   s   dS )Nu   [layout.tree.row]â¬Œr)   rK   r)   r)   r*   rL   j   s    zRowSplitter.get_tree_iconr+   rM   c                 c   sV   |\}}}}t ||ƒ}d}t}	t||ƒD ](\}
}|
|	|| |||ƒfV  ||7 }q(d S ©Nr   ©r   r   Úzip)r5   rN   r"   ÚxÚyrG   rA   Zrender_widthsÚoffsetÚ_RegionÚchildÚchild_widthr)   r)   r*   rO   m   s    
zRowSplitter.divideN©r$   r%   r&   r'   rD   rP   rL   r   r   r	   r   rO   r)   r)   r)   r*   rQ   e   s    þrQ   c                   @   sD   e Zd ZdZdZedœdd„Zed ee	e
def  dœdd	„Zd
S )ÚColumnSplitterz$Split a layout region in to columns.ÚcolumnrJ   c                 C   s   dS )Nu   [layout.tree.column]â¬�r)   rK   r)   r)   r*   rL   ~   s    zColumnSplitter.get_tree_iconr+   rM   c                 c   sV   |\}}}}t ||ƒ}d}t}	t||ƒD ](\}
}|
|	||| ||ƒfV  ||7 }q(d S rS   rT   )r5   rN   r"   rV   rW   rG   rA   Zrender_heightsrX   rY   rZ   Úchild_heightr)   r)   r*   rO   �   s    
zColumnSplitter.divideNr\   r)   r)   r)   r*   r]   y   s    þr]   c                
   @   s¤  e Zd ZdZeedœZd8ddddddœee ee	 ee
 e
e
eddœdd	„Zed
œdd„Zeed
œdd„ƒZeed  d
œdd„ƒZeed
œdd„ƒZe	ed  dœdd„Ze	d dœdd„Zedd
œdd„ƒZddœed ef eee	f ddœdd„Zed ef dd œd!d"„Zed ef dd œd#d$„Zed ef dd œd%d&„Zdd
œd'd(„Zedd)œd*d+„Zd,e	dd-œd.d/„Z e
e
e!d0œd1d2„Z"e#e$ed3œd4d5„Z%e#e$e&d3œd6d7„Z'dS )9r+   aB  A renderable to divide a fixed height in to rows or columns.

    Args:
        renderable (RenderableType, optional): Renderable content, or None for placeholder. Defaults to None.
        name (str, optional): Optional identifier for Layout. Defaults to None.
        size (int, optional): Optional fixed size of layout. Defaults to None.
        minimum_size (int, optional): Minimum size of layout. Defaults to 1.
        ratio (int, optional): Optional ratio for flexible layout. Defaults to 1.
        visible (bool, optional): Visibility of layout. Defaults to True.
    )rR   r^   Nr   T)rD   rC   Úminimum_sizeÚratioÚvisible)Ú
renderablerD   rC   r`   ra   rb   r3   c                C   sR   |p
t | ƒ| _|| _|| _|| _|| _|| _| jd ƒ | _g | _	i | _
tƒ | _d S )Nr^   )r/   Ú_renderablerC   r`   ra   rD   rb   Ú	splittersÚsplitterÚ	_childrenÚ_render_mapr   Ú_lock)r5   rc   rD   rC   r`   ra   rb   r)   r)   r*   r6   œ   s    
zLayout.__init__rJ   c                 c   s<   d| j d fV  d| jd fV  d| jdfV  d| jdfV  d S )NrD   rC   r`   r   ra   )rD   rC   r`   ra   rK   r)   r)   r*   Ú__rich_repr__±   s    zLayout.__rich_repr__c                 C   s   | j r
| S | jS )zLayout renderable.)rg   rd   rK   r)   r)   r*   rc   ·   s    zLayout.renderablec                 C   s   dd„ | j D ƒS )zGets (visible) layout children.c                 S   s   g | ]}|j r|‘qS r)   )rb   )Ú.0rZ   r)   r)   r*   Ú
<listcomp>¿   s      z#Layout.children.<locals>.<listcomp>©rg   rK   r)   r)   r*   rN   ¼   s    zLayout.childrenc                 C   s   | j S )zGet a map of the last render.)rh   rK   r)   r)   r*   ÚmapÁ   s    z
Layout.map)rD   r3   c                 C   s8   | j |kr| S | jD ]}| |¡}|dk	r|  S qdS )zÐGet a named layout, or None if it doesn't exist.

        Args:
            name (str): Name of layout.

        Returns:
            Optional[Layout]: Layout instance or None if no layout was found.
        N)rD   rg   Úget)r5   rD   rZ   Znamed_layoutr)   r)   r*   ro   Æ   s    	



z
Layout.getc                 C   s$   |   |¡}|d kr td|›�ƒ‚|S )NzNo layout with name )ro   ÚKeyError)r5   rD   r1   r)   r)   r*   Ú__getitem__Ø   s    
zLayout.__getitem__r    c                    s€   ddl m‰  ddlm‰ ddlm} dˆdœ‡ ‡fdd„‰| }|ˆ|ƒd	|jj› �d
d�}ddddœ‡‡fdd„‰ˆ|| ƒ |S )z/Get a tree renderable to show layout structure.r   )ÚStyled)ÚTabler   r+   )r1   r3   c                    sF   | j  ¡ }ˆjdd�}| jr$t| ƒnˆ t| ƒdƒ}| ||¡ |}|S )N)r   r   r   r   )ÚpaddingÚdim)rf   rL   Úgridrb   r   Úadd_row)r1   ÚiconÚtableÚtextZ_summary)rr   rs   r)   r*   Úsummaryå   s    
ÿzLayout.tree.<locals>.summaryúlayout.tree.T)Úguide_styleÚ	highlightr    N)Útreer1   r3   c                    s2   |j D ]&}ˆ | jˆ|ƒd|jj› �d�|ƒ qd S )Nr|   )r}   )rg   Úaddrf   rD   )r   r1   rZ   )Úrecurser{   r)   r*   r�   ù   s    
þûzLayout.tree.<locals>.recurse)Zpip._vendor.rich.styledrr   Úpip._vendor.rich.tablers   Úpip._vendor.rich.treer    rf   rD   )r5   r    r1   r   r)   )rr   rs   r�   r{   r*   r   Þ   s    ý

zLayout.treer^   )rf   )Úlayoutsrf   r3   c                G   sd   dd„ |D ƒ}z t |tƒr|n
| j| ƒ | _W n" tk
rP   td|›�ƒ‚Y nX || jdd…< dS )zîSplit the layout in to multiple sub-layouts.

        Args:
            *layouts (Layout): Positional arguments should be (sub) Layout instances.
            splitter (Union[Splitter, str]): Splitter instance or name of splitter.
        c                 S   s"   g | ]}t |tƒr|nt|ƒ‘qS r)   ©Ú
isinstancer+   ©rk   r1   r)   r)   r*   rl     s   ÿz Layout.split.<locals>.<listcomp>zNo splitter called N)r†   rI   re   rf   rp   r.   rg   )r5   rf   r„   Ú_layoutsr)   r)   r*   Úsplit  s    þÿ
ýzLayout.split)r„   r3   c                 G   s   dd„ |D ƒ}| j  |¡ dS )z»Add a new layout(s) to existing split.

        Args:
            *layouts (Union[Layout, RenderableType]): Positional arguments should be renderables or (sub) Layout instances.

        c                 s   s$   | ]}t |tƒr|nt|ƒV  qd S r4   r…   r‡   r)   r)   r*   Ú	<genexpr>&  s   ÿz#Layout.add_split.<locals>.<genexpr>N)rg   Úextend)r5   r„   rˆ   r)   r)   r*   Ú	add_split  s    þzLayout.add_splitc                 G   s   | j |ddiŽ dS )z¢Split the layout in to a row (layouts side by side).

        Args:
            *layouts (Layout): Positional arguments should be (sub) Layout instances.
        rf   rR   N©r‰   ©r5   r„   r)   r)   r*   Ú	split_row,  s    zLayout.split_rowc                 G   s   | j |ddiŽ dS )zµSplit the layout in to a column (layouts stacked on top of each other).

        Args:
            *layouts (Layout): Positional arguments should be (sub) Layout instances.
        rf   r^   Nr�   rŽ   r)   r)   r*   Úsplit_column4  s    zLayout.split_columnc                 C   s   | j dd…= dS )zReset splits to initial state.Nrm   rK   r)   r)   r*   Úunsplit<  s    zLayout.unsplit)rc   r3   c              	   C   s   | j � || _W 5 Q R X dS )zjUpdate renderable.

        Args:
            renderable (RenderableType): New renderable object.
        N)ri   rd   )r5   rc   r)   r)   r*   Úupdate@  s    zLayout.updater   )r8   Úlayout_namer3   c              	   C   sl   | j �\ | | }| j| \}}|\}}}}	| ||j ||	¡¡}
t||
ƒ| j|< | |
||¡ W 5 Q R X dS )z¬Refresh a sub-layout.

        Args:
            console (Console): Console instance where Layout is to be rendered.
            layout_name (str): Name of layout.
        N)ri   rh   Úrender_linesr9   Úupdate_dimensionsr!   Úupdate_screen_lines)r5   r8   r“   r1   r"   Ú_linesrV   rW   rG   rA   Úlinesr)   r)   r*   Úrefresh_screenI  s     ÿzLayout.refresh_screen)rG   rA   r3   c                 C   sŠ   | t dd||ƒfg}|j}|j}g }|j}|rl||ƒ ƒ |d \}}	|j}
|
r*|j |
|	¡D ]}||ƒ q\q*dd„ t|tdƒd�D ƒ}|S )z,Create a dict that maps layout on to Region.r   éÿÿÿÿc                 S   s   i | ]\}}||“qS r)   r)   ©rk   r1   r"   r)   r)   r*   Ú
<dictcomp>i  s   ÿ z+Layout._make_region_map.<locals>.<dictcomp>r   )Úkey)r   ÚappendÚpoprN   rf   rO   Úsortedr   )r5   rG   rA   ÚstackÚpushrŸ   Úlayout_regionsZappend_layout_regionr1   r"   rN   Zchild_and_regionÚ
region_mapr)   r)   r*   Ú_make_region_mapZ  s     
þzLayout._make_region_mapr7   c                 C   sv   |j }|jp|j}|  ||¡}dd„ | ¡ D ƒ}i }|j}|j}	|D ],\}
}||
j|	|j|jƒƒ}t||ƒ||
< qD|S )z÷Render the sub_layouts.

        Args:
            console (Console): Console instance.
            options (ConsoleOptions): Console options.

        Returns:
            RenderMap: A dict that maps Layout on to a tuple of Region, lines
        c                 S   s   g | ]\}}|j s||f‘qS r)   )rN   r›   r)   r)   r*   rl   |  s   þz!Layout.render.<locals>.<listcomp>)	rB   rA   r¥   Úitemsr”   r•   rc   rG   r!   )r5   r8   r9   Úrender_widthÚrender_heightr¤   r£   Ú
render_mapr”   r•   r1   r"   r˜   r)   r)   r*   r#   o  s     
þ ÿzLayout.renderc              	   c   sÈ   | j �¸ |jp|j}|jp|j}|  || ||¡¡}|| _dd„ t|ƒD ƒ}t}| 	¡ D ]>\}}	|\}
}}}t
||||| ƒ|	ƒD ]\}}| |¡ q‚qXt ¡ }|D ]}|E d H  |V  q¤W 5 Q R X d S )Nc                 S   s   g | ]}g ‘qS r)   r)   )rk   Ú_r)   r)   r*   rl   ”  s     z+Layout.__rich_console__.<locals>.<listcomp>)ri   rB   rG   rA   r#   r•   rh   Úranger   ÚvaluesrU   r‹   r   Úline)r5   r8   r9   rG   rA   r©   Zlayout_linesÚ_islicer"   r˜   Z_xrW   Z_layout_widthZlayout_heightrR   r­   Únew_lineZ
layout_rowr)   r)   r*   rH   Œ  s$     ÿ
zLayout.__rich_console__)N)(r$   r%   r&   r'   rQ   r]   re   r   r   rP   ÚintÚboolr6   r   rj   Úpropertyrc   r
   rN   Ú	RenderMaprn   ro   rq   r   r   rI   r‰   rŒ   r�   r�   r‘   r’   r™   Ú	RegionMapr¥   r   r   r#   r   rH   r)   r)   r)   r*   r+   �   s^   
 þø÷*ý

ü	 þÚ__main__)r   Úheaderé   )rD   rC   Úmain)ra   rD   é
   Úfooter)rC   rD   Zside)rD   Úbodyé   )rD   ra   ÚcontentÚs2Útopr<   ÚbottomZleft1Zleft2ZfooN)@Úabcr   r   Ú	itertoolsr   Úoperatorr   Ú	threadingr   Útypingr   r   r	   r
   r   r   r   r   r   Ú_ratior   Úalignr   r8   r   r   r   r   rF   r   Úpanelr   Úprettyr   r"   r   Úreprr   r   Úsegmentr   r2   r   rƒ   r    r!   r´   r³   Ú	Exceptionr,   r.   r/   rI   rQ   r]   r+   r$   Úpip._vendor.rich.consoler1   r�   r�   r   r’   Úprintr)   r)   r)   r*   Ú<module>   s`   ,  



ý  ÿ 