U
    EZh$                     @   s"  d dl mZmZmZmZ ddlmZ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mZ dd	lmZ eeeeef ZG d
d deZedkr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& e&ddgdZ'e'j(dddd e'j(ddd e'j(dddd e')d d!d" e')d#d$d% e')d&d'd( e')d)d*d+ d,Z*e$e*d-d.dd/Z+e d0Z,ed1ddd2Z-e-j.d3d4d5Z/e/j.d6d7d5Z0e0.ed8e+ e0.ed9e"e,dd: e/j.d;d<d5Z1de1_2e"j3d=d4d:Z4e1.ed>e4 e1.ed?e' e	 Ze5e- d@S )A    )IteratorListOptionalTuple   )
loop_first	loop_last)ConsoleConsoleOptionsRenderableTypeRenderResult)JupyterMixin)Measurement)Segment)Style
StyleStack	StyleType)Styledc                	   @   s   e Zd ZdZdZdddgZdddd	d	d
eeeeeeddddZ	dddd	dee
e e
e ee
e d dddZddddddZddddddZdS )Treea  A renderable for a tree structure.

    Attributes:
        ASCII_GUIDES (GuideType): Guide lines used when Console.ascii_only is True.
        TREE_GUIDES (List[GuideType, GuideType, GuideType]): Default guide lines.

    Args:
        label (RenderableType): The renderable or str for the tree label.
        style (StyleType, optional): Style of this tree. Defaults to "tree".
        guide_style (StyleType, optional): Style of the guide lines. Defaults to "tree.line".
        expanded (bool, optional): Also display children. Defaults to True.
        highlight (bool, optional): Highlight renderable (if str). Defaults to False.
        hide_root (bool, optional): Hide the root node. Defaults to False.
    )    z|   z+-- z`-- )r   u   │   u
   ├── u
   └── )r   u   ┃   u
   ┣━━ u
   ┗━━ )r   u   ║   u
   ╠══ u
   ╚══ treez	tree.lineTF)styleguide_styleexpanded	highlight	hide_rootN)labelr   r   r   r   r   returnc                C   s.   || _ || _|| _g | _|| _|| _|| _d S N)r   r   r   childrenr   r   r   )selfr   r   r   r   r   r    r!   9/tmp/pip-unpacked-wheel-36xvkur8/pip/_vendor/rich/tree.py__init__%   s    
zTree.__init__r   r   r   r   )r   r   r   r   r   r   c                C   sL   t ||dkr| jn||dkr"| jn|||dkr4| jn|d}| j| |S )a3  Add a child tree.

        Args:
            label (RenderableType): The renderable or str for the tree label.
            style (StyleType, optional): Style of this tree. Defaults to "tree".
            guide_style (StyleType, optional): Style of the guide lines. Defaults to "tree.line".
            expanded (bool, optional): Also display children. Defaults to True.
            highlight (Optional[bool], optional): Highlight renderable (if str). Defaults to False.

        Returns:
            Tree: A new child Tree, which may be further modified.
        Nr$   )r   r   r   r   r   append)r    r   r   r   r   r   noder!   r!   r"   add7   s    zTree.addr	   r
   r   )consoleoptionsr   c                 #   s  g }|j }|j}t }|j}t }|jddp6|}	td\}
}}}t t	ttd fdd}|||	g}|t
tg t|j}t|j}tddd}d	}|r| }zt|\}}W nT tk
r    |   |r|d
 jp|}	|||	|d
< |   |   Y qY nX || |rJ|||d
 jpB||d
< |j||j }	|j||j }|jrxdndd  }|jt|j|jjtdd |D  jd djd k	d}|d	krԈjsFt|D ]h\}}|r j||j|dE d H  |E d H  |V  |r|r||r*|
n||d
 jp:||d
< q|jr|jr||r^|
n||d
 jpn||d
< ||t|jdkr|n||	 | ||j | ||j |t
t|j |d7 }qd S )N )default   )indexr   r   c                    sL   j rj|  }n0|jrdn|jr&dnd}jjr8dn| |  } ||S )z.Make a Segment for a level of the guide lines.r      r   )Z
ascii_onlyASCII_GUIDESbold
underline2TREE_GUIDESZlegacy_windows)r-   r   lineZguideZ_Segmentr)   r    r!   r"   
make_guidee   s
    z)Tree.__rich_console__.<locals>.make_guideF)r0   r1   r   r.   r   c                 s   s   | ]}|j V  qd S r   )Zcell_length).0levelr!   r!   r"   	<genexpr>   s     z(Tree.__rich_console__.<locals>.<genexpr>)widthr   height)pad)Z
post_style)!popr%   r   r3   	get_styler   nullr   rangeintiterr   r   r   nextStopIterationcurrentr   Zrender_linesr   r   update	max_widthsumr   justifyr   Zapply_styleZbackground_styler   r   lenpush)r    r(   r)   stackr=   rK   new_liner>   Z
null_styler   SPACECONTINUEZFORKZENDr5   levelsZguide_style_stackZstyle_stackZremove_guide_stylesdepthZ
stack_nodelastr&   r   prefixZrenderable_linesfirstr3   r!   r4   r"   __rich_console__V   s    	


  zTree.__rich_console__r   c                 C   s   t | gg}|j}|j}d}d}tj}d}	|r| }
zt|
}W n  tk
r`   |	d8 }	Y q*Y nX ||
 ||||j\}}|	d }t|| |}t|| |}|j	r*|j
r*|t |j
 |	d7 }	q*t||S )Nr   r   r,   )rB   r=   r%   r   getrC   rD   r   maxr   r   )r    r(   r)   rL   r=   rK   Zminimummaximummeasurer8   Z	iter_treer   Zmin_measureZmax_measureindentr!   r!   r"   __rich_measure__   s.    

zTree.__rich_measure__)__name__
__module____qualname____doc__r/   r2   r   r   boolr#   r   r'   rU   r[   r!   r!   r!   r"   r      sP   
  [ r   __main__)Group)Markdown)Panel)Syntax)Tabler*   Zdim)Z
row_stylesZReleasedZcyanT)r   Zno_wrapZTitleZmagenta)r   z
Box OfficerightZgreen)rI   r   zDec 20, 2019z Star Wars: The Rise of Skywalkerz$952,110,690zMay 25, 2018zSolo: A Star Wars Storyz$393,151,347zDec 15, 2017z!Star Wars Ep. V111: The Last Jediz$1,332,539,889zDec 16, 2016zRogue One: A Star Wars Storyz$1,332,439,889zmclass Segment(NamedTuple):
    text: str = ""
    style: Optional[Style] = None
    is_control: bool = False
pythonZmonokai)ZthemeZline_numbersz=### example.md
> Hello, World!
>
> Markdown _all_ the things
u   🌲 [b green]Rich Tree)r   r   z:file_folder: RenderablesZred)r   z!:file_folder: [bold yellow]Atomiczuu greenu   📄 Syntaxu   📄 Markdown)Zborder_stylez&:file_folder: [bold magenta]Containerszbold magentazJust a panelu   📄 Panelsu   📄 [b magenta]TableN)6typingr   r   r   r   Z_loopr   r   r(   r	   r
   r   r   Zjupyterr   rY   r   segmentr   r   r   r   r   Zstyledr   strZ	GuideTyper   r\   Zpip._vendor.rich.consolerb   Zpip._vendor.rich.markdownrc   Zpip._vendor.rich.panelrd   Zpip._vendor.rich.syntaxre   Zpip._vendor.rich.tablerf   tableZ
add_columnZadd_rowcodeZsyntaxZmarkdownrootr'   r&   Zsimple_nodeZcontainers_noder   ZfitZpanelprintr!   r!   r!   r"   <module>   sX    ?
	 