a
    hbòfà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#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�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)Ú	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)   úT/home/httpd/docs/test/DocsMgr/lib/python3.9/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   sv   |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)Ú	max_widthÚheightÚsizer1   Únamer   r   Úcenterr   r2   Úhighlighter)r5   r8   r9   ÚwidthrB   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_iconT   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*   ÚdivideX   s    zSplitter.divideN)r$   r%   r&   r'   rD   Ústrr(   r   rL   r   r   r	   r   rO   r)   r)   r)   r*   rI   O   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   i   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   rB   Zrender_widthsÚoffsetÚ_RegionÚchildÚchild_widthr)   r)   r*   rO   l   s    
zRowSplitter.divideN©r$   r%   r&   r'   rD   rP   rL   r   r   r	   r   rO   r)   r)   r)   r*   rQ   d   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   rB   Zrender_heightsrX   rY   rZ   Úchild_heightr)   r)   r*   rO   €   s    
zColumnSplitter.divideNr\   r)   r)   r)   r*   r]   x   s   þr]   c                   @   s¬  e Zd ZdZeedœZd8dddddddœee 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ÚvisiblerB   )Ú
renderablerD   rC   r`   ra   rb   rB   r3   c                C   sX   |p
t | ƒ| _|| _|| _|| _|| _|| _|| _| jd ƒ | _	g | _
i | _tƒ | _d S )Nr^   )r/   Ú_renderablerC   r`   ra   rD   rb   rB   Ú	splittersÚsplitterÚ	_childrenÚ_render_mapr   Ú_lock)r5   rc   rD   rC   r`   ra   rb   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>À   ó    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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)rD   rg   Úget)r5   rD   rZ   Znamed_layoutr)   r)   r*   rp   Ç   s    	



z
Layout.getc                 C   s$   |   |¡}|d u r td|›�ƒ‚|S )NzNo layout with name )rp   Ú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)rs   rt   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.styledrs   Úpip._vendor.rich.tablert   Úpip._vendor.rich.treer    rf   rD   )r5   r    r1   r€   r)   )rs   rt   r‚   r|   r*   r€   ß   s    ý

zLayout.treer^   )rf   )Úlayoutsrf   r3   c                G   sb   dd„ |D ƒ}z t |tƒr|n
| j| ƒ | _W n  tyN   td|›�ƒ‚Y n0 || 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   rq   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 tow 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_column5  s    zLayout.split_columnc                 C   s   | j dd…= dS )zReset splits to initial state.Nrn   rK   r)   r)   r*   Úunsplit=  s    zLayout.unsplit)rc   r3   c                 C   s0   | j � || _W d  ƒ n1 s"0    Y  dS )zjUpdate renderable.

        Args:
            renderable (RenderableType): New renderable object.
        N)ri   rd   )r5   rc   r)   r)   r*   ÚupdateA  s    zLayout.updater   )r8   Úlayout_namer3   c                 C   s€   | j �f | | }| j| \}}|\}}}}	| ||j ||	¡¡}
t||
ƒ| j|< | |
||¡ W d  ƒ n1 sr0    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)ri   rh   Úrender_linesr9   Úupdate_dimensionsr!   Úupdate_screen_lines)r5   r8   r”   r1   r"   Ú_linesrV   rW   rG   rB   Úlinesr)   r)   r*   Úrefresh_screenJ  s    ÿzLayout.refresh_screen)rG   rB   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>j  s   ÿz+Layout._make_region_map.<locals>.<dictcomp>r   )Úkey)r   ÚappendÚpoprN   rf   rO   Úsortedr   )r5   rG   rB   ÚstackÚpushr    Úlayout_regionsZappend_layout_regionr1   r"   rN   Zchild_and_regionÚ
region_mapr)   r)   r*   Ú_make_region_map[  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>)	rA   rB   r¦   Úitemsr•   r–   rc   rG   r!   )r5   r8   r9   Úrender_widthZrender_heightr¥   r¤   Ú
render_mapr•   r–   r1   r"   r™   r)   r)   r*   r#   p  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 d   ƒ n1 sÎ0    Y  d S )Nc                 S   s   g | ]}g ‘qS r)   r)   )rk   Ú_r)   r)   r*   rl   •  rm   z+Layout.__rich_console__.<locals>.<listcomp>)ri   rA   rG   rB   r#   r–   rh   Úranger   ÚvaluesrU   rŒ   r   Úline)r5   r8   r9   rG   rB   r©   Zlayout_linesÚ_islicer"   r™   Ú_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   Ú	RenderMapro   rp   rr   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   Úreprr   r   r"   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\   ,  



ýÿ 