o 7]h#@sddlmZmZmZmZddlmZmZddlm Z m Z m Z m Z ddl mZddlmZddlmZddlmZmZmZdd lmZGd d d eZed kr dd lmZddlmZddlm Z ddl!m"Z"ddl#m$Z$e$ddgdZ%e%j&dddde%j&ddde%j&dddde%'d d!d"e%'d#d$d%e%'d&d'd(e%'d)d*d+d,Z(e"e(d-d.dd/Z)ed0Z*ed1ddd2Z+e+j,d3d4d5Z-e-j,d6d7d5Z.e.,ed8e)e.,ed9e e*dd:e-j,d;de2e/,ed?e%e Ze3e+d@Sd@S)A)IteratorListOptionalTuple) loop_first loop_last)ConsoleConsoleOptionsRenderableType RenderResult) JupyterMixin) Measurement)Segment)Style StyleStack StyleType)Styledc@seZdZdZdddddddeded ed ed ed ed dfddZddddddedeed eed ed ed df ddZ     dddZ     dddZ dS) TreeaA renderable for a tree structure. 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. treez tree.lineTF)style guide_styleexpanded highlight hide_rootlabelrrrrrreturnNcCs.||_||_||_g|_||_||_||_dSN)rrrchildrenrrr)selfrrrrrrr 7/usr/lib/python3/dist-packages/pip/_vendor/rich/tree.py__init__s  z Tree.__init__rrrrcCsLt||dur |jn||dur|jn|||dur|jn|d}|j||S)a3Add 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#)rrrrrappend)rrrrrrnoder r r!add)s zTree.addconsoler optionsr r c#sg}|j}|j}t}|j}t}||jddp|} td\} } } } dgdtdt dtdtffd d }|| | g}|t t |gt ||j}t ||j }td d d }d }|rj|}zt|\}}Wn%ty||r|dj p|} || | |d<||Yqbw|||r|| |dj p||d<|j||j} |j||j }||jrdndd}|t|j|jjtdd|D|jdd}|d kr|jst|D]2\}}|rj||j|dEdH|EdH|V|r|r||r| n| |dj p||d<q|jrf|jrf||r+| n| |dj p3||d<||t|jdkrD| n| | |||j |||j|t t |j|d7}|sedSdS)N)default) z| z+-- z`-- ))r,u│ u ├── u └── )r,u┃ u ┣━━ u ┗━━ )r,u║ u ╠══ u ╚══ indexrrcsHjr|}n|jr dn|jrdnd}jrdn||}||S)z.Make a Segment for a level of the guide lines.rr) ascii_onlybold underline2legacy_windows)r-rlineguide ASCII_GUIDES TREE_GUIDES_Segmentr(r r! make_guide^s   z)Tree.__rich_console__..make_guideF)r0r1rr.rcss|]}|jVqdSr) cell_length).0levelr r r! sz(Tree.__rich_console__..)widthrheight) post_style) popr$rr3 get_stylernullrrangeintiterrrrnext StopIterationcurrentr render_linesrrupdate max_widthsumrr apply_stylebackground_stylerrlenpush)rr'r(stackrBrRnew_linerC null_stylerSPACECONTINUEFORKENDr9levelsguide_style_stack style_stackremove_guide_stylesdepth stack_nodelastr%rprefixrenderable_linesfirstr3r r5r!__rich_console__Hs         zTree.__rich_console__rcCst|gg}|j}|j}d}d}tj}d} |r`|} zt| } Wn ty-| d8} Yqw|| |||| j\} } | d}t| ||}t| ||}| j r^| j r^|t| j | d7} |st||S)Nrrr+) rGrBr$rgetrHrIrmaxrr)rr'r(rSrBrRminimummaximummeasurer= iter_treer min_measure max_measureindentr r r!__rich_measure__s2     zTree.__rich_measure__)r'r r(r rr )r'r r(r rr) __name__ __module__ __qualname____doc__r rboolr"rr&rdrnr r r r!r sj   `r__main__)Group)Markdown)Panel)Syntax)Tabler)dim) row_stylesReleasedcyanT)rno_wrapTitlemagenta)rz Box Officerightgreen)justifyrz Dec 20, 2019z Star Wars: The Rise of Skywalkerz $952,110,690z May 25, 2018zSolo: A Star Wars Storyz $393,151,347z Dec 15, 2017z!Star Wars Ep. V111: The Last Jediz$1,332,539,889z Dec 16, 2016zRogue One: A Star Wars Storyz$1,332,439,889zyclass Segment(NamedTuple): text: str = "" style: Optional[Style] = None is_control: bool = False pythonmonokai)theme line_numbersz>### example.md > Hello, World! > > Markdown _all_ the things u🌲 [b green]Rich Tree)rrz:file_folder: Renderablesred)rz!:file_folder: [bold yellow]Atomiczuu greenu 📄 Syntaxu 📄 Markdown) border_stylez&:file_folder: [bold magenta]Containersz bold magentaz Just a panelu 📄 Panelsu📄 [b magenta]TableN)4typingrrrr_looprrr'r r r r jupyterr rirsegmentrrrrrstyledrrropip._vendor.rich.consolerupip._vendor.rich.markdownrvpip._vendor.rich.panelrwpip._vendor.rich.syntaxrxpip._vendor.rich.tablerytable add_columnadd_rowcodesyntaxmarkdownrootr&r% simple_nodecontainers_noderfitpanelprintr r r r!sX     9