o
    Ëý°jà6  ã                   @   sx  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#m$Z$ ddl%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�r:d 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 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)Ú	rich_reprÚResult)ÚRegion)Ú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)   úŠ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pip/_vendor/rich/layout.pyr!       s   
 r!   ÚLayoutc                   @   ó   e Zd ZdZdS )ÚLayoutErrorzLayout related error.N©r$   r%   r&   r'   r)   r)   r)   r*   r-   +   ó    r-   c                   @   r,   )Ú
NoSplitterz"Requested splitter does not exist.Nr.   r)   r)   r)   r*   r0   /   r/   r0   c                   @   sD   e Zd ZdZeƒ Zddddeddfdd	„Zd
ede	de
fdd„ZdS )Ú_Placeholderz4An internal renderable used as a Layout placeholder.Ú Úlayoutr+   ÚstyleÚreturnNc                 C   s   || _ || _d S ©N)r3   r4   )Úselfr3   r4   r)   r)   r*   Ú__init__8   s   
z_Placeholder.__init__ÚconsoleÚoptionsc                 c   sx   � |j }|jp
|jj}| j}|jr|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)r4   ÚtitleÚborder_style)Ú	max_widthÚheightÚsizer3   Únamer   r   Úcenterr   r4   Úhighlighter)r7   r9   r:   ÚwidthrC   r3   r@   r)   r)   r*   Ú__rich_console__<   s   €ÿýüz_Placeholder.__rich_console__)r2   )r$   r%   r&   r'   r   rG   r   r8   r   r   r   rI   r)   r)   r)   r*   r1   3   s    ÿÿþr1   c                
   @   sZ   e Zd ZU dZdZeed< edefdd„ƒZede	d d	e
deede
f  fd
d„ƒZdS )ÚSplitterzBase class for a splitter.r2   rE   r5   c                 C   ó   dS )z(Get the icon (emoji) used in layout.treeNr)   ©r7   r)   r)   r*   Úget_tree_iconT   ó    zSplitter.get_tree_iconÚchildrenr+   r"   c                 C   rK   )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)   )r7   rO   r"   r)   r)   r*   ÚdivideX   rN   zSplitter.divideN)r$   r%   r&   r'   rE   Ústrr(   r   rM   r   r   r	   r   rP   r)   r)   r)   r*   rJ   O   s   
 ÿÿþrJ   c                	   @   óH   e Zd ZdZdZdefdd„Zded dede	e
def  fd	d
„ZdS )ÚRowSplitterz!Split a layout region in to rows.Úrowr5   c                 C   rK   )Nu   [layout.tree.row]â¬Œr)   rL   r)   r)   r*   rM   i   ó   zRowSplitter.get_tree_iconrO   r+   r"   c                 c   sX   � |\}}}}t ||ƒ}d}t}	t||ƒD ]\}
}|
|	|| |||ƒfV  ||7 }qd S ©Nr   ©r   r   Úzip)r7   rO   r"   ÚxÚyrH   rC   Úrender_widthsÚoffsetÚ_RegionÚchildÚchild_widthr)   r)   r*   rP   l   ó   €

þzRowSplitter.divideN©r$   r%   r&   r'   rE   rQ   rM   r   r   r	   r   rP   r)   r)   r)   r*   rS   d   ó    ÿÿþrS   c                	   @   rR   )ÚColumnSplitterz$Split a layout region in to columns.Úcolumnr5   c                 C   rK   )Nu   [layout.tree.column]â¬�r)   rL   r)   r)   r*   rM   }   rU   zColumnSplitter.get_tree_iconrO   r+   r"   c                 c   sX   � |\}}}}t ||ƒ}d}t}	t||ƒD ]\}
}|
|	||| ||ƒfV  ||7 }qd S rV   rW   )r7   rO   r"   rY   rZ   rH   rC   Úrender_heightsr\   r]   r^   Úchild_heightr)   r)   r*   rP   €   r`   zColumnSplitter.divideNra   r)   r)   r)   r*   rc   x   rb   rc   c                   @   sÔ  e Zd ZdZeedœZ	d=dddddddœdee dee	 d	ee
 d
e
de
dedee
 ddfdd„Zdefdd„Zedefdd„ƒZeded  fdd„ƒZedefdd„ƒZde	ded  fdd„Zde	dd fdd„Zed>dd„ƒZd d!œd"ed ef d#eee	f ddfd$d%„Zd"ed ef ddfd&d'„Zd"ed ef ddfd(d)„Zd"ed ef ddfd*d+„Zd?d,d-„Zdeddfd.d/„Zd0d1d2e	ddfd3d4„Z d5e
de
de!fd6d7„Z"d0e#d8e$defd9d:„Z%d0e#d8e$de&fd;d<„Z'dS )@r+   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.
    )rT   rd   Nr   T)rE   rD   Úminimum_sizeÚratioÚvisiblerC   Ú
renderablerE   rD   rg   rh   ri   rC   r5   c                C   sX   |pt | ƒ| _|| _|| _|| _|| _|| _|| _| jd ƒ | _	g | _
i | _tƒ | _d S )Nrd   )r1   Ú_renderablerD   rg   rh   rE   ri   rC   Ú	splittersÚsplitterÚ	_childrenÚ_render_mapr   Ú_lock)r7   rj   rE   rD   rg   rh   ri   rC   r)   r)   r*   r8   ›   s   zLayout.__init__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 )NrE   rD   rg   r   rh   )rE   rD   rg   rh   rL   r)   r)   r*   Ú__rich_repr__²   s
   €zLayout.__rich_repr__c                 C   s   | j r| S | jS )zLayout renderable.)rn   rk   rL   r)   r)   r*   rj   ¸   ó   zLayout.renderablec                 C   s   dd„ | j D ƒS )zGets (visible) layout children.c                 S   s   g | ]}|j r|‘qS r)   )ri   )Ú.0r^   r)   r)   r*   Ú
<listcomp>À   s    z#Layout.children.<locals>.<listcomp>©rn   rL   r)   r)   r*   rO   ½   rr   zLayout.childrenc                 C   s   | j S )zGet a map of the last render.)ro   rL   r)   r)   r*   ÚmapÂ   s   z
Layout.mapc                 C   s8   | j |kr| S | jD ]}| |¡}|du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)rE   rn   Úget)r7   rE   r^   Únamed_layoutr)   r)   r*   rw   Ç   s   
	

ÿz
Layout.getc                 C   s$   |   |¡}|d u rtd|›�ƒ‚|S )NzNo layout with name )rw   ÚKeyError)r7   rE   r3   r)   r)   r*   Ú__getitem__Ù   s   
zLayout.__getitem__r    c                    sz   ddl m‰  ddlm‰ ddlm} dddˆf‡ ‡fdd	„‰| }|ˆ|ƒd
|jj› �dd�}d‡‡fdd„‰ˆ|| ƒ |S )z/Get a tree renderable to show layout structure.r   )ÚStyled)ÚTabler   r3   r+   r5   c                    sF   | j  ¡ }ˆjdd�}| jrt| ƒnˆ t| ƒdƒ}| ||¡ |}|S )N)r   r   r   r   )ÚpaddingÚdim)rm   rM   Úgridri   r   Úadd_row)r3   ÚiconÚtableÚtextÚ_summary)r{   r|   r)   r*   Úsummaryæ   s   
ÿzLayout.tree.<locals>.summaryúlayout.tree.T)Úguide_styleÚ	highlightÚtreer    Nc                    s2   |j D ]}ˆ | jˆ|ƒd|jj› �d�|ƒ qd S )Nr†   )r‡   )rn   Úaddrm   rE   )r‰   r3   r^   )Úrecurser…   r)   r*   r‹   ú   s   
þûÿzLayout.tree.<locals>.recurse)r‰   r    r3   r+   r5   N)Úpip._vendor.rich.styledr{   Úpip._vendor.rich.tabler|   Úpip._vendor.rich.treer    rm   rE   )r7   r    r3   r‰   r)   )r{   r|   r‹   r…   r*   r‰   ß   s   ý

zLayout.treerd   )rm   Úlayoutsrm   c                G   s^   dd„ |D ƒ}zt |tƒr|n| j| ƒ | _W n ty%   td|›�ƒ‚w || 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+   ©rs   r3   r)   r)   r*   rt     s    ÿÿz Layout.split.<locals>.<listcomp>zNo splitter called N)r‘   rJ   rl   rm   ry   r0   rn   )r7   rm   r�   Ú_layoutsr)   r)   r*   Úsplit  s   þÿ
ýÿzLayout.splitc                 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 r6   r�   r’   r)   r)   r*   Ú	<genexpr>'  s
   € ÿ
ÿz#Layout.add_split.<locals>.<genexpr>N)rn   Úextend)r7   r�   r“   r)   r)   r*   Ú	add_split   s   þzLayout.add_splitc                 G   ó   | j |ddiŽ dS )z£Split the layout in tow a row (Layouts side by side).

        Args:
            *layouts (Layout): Positional arguments should be (sub) Layout instances.
        rm   rT   N©r”   ©r7   r�   r)   r)   r*   Ú	split_row-  ó   zLayout.split_rowc                 G   r˜   )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.
        rm   rd   Nr™   rš   r)   r)   r*   Úsplit_column5  rœ   zLayout.split_columnc                 C   s   | j dd…= dS )zReset splits to initial state.Nru   rL   r)   r)   r*   Úunsplit=  s   zLayout.unsplitc                 C   s2   | j � || _W d  ƒ dS 1 sw   Y  dS )zjUpdate renderable.

        Args:
            renderable (RenderableType): New renderable object.
        N)rp   rk   )r7   rj   r)   r)   r*   ÚupdateA  s   "ÿzLayout.updater9   r   Úlayout_namec                 C   s‚   | j �4 | | }| j| \}}|\}}}}	| ||j ||	¡¡}
t||
ƒ| j|< | |
||¡ W d  ƒ dS 1 s:w   Y  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)rp   ro   Úrender_linesr:   Úupdate_dimensionsr!   Úupdate_screen_lines)r7   r9   r    r3   r"   Ú_linesrY   rZ   rH   rC   Úlinesr)   r)   r*   Úrefresh_screenJ  s   ÿ"øzLayout.refresh_screenrH   c                 C   sŒ   | t dd||ƒfg}|j}|j}g }|j}|r7||ƒ ƒ |d \}}	|j}
|
r5|j |
|	¡D ]}||ƒ q.|s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)   ©rs   r3   r"   r)   r)   r*   Ú
<dictcomp>j  s    ÿÿz+Layout._make_region_map.<locals>.<dictcomp>r   )Úkey)r   ÚappendÚpoprO   rm   rP   Úsortedr   )r7   rH   rC   ÚstackÚpushr¬   Úlayout_regionsÚappend_layout_regionr3   r"   rO   Úchild_and_regionÚ
region_mapr)   r)   r*   Ú_make_region_map[  s"   

úþzLayout._make_region_mapr:   c                 C   sv   |j }|jp|j}|  ||¡}dd„ | ¡ D ƒ}i }|j}|j}	|D ]\}
}||
j|	|j|jƒƒ}t||ƒ||
< q"|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)   )rO   r¨   r)   r)   r*   rt   }  s    ýÿz!Layout.render.<locals>.<listcomp>)	rB   rC   r´   Úitemsr¡   r¢   rj   rH   r!   )r7   r9   r:   Úrender_widthÚrender_heightr³   r°   Ú
render_mapr¡   r¢   r3   r"   r¥   r)   r)   r*   r#   p  s   
þÿzLayout.renderc                 c   sà   � | j �b |jp
|j}|jp|j}|  || ||¡¡}|| _dd„ t|ƒD ƒ}t}| 	¡ D ]\}}	|\}
}}}t
||||| ƒ|	ƒD ]	\}}| |¡ qBq-t ¡ }|D ]
}|E d H  |V  qSW d   ƒ d S 1 siw   Y  d S )Nc                 S   s   g | ]}g ‘qS r)   r)   )rs   Ú_r)   r)   r*   rt   •  s    z+Layout.__rich_console__.<locals>.<listcomp>)rp   rB   rH   rC   r#   r¢   ro   Úranger   ÚvaluesrX   r–   r   Úline)r7   r9   r:   rH   rC   r¸   Úlayout_linesÚ_islicer"   r¥   Ú_xrZ   Ú_layout_widthÚlayout_heightrT   r¼   Únew_lineÚ
layout_rowr)   r)   r*   rI   �  s*   €ÿý
þ"ñzLayout.__rich_console__r6   )r5   r    )r5   N)(r$   r%   r&   r'   rS   rc   rl   r   r   rQ   ÚintÚboolr8   r   rq   Úpropertyrj   r
   rO   Ú	RenderMaprv   rw   rz   r‰   r   rJ   r”   r—   r›   r�   rž   rŸ   r¦   Ú	RegionMapr´   r   r   r#   r   rI   r)   r)   r)   r*   r+   Œ   s|    
þ÷þüûúùø	÷

ö*ý
þ
ý
ü
	ÿÿþÚ__main__)r   Úheaderé   )rE   rD   Úmain)rh   rE   é
   Úfooter)rD   rE   Úside)rE   Úbodyé   )rE   rh   ÚcontentÚs2Útopr=   ÚbottomÚleft1Úleft2ÚfooN)@Úabcr   r   Ú	itertoolsr   Úoperatorr   Ú	threadingr   Útypingr   r   r	   r
   r   r   r   r   r   Ú_ratior   Úalignr   r9   r   r   r   r   rG   r   Úpanelr   Úprettyr   Úreprr   r   r"   r   Úsegmentr   r4   r   rŽ   r    r!   rÈ   rÇ   Ú	Exceptionr-   r0   r1   rJ   rS   rc   r+   r$   Úpip._vendor.rich.consoler3   r�   r›   r‰   rŸ   Úprintr)   r)   r)   r*   Ú<module>   s`    ,  



ýÿ è