B
    od6                 @   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
rd 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(   I/var/www/html/venv/lib/python3.7/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.N)r#   r$   r%   r&   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)r/   r0   )selfr/   r0   r(   r(   r)   __init__8   s    z_Placeholder.__init__)consoleoptionsr1   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)r0   titleborder_styleheight)	max_widthr=   sizer/   namer   r   centerr   r0   highlighter)r2   r4   r5   widthr=   r/   r;   r(   r(   r)   __rich_console__<   s    z_Placeholder.__rich_console__)r.   )r#   r$   r%   r&   r   rB   r   r3   r   r   r   rD   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.r.   r@   )r1   c             C   s   dS )z(Get the icon (emoji) used in layout.treeNr(   )r2   r(   r(   r)   get_tree_iconU   s    zSplitter.get_tree_iconr*   )childrenr!   r1   c             C   s   dS )zDivide a region amongst several child layouts.

        Args:
            children (Sequence(Layout)): A number of child layouts.
            region (Region): A rectangular region to divide.
        Nr(   )r2   rG   r!   r(   r(   r)   divideY   s    	zSplitter.divideN)r#   r$   r%   r&   r@   strr'   r   rF   r   r   r	   r   rH   r(   r(   r(   r)   rE   P   s   
rE   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.row)r1   c             C   s   dS )Nu   [layout.tree.row]⬌r(   )r2   r(   r(   r)   rF   j   s    zRowSplitter.get_tree_iconr*   )rG   r!   r1   c             c   sZ   |\}}}}t ||}d}t}	x6t||D ](\}
}|
|	|| |||fV  ||7 }q*W d S )Nr   )r   r   zip)r2   rG   r!   xyrC   r=   Zrender_widthsoffset_Regionchildchild_widthr(   r(   r)   rH   m   s    
zRowSplitter.divideN)r#   r$   r%   r&   r@   rI   rF   r   r   r	   r   rH   r(   r(   r(   r)   rJ   e   s
   rJ   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.column)r1   c             C   s   dS )Nu   [layout.tree.column]⬍r(   )r2   r(   r(   r)   rF   ~   s    zColumnSplitter.get_tree_iconr*   )rG   r!   r1   c             c   sZ   |\}}}}t ||}d}t}	x6t||D ](\}
}|
|	||| ||fV  ||7 }q*W d S )Nr   )r   r   rL   )r2   rG   r!   rM   rN   rC   r=   Zrender_heightsrO   rP   rQ   child_heightr(   r(   r)   rH      s    
zColumnSplitter.divideN)r#   r$   r%   r&   r@   rI   rF   r   r   r	   r   rH   r(   r(   r(   r)   rS   y   s
   rS   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.
    )rK   rT   Nr   T)r@   r?   minimum_sizeratiovisible)
renderabler@   r?   rV   rW   rX   r1   c            C   sR   |p
t | | _|| _|| _|| _|| _|| _| jd  | _g | _	i | _
t | _d S )NrT   )r-   _renderabler?   rV   rW   r@   rX   	splitterssplitter	_children_render_mapr   _lock)r2   rY   r@   r?   rV   rW   rX   r(   r(   r)   r3      s    
zLayout.__init__)r1   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 )Nr@   r?   rV   r   rW   )r@   r?   rV   rW   )r2   r(   r(   r)   __rich_repr__   s    zLayout.__rich_repr__c             C   s   | j r
| S | jS )zLayout renderable.)r]   rZ   )r2   r(   r(   r)   rY      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(   )rX   ).0rQ   r(   r(   r)   
<listcomp>   s    z#Layout.children.<locals>.<listcomp>)r]   )r2   r(   r(   r)   rG      s    zLayout.childrenc             C   s   | j S )zGet a map of the last render.)r^   )r2   r(   r(   r)   map   s    z
Layout.map)r@   r1   c             C   s8   | j |kr| S x$| jD ]}||}|dk	r|S qW dS )zGet 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)r@   r]   get)r2   r@   rQ   Znamed_layoutr(   r(   r)   rd      s    	

z
Layout.getc             C   s$   |  |}|d kr td||S )NzNo layout with name )rd   KeyError)r2   r@   r/   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)Table)r   r*   )r/   r1   c                sF   | j  }jdd}| jr$t| n t| d}||| |}|S )N)r   r   r   r   )paddingdim)r\   rF   gridrX   r   add_row)r/   icontabletextZ_summary)rg   rh   r(   r)   summary   s    
zLayout.tree.<locals>.summaryzlayout.tree.T)guide_style	highlightr   N)treer/   r1   c                s6   x0|j D ]&} | j|d|jj d| qW d S )Nzlayout.tree.)rq   )r]   addr\   r@   )rs   r/   rQ   )recurserp   r(   r)   ru      s    zLayout.tree.<locals>.recurse)Zpip._vendor.rich.styledrg   pip._vendor.rich.tablerh   pip._vendor.rich.treer   r\   r@   )r2   r   r/   rs   r(   )rg   rh   ru   rp   r)   rs      s    

zLayout.treerT   )r\   )layoutsr\   r1   c            G   sd   dd |D }y t |tr|n
| j|  | _W n" tk
rP   td|Y nX || jdd< dS )zSplit 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*   )ra   r/   r(   r(   r)   rb     s   z Layout.split.<locals>.<listcomp>zNo splitter called N)ry   rE   r[   r\   re   r,   r]   )r2   r\   rx   _layoutsr(   r(   r)   split  s    zLayout.split)rx   r1   c             G   s   dd |D }| j | dS )zAdd 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 )N)ry   r*   )ra   r/   r(   r(   r)   	<genexpr>'  s   z#Layout.add_split.<locals>.<genexpr>N)r]   extend)r2   rx   rz   r(   r(   r)   	add_split  s    zLayout.add_splitc             G   s   | j |ddi dS )zSplit the layout in to a row (layouts side by side).

        Args:
            *layouts (Layout): Positional arguments should be (sub) Layout instances.
        r\   rK   N)r{   )r2   rx   r(   r(   r)   	split_row,  s    zLayout.split_rowc             G   s   | j |ddi dS )zSplit the layout in to a column (layouts stacked on top of each other).

        Args:
            *layouts (Layout): Positional arguments should be (sub) Layout instances.
        r\   rT   N)r{   )r2   rx   r(   r(   r)   split_column4  s    zLayout.split_columnc             C   s   | j dd= dS )zReset splits to initial state.N)r]   )r2   r(   r(   r)   unsplit<  s    zLayout.unsplit)rY   r1   c          	   C   s   | j  || _W dQ R X dS )zjUpdate renderable.

        Args:
            renderable (RenderableType): New renderable object.
        N)r_   rZ   )r2   rY   r(   r(   r)   update@  s    zLayout.updater   )r4   layout_namer1   c          	   C   sl   | j \ | | }| j| \}}|\}}}}	|||j||	}
t||
| j|< ||
|| W dQ R X dS )zRefresh a sub-layout.

        Args:
            console (Console): Console instance where Layout is to be rendered.
            layout_name (str): Name of layout.
        N)r_   r^   render_linesr5   update_dimensionsr    update_screen_lines)r2   r4   r   r/   r!   _linesrM   rN   rC   r=   linesr(   r(   r)   refresh_screenI  s    zLayout.refresh_screen)rC   r=   r1   c             C   s   | t dd||fg}|j}|j}g }|j}xH|rr||  |d \}}	|j}
|
r,x|j|
|	D ]}|| q`W q,W 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(   )ra   r/   r!   r(   r(   r)   
<dictcomp>i  s   z+Layout._make_region_map.<locals>.<dictcomp>r   )key)r   appendpoprG   r\   rH   sortedr   )r2   rC   r=   stackpushr   layout_regionsZappend_layout_regionr/   r!   rG   Zchild_and_region
region_mapr(   r(   r)   _make_region_mapZ  s    
zLayout._make_region_map)r4   r5   r1   c             C   sz   |j }|jp|j}| ||}dd | D }i }|j}|j}	x4|D ],\}
}||
j|	|j|j}t||||
< qFW |S )zRender 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(   )rG   )ra   r/   r!   r(   r(   r)   rb   }  s   z!Layout.render.<locals>.<listcomp>)	r>   r=   r   itemsr   r   rY   rC   r    )r2   r4   r5   render_widthrender_heightr   r   
render_mapr   r   r/   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}xN|	 D ]B\}}	|\}
}}}x,t
||||| |	D ]\}}|| qW qZW t }x|D ]}|E d H  |V  qW W d Q R X d S )Nc             S   s   g | ]}g qS r(   r(   )ra   _r(   r(   r)   rb     s    z+Layout.__rich_console__.<locals>.<listcomp>)r_   r>   rC   r=   r"   r   r^   ranger   valuesrL   r}   r   line)r2   r4   r5   rC   r=   r   Zlayout_lines_islicer!   r   Z_xrN   Z_layout_widthZlayout_heightrK   r   new_lineZ
layout_rowr(   r(   r)   rD     s     

zLayout.__rich_console__)N)(r#   r$   r%   r&   rJ   rS   r[   r   r   rI   intboolr3   r   r`   propertyrY   r
   rG   	RenderMaprc   rd   rf   rs   r   rE   r{   r~   r   r   r   r   r   	RegionMapr   r   r   r"   r   rD   r(   r(   r(   r)   r*      s@   
*	__main__)r   header   )r@   r?   main)rW   r@   
   footer)r?   r@   Zside)r@   body   )r@   rW   contents2topr8   bottomZleft1Zleft2ZfooN)@abcr   r   	itertoolsr   operatorr   	threadingr   typingr   r   r	   r
   r   r   r   r   r   _ratior   alignr   r4   r   r   r   r   rB   r   panelr   prettyr   r!   r   reprr   r   segmentr   r0   r   rw   r   r    r   r   	Exceptionr+   r,   r-   rE   rJ   rS   r*   r#   pip._vendor.rich.consoler/   r   r   rs   r   printr(   r(   r(   r)   <module>   sV   ,  


 