o 7]h6@sxddlmZmZddlmZddlmZddlmZddl m Z m Z m Z m Z mZmZmZmZmZddlmZddlmZdd lmZmZmZmZdd lmZdd lmZdd l m!Z!dd l"m#Z#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*e r|ddl+m,Z,GdddeZ-e de&fZ.e de-fZ/Gddde0Z1Gddde1Z2GdddZ3GdddeZ4Gddde4Z5Gdd d e4Z6e#Gd!ddZ7e8d"kr:dd#l9mZeZe7Z:e:;e7d$d%d&e7dd'd(e7d)d*d+e:d'd8e?e:d9Sd9S):)ABCabstractmethod)islice) itemgetter)RLock) TYPE_CHECKINGDictIterableList NamedTupleOptionalSequenceTupleUnion) ratio_resolve)Align)ConsoleConsoleOptionsRenderableType RenderResult)ReprHighlighter)Panel)Pretty) rich_reprResult)Region)Segment) StyleTypeTreec@s*eZdZUdZeed<eeeed<dS) LayoutRenderzAn individual layout render.regionrenderN)__name__ __module__ __qualname____doc__r__annotations__r rr)r)9/usr/lib/python3/dist-packages/pip/_vendor/rich/layout.pyr! s r!Layoutc@eZdZdZdS) LayoutErrorzLayout related error.Nr$r%r&r'r)r)r)r*r-+r-c@r,) NoSplitterz"Requested splitter does not exist.Nr.r)r)r)r*r0/r/r0c@sDeZdZdZeZddddeddfdd Zd ed e de fd d Z dS) _Placeholderz4An internal renderable used as a Layout placeholder.layoutr+stylereturnNcCs||_||_dSN)r3r4)selfr3r4r)r)r*__init__8s z_Placeholder.__init__consoleoptionsccsx|j}|jp |jj}|j}|jr|jd|d|dnd|d|d}ttjt|dd|j | |ddVdS) Nz (z x )(middle)verticalblue)r4title border_style) max_widthheightsizer3namerrcenterrr4 highlighter)r7r9r:widthrCr3r@r)r)r*__rich_console__<s z_Placeholder.__rich_console__)r2) r$r%r&r'rrGrr8rrrrIr)r)r)r*r13sr1c @sZeZdZUdZdZeed<edefddZede dd e de e de ffd d Z d S) SplitterzBase class for a splitter.r2rEr5cCdS)z(Get the icon (emoji) used in layout.treeNr)r7r)r)r* get_tree_iconTzSplitter.get_tree_iconchildrenr+r"cCrK)zDivide a region amongst several child layouts. Args: children (Sequence(Layout)): A number of child layouts. region (Region): A rectangular region to divide. Nr))r7rOr"r)r)r*divideXrNzSplitter.divideN)r$r%r&r'rEstrr(rrMr rr rrPr)r)r)r*rJOs  rJc @HeZdZdZdZdefddZdeddede e deffd d Z d S) RowSplitterz!Split a layout region in to rows.rowr5cCrK)Nu[layout.tree.row]⬌r)rLr)r)r*rMizRowSplitter.get_tree_iconrOr+r"c csX|\}}}}t||}d}t} t||D]\} } | | |||| |fV|| 7}qdSNrrrzip) r7rOr"xyrHrC render_widthsoffset_Regionchild child_widthr)r)r*rPl   zRowSplitter.divideN r$r%r&r'rErQrMr rr rrPr)r)r)r*rSdrSc @rR) ColumnSplitterz$Split a layout region in to columns.columnr5cCrK)Nu[layout.tree.column]⬍r)rLr)r)r*rM}rUzColumnSplitter.get_tree_iconrOr+r"c csX|\}}}}t||}d}t} t||D]\} } | | ||||| fV|| 7}qdSrVrW) r7rOr"rYrZrHrCrender_heightsr\r]r^ child_heightr)r)r*rPr`zColumnSplitter.divideNrar)r)r)r*rcxrbrcc@seZdZdZeedZ d=ddddddddeedee d ee d e d e d e d ee ddfddZ de fddZedefddZededfddZedefddZde dedfddZde ddfddZed>ddZd d!d"edefd#eee fddfd$d%Zd"edefddfd&d'Zd"edefddfd(d)Zd"edefddfd*d+Zd?d,d-Zdeddfd.d/Zd0d1d2e ddfd3d4Z d5e d e de!fd6d7Z"d0e#d8e$defd9d:Z%d0e#d8e$de&fd;d<Z'dS)@r+aBA 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. )rTrdNrT)rErD minimum_sizeratiovisiblerC renderablerErDrgrhrirCr5cCsX|pt||_||_||_||_||_||_||_|jd|_ g|_ i|_ t |_ dS)Nrd)r1 _renderablerDrgrhrErirC splitterssplitter _children _render_mapr_lock)r7rjrErDrgrhrirCr)r)r*r8s  zLayout.__init__ccs>d|jdfVd|jdfVd|jdfVd|jdfVdS)NrErDrgrrh)rErDrgrhrLr)r)r* __rich_repr__s zLayout.__rich_repr__cCs|jr|S|jS)zLayout renderable.)rnrkrLr)r)r*rjzLayout.renderablecCsdd|jDS)zGets (visible) layout children.cSsg|]}|jr|qSr))ri).0r^r)r)r* sz#Layout.children..rnrLr)r)r*rOrrzLayout.childrencCs|jS)zGet a map of the last render.)rorLr)r)r*mapsz Layout.mapcCs8|j|kr|S|jD]}||}|dur|Sq dS)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)rErnget)r7rEr^ named_layoutr)r)r*rws   z Layout.getcCs$||}|durtd||S)NzNo layout with name )rwKeyError)r7rEr3r)r)r* __getitem__s zLayout.__getitem__r cszddlmddlmddlm}dddffdd |}||d |jjd d }dfdd |||S)z/Get a tree renderable to show layout structure.r)Styled)Tablerr3r+r5csF|j}jdd}|jrt|nt|d}||||}|S)N)rrrr)paddingdim)rmrMgridriradd_row)r3icontabletext_summary)r{r|r)r*summarys   zLayout.tree..summary layout.tree.T) guide_style highlighttreer Ncs2|jD]}|j|d|jjd|qdS)Nr)r)rnaddrmrE)rr3r^)recurserr)r*rs  zLayout.tree..recurse)rr r3r+r5N)pip._vendor.rich.styledr{pip._vendor.rich.tabler|pip._vendor.rich.treer rmrE)r7r r3rr))r{r|rrr*rs      z Layout.treerd)rmlayoutsrmcGs^dd|D}zt|tr|n|j||_Wnty%td|w||jdd<dS)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. cSs"g|] }t|tr |nt|qSr) isinstancer+rsr3r)r)r*rtsz Layout.split..zNo splitter called N)rrJrlrmryr0rn)r7rmr_layoutsr)r)r*splits   z Layout.splitcGsdd|D}|j|dS)zAdd a new layout(s) to existing split. Args: *layouts (Union[Layout, RenderableType]): Positional arguments should be renderables or (sub) Layout instances. css&|]}t|tr |nt|VqdSr6rrr)r)r* 's  z#Layout.add_split..N)rnextend)r7rrr)r)r* add_split szLayout.add_splitcG|j|ddidS)zSplit the layout in tow a row (Layouts side by side). Args: *layouts (Layout): Positional arguments should be (sub) Layout instances. rmrTNrr7rr)r)r* split_row-zLayout.split_rowcGr)zSplit the layout in to a column (layouts stacked on top of each other). Args: *layouts (Layout): Positional arguments should be (sub) Layout instances. rmrdNrrr)r)r* split_column5rzLayout.split_columncCs|jdd=dS)zReset splits to initial state.NrurLr)r)r*unsplit=szLayout.unsplitcCs2|j ||_WddS1swYdS)zjUpdate renderable. Args: renderable (RenderableType): New renderable object. N)rprk)r7rjr)r)r*updateAs"z Layout.updater9r layout_namec Cs|j4||}|j|\}}|\}}}} |||j|| } t|| |j|<|| ||WddS1s:wYdS)zRefresh a sub-layout. Args: console (Console): Console instance where Layout is to be rendered. layout_name (str): Name of layout. N)rpro render_linesr:update_dimensionsr!update_screen_lines) r7r9rr3r"_linesrYrZrHrClinesr)r)r*refresh_screenJs "zLayout.refresh_screenrHc Cs|tdd||fg}|j}|j}g}|j}|r7|||d\}} |j} | r5|j| | D]} || q.|sddt|tddD} | S)z,Create a dict that maps layout on to Region.rcSsi|]\}}||qSr)r)rsr3r"r)r)r* jsz+Layout._make_region_map..r)key)rappendpoprOrmrPsortedr) r7rHrCstackpushrlayout_regionsappend_layout_regionr3r"rOchild_and_region region_mapr)r)r*_make_region_map[s"   zLayout._make_region_mapr:c Csv|j}|jp|j}|||}dd|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 cSsg|] \}}|js||fqSr))rOrr)r)r*rt}s z!Layout.render..) rBrCritemsrrrjrHr!) r7r9r: render_width render_heightrr render_maprrr3r"rr)r)r*r#ps   z Layout.renderccs|jb|jp |j}|jp|j}|||||}||_ddt|D}t}| D]\}} |\} } } } t ||| | | | D] \}}| |qBq-t }|D] }|EdH|VqSWddS1siwYdS)NcSsg|]}gqSr)r))rs_r)r)r*rtsz+Layout.__rich_console__..)rprBrHrCr#rrorangervaluesrXrrline)r7r9r:rHrCr layout_lines_islicer"r_xrZ _layout_width layout_heightrTrnew_line layout_rowr)r)r*rIs*     "zLayout.__rich_console__r6)r5r )r5N)(r$r%r&r'rSrcrlr rrQintboolr8rrqpropertyrjr rO RenderMaprvrwrzrrrJrrrrrrr RegionMaprrrr#rrIr)r)r)r*r+s|    *      __main__)rheader)rErDmain)rhrE footer)rDrEside)rEbody)rErhcontents2topr=bottomleft1left2fooN)@abcrr itertoolsroperatorr threadingrtypingrrr r r r r rr_ratioralignrr9rrrrrGrpanelrprettyrreprrrr"rsegmentrr4rrr r!rr Exceptionr-r0r1rJrSrcr+r$pip._vendor.rich.consoler3rrrrprintr)r)r)r*s`   ,