o
    h6                     @   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# 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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)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)   ]/home/www/facesmatcher.com/frenv_anti/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   sz    |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)ZverticalZblue)r4   titleZborder_styleheight)	max_widthr?   sizer3   namer   r   centerr   r4   highlighter)r7   r9   r:   widthr?   r3   r>   r)   r)   r*   __rich_console__<   s   z_Placeholder.__rich_console__)r2   )r$   r%   r&   r'   r   rD   r   r8   r   r   r   rF   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   rB   r5   c                 C      dS )z(Get the icon (emoji) used in layout.treeNr)   r7   r)   r)   r*   get_tree_iconU       zSplitter.get_tree_iconchildrenr+   r"   c                 C   rH   )zDivide a region amongst several child layouts.

        Args:
            children (Sequence(Layout)): A number of child layouts.
            region (Region): A rectangular region to divide.
        Nr)   )r7   rL   r"   r)   r)   r*   divideY   rK   zSplitter.divideN)r$   r%   r&   r'   rB   strr(   r   rJ   r   r   r	   r   rM   r)   r)   r)   r*   rG   P   s   
 rG   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   rH   )Nu   [layout.tree.row]⬌r)   rI   r)   r)   r*   rJ   j      zRowSplitter.get_tree_iconrL   r+   r"   c                 c   sX    |\}}}}t ||}d}t}	t||D ]\}
}|
|	|| |||fV  ||7 }qd S Nr   r   r   zip)r7   rL   r"   xyrE   r?   Zrender_widthsoffset_RegionchildZchild_widthr)   r)   r*   rM   m      

zRowSplitter.divideNr$   r%   r&   r'   rB   rN   rJ   r   r   r	   r   rM   r)   r)   r)   r*   rP   e       rP   c                	   @   rO   )ColumnSplitterz$Split a layout region in to columns.columnr5   c                 C   rH   )Nu   [layout.tree.column]⬍r)   rI   r)   r)   r*   rJ   ~   rR   zColumnSplitter.get_tree_iconrL   r+   r"   c                 c   sX    |\}}}}t ||}d}t}	t||D ]\}
}|
|	||| ||fV  ||7 }qd S rS   rT   )r7   rL   r"   rV   rW   rE   r?   Zrender_heightsrX   rY   rZ   Zchild_heightr)   r)   r*   rM      r[   zColumnSplitter.divideNr\   r)   r)   r)   r*   r^   y   r]   r^   c                   @   s  e Zd ZdZeedZ	d=dddddddee dee	 d	ee
 d
e
de
d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d/d0d1e	ddfd2d3Z d4e
d5e
de!fd6d7Z"d/e#d8e$defd9d:Z%d/e#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.
    )rQ   r_   Nr   T)rB   rA   minimum_sizeratiovisible
renderablerB   rA   r`   ra   rb   r5   c                C   sR   |pt | | _|| _|| _|| _|| _|| _| jd  | _g | _	i | _
t | _d S )Nr_   )r1   _renderablerA   r`   ra   rB   rb   	splitterssplitter	_children_render_mapr   _lock)r7   rc   rB   rA   r`   ra   rb   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 )NrB   rA   r`   r   ra   )rB   rA   r`   ra   rI   r)   r)   r*   __rich_repr__   s
   zLayout.__rich_repr__c                 C   s   | j r| S | jS )zLayout renderable.)rg   rd   rI   r)   r)   r*   rc         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   rI   r)   r)   r*   rL      rk   zLayout.childrenc                 C   s   | j S )zGet a map of the last render.)rh   rI   r)   r)   r*   map   s   z
Layout.mapc                 C   s8   | j |kr| S | jD ]}||}|dur|  S q
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)rB   rg   get)r7   rB   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)r7   rB   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   )paddingZdim)rf   rJ   Zgridrb   r   Zadd_row)r3   ZicontabletextZ_summary)rs   rt   r)   r*   summary   s   
zLayout.tree.<locals>.summarylayout.tree.T)guide_styleZ	highlighttreer    Nc                    s2   |j D ]} | j|d|jj d| qd S )Nry   )rz   )rg   addrf   rB   )r{   r3   rZ   )recurserx   r)   r*   r}      s   
zLayout.tree.<locals>.recurse)r{   r    r3   r+   r5   N)Zpip._vendor.rich.styledrs   Zpip._vendor.rich.tablert   pip._vendor.rich.treer    rf   rB   )r7   r    r3   r{   r)   )rs   rt   r}   rx   r*   r{      s   

zLayout.treer_   )rf   layoutsrf   c                G   s^   dd |D }zt |tr|n| j|  | _W n ty%   td|w || 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+   rl   r3   r)   r)   r*   rm     s    z Layout.split.<locals>.<listcomp>zNo splitter called N)r   rG   re   rf   rq   r0   rg   )r7   rf   r   _layoutsr)   r)   r*   split  s   
zLayout.splitc                 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 r6   r   r   r)   r)   r*   	<genexpr>%  s
    
z#Layout.add_split.<locals>.<genexpr>N)rg   extend)r7   r   r   r)   r)   r*   	add_split  s   zLayout.add_splitc                 G      | 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.
        rf   rQ   Nr   r7   r   r)   r)   r*   	split_row+     zLayout.split_rowc                 G   r   )zSplit 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_column3  r   zLayout.split_columnc                 C   s   | j dd= dS )zReset splits to initial state.Nrn   rI   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)ri   rd   )r7   rc   r)   r)   r*   update?  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 )zRefresh a sub-layout.

        Args:
            console (Console): Console instance where Layout is to be rendered.
            layout_name (str): Name of layout.
        N)ri   rh   render_linesr:   update_dimensionsr!   Zupdate_screen_lines)r7   r9   r   r3   r"   _linesrV   rW   rE   r?   linesr)   r)   r*   refresh_screenH  s   "zLayout.refresh_screenrE   r?   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)   rl   r3   r"   r)   r)   r*   
<dictcomp>h  s    z+Layout._make_region_map.<locals>.<dictcomp>r   )key)r   appendpoprL   rf   rM   sortedr   )r7   rE   r?   stackpushr   layout_regionsZappend_layout_regionr3   r"   rL   Zchild_and_region
region_mapr)   r)   r*   _make_region_mapY  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 )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)   )rL   r   r)   r)   r*   rm   {  s    z!Layout.render.<locals>.<listcomp>)	r@   r?   r   itemsr   r   rc   rE   r!   )r7   r9   r:   Zrender_widthZrender_heightr   r   
render_mapr   r   r3   r"   r   r)   r)   r*   r#   n  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)   )rl   _r)   r)   r*   rm     s    z+Layout.__rich_console__.<locals>.<listcomp>)ri   r@   rE   r?   r#   r   rh   ranger   valuesrU   r   r   line)r7   r9   r:   rE   r?   r   Zlayout_lines_islicer"   r   _xrW   Z_layout_widthZlayout_heightrQ   r   new_lineZ
layout_rowr)   r)   r*   rF     s*   
"zLayout.__rich_console__r6   )r5   r    )r5   N)(r$   r%   r&   r'   rP   r^   re   r   r   rN   intboolr8   r   rj   propertyrc   r
   rL   	RenderMapro   rp   rr   r{   r   rG   r   r   r   r   r   r   r   	RegionMapr   r   r   r#   r   rF   r)   r)   r)   r*   r+      sv    
	
)



	__main__)r   header   )rB   rA   main)ra   rB   
   footer)rA   rB   Zside)rB   body   )rB   ra   contents2topr=   ZbottomZleft1Zleft2ZfooN)@abcr   r   	itertoolsr   operatorr   	threadingr   typingr   r   r	   r
   r   r   r   r   r   Z_ratior   Zalignr   r9   r   r   r   r   rD   r   Zpanelr   prettyr   r"   r   reprr   r   segmentr   r4   r   r~   r    r!   r   r   	Exceptionr-   r0   r1   rG   rP   r^   r+   r$   Zpip._vendor.rich.consoler3   r   r   r{   r   printr)   r)   r)   r*   <module>   s`    ,  



 