o
    a+)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)   VC:\Users\User\Downloads\Proyecto_IoT\venv\Lib\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)verticalblue)r4   titleborder_styleheight)	max_widthrB   sizer3   namer   r   centerr   r4   highlighter)r7   r9   r:   widthrB   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_iconU       zSplitter.get_tree_iconchildrenr+   r"   c                 C   rK   )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   rO   r"   r)   r)   r*   divideY   rN   zSplitter.divideN)r$   r%   r&   r'   rE   strr(   r   rM   r   r   r	   r   rP   r)   r)   r)   r*   rJ   P   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   j      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   rB   Zrender_widthsoffset_Regionchildchild_widthr)   r)   r*   rP   m      

zRowSplitter.divideNr$   r%   r&   r'   rE   rQ   rM   r   r   r	   r   rP   r)   r)   r)   r*   rS   e       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   rB   Zrender_heightsr[   r\   r]   child_heightr)   r)   r*   rP      r_   zColumnSplitter.divideNr`   r)   r)   r)   r*   rb   y   ra   rb   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.
    )rT   rc   Nr   T)rE   rD   minimum_sizeratiovisible
renderablerE   rD   re   rf   rg   r5   c                C   sR   |pt | | _|| _|| _|| _|| _|| _| jd  | _g | _	i | _
t | _d S )Nrc   )r1   _renderablerD   re   rf   rE   rg   	splitterssplitter	_children_render_mapr   _lock)r7   rh   rE   rD   re   rf   rg   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   re   r   rf   )rE   rD   re   rf   rL   r)   r)   r*   __rich_repr__   s
   zLayout.__rich_repr__c                 C   s   | j r| S | jS )zLayout renderable.)rl   ri   rL   r)   r)   r*   rh         zLayout.renderablec                 C   s   dd | j D S )zGets (visible) layout children.c                 S   s   g | ]}|j r|qS r)   )rg   ).0r]   r)   r)   r*   
<listcomp>   s    z#Layout.children.<locals>.<listcomp>rl   rL   r)   r)   r*   rO      rp   zLayout.childrenc                 C   s   | j S )zGet a map of the last render.)rm   rL   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)rE   rl   get)r7   rE   r]   Znamed_layoutr)   r)   r*   ru      s   
	

z
Layout.getc                 C   s$   |  |}|d u rtd||S )NzNo layout with name )ru   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)rk   rM   gridrg   r   add_row)r3   icontabletextZ_summary)rx   ry   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   )rl   addrk   rE   )r   r3   r]   )recurser   r)   r*   r      s   
zLayout.tree.<locals>.recurse)r   r    r3   r+   r5   N)Zpip._vendor.rich.styledrx   pip._vendor.rich.tablery   pip._vendor.rich.treer    rk   rE   )r7   r    r3   r   r)   )rx   ry   r   r   r*   r      s   

zLayout.treerc   )rk   layoutsrk   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+   rq   r3   r)   r)   r*   rr     s    z Layout.split.<locals>.<listcomp>zNo splitter called N)r   rJ   rj   rk   rv   r0   rl   )r7   rk   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)rl   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.
        rk   rT   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.
        rk   rc   Nr   r   r)   r)   r*   split_column4  r   zLayout.split_columnc                 C   s   | j dd= dS )zReset splits to initial state.Nrs   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)rn   ri   )r7   rh   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)rn   rm   render_linesr:   update_dimensionsr!   update_screen_lines)r7   r9   r   r3   r"   _linesrY   rZ   rH   rB   linesr)   r)   r*   refresh_screenI  s   "zLayout.refresh_screenrH   rB   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)   rq   r3   r"   r)   r)   r*   
<dictcomp>i  s    z+Layout._make_region_map.<locals>.<dictcomp>r   )key)r   appendpoprO   rk   rP   sortedr   )r7   rH   rB   stackpushr   layout_regionsZappend_layout_regionr3   r"   rO   Zchild_and_region
region_mapr)   r)   r*   _make_region_mapZ  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)   )rO   r   r)   r)   r*   rr   |  s    z!Layout.render.<locals>.<listcomp>)	rC   rB   r   itemsr   r   rh   rH   r!   )r7   r9   r:   render_widthrender_heightr   r   
render_mapr   r   r3   r"   r   r)   r)   r*   r#   o  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)   )rq   _r)   r)   r*   rr     s    z+Layout.__rich_console__.<locals>.<listcomp>)rn   rC   rH   rB   r#   r   rm   ranger   valuesrX   r   r   line)r7   r9   r:   rH   rB   r   Zlayout_lines_islicer"   r   Z_xrZ   Z_layout_widthZlayout_heightrT   r   new_lineZ
layout_rowr)   r)   r*   rI     s*   
"zLayout.__rich_console__r6   )r5   r    )r5   N)(r$   r%   r&   r'   rS   rb   rj   r   r   rQ   intboolr8   r   ro   propertyrh   r
   rO   	RenderMaprt   ru   rw   r   r   rJ   r   r   r   r   r   r   r   	RegionMapr   r   r   r#   r   rI   r)   r)   r)   r*   r+      sv    
	
*



	__main__)r   header   )rE   rD   main)rf   rE   
   footer)rD   rE   Zside)rE   body   )rE   rf   contents2topr=   bottomZleft1Zleft2Z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   r"   r   reprr   r   segmentr   r4   r   r   r    r!   r   r   	Exceptionr-   r0   r1   rJ   rS   rb   r+   r$   pip._vendor.rich.consoler3   r   r   r   r   printr)   r)   r)   r*   <module>   s`    ,  



 