U cf6@stddlmZmZddlmZddlmZddlmZddl m Z m Z m Z m Z mZmZmZmZmZddlmZddlmZdd lmZmZmZmZdd lmZdd lmZdd l m!Z!dd l"m#Z#ddl$m%Z%m&Z&ddl'm(Z(ddl)m*Z*e rddl+m,Z,GdddeZ-e de#fZ.e de-fZ/Gddde0Z1Gddde1Z2GdddZ3GdddeZ4Gddde4Z5Gdd d e4Z6e&Gd!ddZ7e8d"krpdd#l9mZeZe7Z:e:;e7d$d%d&e7dd'd(e7d)d*d+e:d'd8e?e:d9S):)ABCabstractmethod)islice) itemgetter)RLock) TYPE_CHECKINGDictIterableList NamedTupleOptionalSequenceTupleUnion) ratio_resolve)Align)ConsoleConsoleOptionsRenderableType RenderResult)ReprHighlighter)Panel)Pretty)Region)Result rich_repr)Segment) StyleTypeTreec@s*eZdZUdZeed<eeeed<dS) LayoutRenderzAn individual layout render.regionrenderN)__name__ __module__ __qualname____doc__r__annotations__r rr)r)E/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/rich/layout.pyr! s r!Layoutc@seZdZdZdS) LayoutErrorzLayout related error.Nr$r%r&r'r)r)r)r*r,+sr,c@seZdZdZdS) NoSplitterz"Requested splitter does not exist.Nr-r)r)r)r*r./sr.c@s<eZdZdZeZd deddddZee e dd d Z dS) _Placeholderz4An internal renderable used as a Layout placeholder.r+N)layoutstylereturncCs||_||_dSN)r1r2)selfr1r2r)r)r*__init__8sz_Placeholder.__init__consoleoptionsr3ccsx|j}|jp|jj}|j}|jr8|jd|d|dnd|d|d}ttjt|dd|j | |d|dVdS) Nz (z x )(middle)verticalblue)r2title border_styleheight) max_widthrAsizer1namerrcenterrr2 highlighter)r5r8r9widthrAr1r?r)r)r*__rich_console__<sz_Placeholder.__rich_console__)r0) r$r%r&r'rrFrr6rrrrHr)r)r)r*r/3sr/c@sVeZdZUdZdZeed<eedddZee de e e de fdd d Z d S) SplitterzBase class for a splitter.r0rDr3cCsdS)z(Get the icon (emoji) used in layout.treeNr)r5r)r)r* get_tree_iconUszSplitter.get_tree_iconr+childrenr"r3cCsdS)zDivide a region amongst several child layouts. Args: children (Sequence(Layout)): A number of child layouts. region (Region): A rectangular region to divide. Nr))r5rNr"r)r)r*divideYszSplitter.divideN)r$r%r&r'rDstrr(rrLr rr rrOr)r)r)r*rIPs  rIc@sDeZdZdZdZedddZedee e defddd Z d S) RowSplitterz!Split a layout region in to rows.rowrJcCsdS)Nu[layout.tree.row]⬌r)rKr)r)r*rLjszRowSplitter.get_tree_iconr+rMc csV|\}}}}t||}d}t} t||D](\} } | | |||| |fV|| 7}q(dSNrrrzip) r5rNr"xyrGrAZ render_widthsoffset_Regionchild child_widthr)r)r*rOms  zRowSplitter.divideN r$r%r&r'rDrPrLr rr rrOr)r)r)r*rQesrQc@sDeZdZdZdZedddZedee e defddd Z d S) ColumnSplitterz$Split a layout region in to columns.columnrJcCsdS)Nu[layout.tree.column]⬍r)rKr)r)r*rL~szColumnSplitter.get_tree_iconr+rMc csV|\}}}}t||}d}t} t||D](\} } | | ||||| fV|| 7}q(dSrSrT) r5rNr"rVrWrGrAZrender_heightsrXrYrZ child_heightr)r)r*rOs  zColumnSplitter.divideNr\r)r)r)r*r]ysr]c @seZdZdZeedZd8ddddddeeee ee e e e dddd Z e d d d Zeed d dZeedd ddZeed ddZe eddddZe ddddZedd ddZddedefeee fddddZedefdd d!d"Zedefdd d#d$Zedefdd d%d&Zdd d'd(Zedd)d*d+Zd,e dd-d.d/Z e e e!d0d1d2Z"e#e$ed3d4d5Z%e#e$e&d3d6d7Z'dS)9r+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. )rRr^NrT)rDrC minimum_sizeratiovisible) renderablerDrCr`rarbr3cCsR|p t||_||_||_||_||_||_|jd|_g|_ i|_ t |_ dS)Nr^) r/ _renderablerCr`rarDrb splitterssplitter _children _render_mapr_lock)r5rcrDrCr`rarbr)r)r*r6s zLayout.__init__rJccs<d|jdfVd|jdfVd|jdfVd|jdfVdS)NrDrCr`rra)rDrCr`rarKr)r)r* __rich_repr__szLayout.__rich_repr__cCs|jr |S|jS)zLayout renderable.)rgrdrKr)r)r*rcszLayout.renderablecCsdd|jDS)zGets (visible) layout children.cSsg|]}|jr|qSr))rb).0rZr)r)r* sz#Layout.children..rgrKr)r)r*rNszLayout.childrencCs|jS)zGet a map of the last render.)rhrKr)r)r*mapsz Layout.map)rDr3cCs8|j|kr|S|jD]}||}|dk r|SqdS)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)rDrgget)r5rDrZZ named_layoutr)r)r*ros    z Layout.getcCs$||}|dkr td||S)NzNo layout with name )roKeyError)r5rDr1r)r)r* __getitem__s zLayout.__getitem__r csddlmddlmddlm}ddfdd |}||d |jjd d }d dd dfdd |||S)z/Get a tree renderable to show layout structure.r)Styled)Tablerr+)r1r3csF|j}jdd}|jr$t|n t|d}||||}|S)N)rrrr)paddingdim)rfrLgridrbradd_row)r1icontabletextZ_summary)rrrsr)r*summarys   zLayout.tree..summary layout.tree.T) guide_style highlightr N)treer1r3cs2|jD]&}|j|d|jjd|qdS)Nr|)r})rgaddrfrD)rr1rZ)recurser{r)r*rs  zLayout.tree..recurse)Zpip._vendor.rich.styledrrpip._vendor.rich.tablerspip._vendor.rich.treer rfrD)r5r r1rr))rrrsrr{r*rs      z Layout.treer^)rf)layoutsrfr3cGsddd|D}z t|tr|n |j||_Wn"tk rPtd|YnX||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+rkr1r)r)r*rlsz Layout.split..zNo splitter called N)rrIrerfrpr.rg)r5rfr_layoutsr)r)r*splits  z Layout.split)rr3cGsdd|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|VqdSr4rrr)r)r* %sz#Layout.add_split..N)rgextend)r5rrr)r)r* add_splitszLayout.add_splitcGs|j|ddidS)zSplit the layout in to a row (layouts side by side). Args: *layouts (Layout): Positional arguments should be (sub) Layout instances. rfrRNrr5rr)r)r* split_row+szLayout.split_rowcGs|j|ddidS)zSplit the layout in to a column (layouts stacked on top of each other). Args: *layouts (Layout): Positional arguments should be (sub) Layout instances. rfr^Nrrr)r)r* split_column3szLayout.split_columncCs|jdd=dS)zReset splits to initial state.NrmrKr)r)r*unsplit;szLayout.unsplit)rcr3c Cs|j ||_W5QRXdS)zjUpdate renderable. Args: renderable (RenderableType): New renderable object. N)rird)r5rcr)r)r*update?sz Layout.updater)r8 layout_namer3c Csl|j\||}|j|\}}|\}}}} |||j|| } t|| |j|<|| ||W5QRXdS)zRefresh a sub-layout. Args: console (Console): Console instance where Layout is to be rendered. layout_name (str): Name of layout. N)rirh render_linesr9update_dimensionsr!update_screen_lines) r5r8rr1r"_linesrVrWrGrAlinesr)r)r*refresh_screenHs  zLayout.refresh_screen)rGrAr3c Cs|tdd||fg}|j}|j}g}|j}|rl|||d\}} |j} | r*|j| | D] } || q\q*ddt|tddD} | S)z,Create a dict that maps layout on to Region.rcSsi|]\}}||qSr)r)rkr1r"r)r)r* hsz+Layout._make_region_map..r)key)rappendpoprNrfrOsortedr) r5rGrAstackpushrlayout_regionsZappend_layout_regionr1r"rNZchild_and_region region_mapr)r)r*_make_region_mapYs    zLayout._make_region_mapr7c Csv|j}|jp|j}|||}dd|D}i}|j}|j} |D],\} } || j| | j| j} t| | || <qD|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))rNrr)r)r*rl{sz!Layout.render..) rBrAritemsrrrcrGr!) r5r8r9 render_width render_heightrr render_maprrr1r"rr)r)r*r#ns     z Layout.renderc cs|j|jp|j}|jp|j}|||||}||_ddt|D}t}| D]>\}} |\} } } } t ||| | | | D]\}}| |qqXt }|D]}|EdH|VqW5QRXdS)NcSsg|]}gqSr)r))rk_r)r)r*rlsz+Layout.__rich_console__..)rirBrGrAr#rrhrangervaluesrUrrline)r5r8r9rGrArZ layout_lines_islicer"rZ_xrWZ _layout_widthZ layout_heightrRrnew_lineZ layout_rowr)r)r*rHs$     zLayout.__rich_console__)N)(r$r%r&r'rQr]rer rrPintboolr6rrjpropertyrcr rN RenderMaprnrorqrrrIrrrrrrr RegionMaprrrr#rrHr)r)r)r*r+s^  )     __main__)rheader)rDrCmain)rarD footer)rCrDZside)rDbody)rDracontents2topr<bottomZleft1Zleft2ZfooN)@abcrr itertoolsroperatorr threadingrtypingrrr r r r r rr_ratioralignrr8rrrrrFrpanelrprettyrr"rreprrrsegmentrr2rrr r!rr Exceptionr,r.r/rIrQr]r+r$pip._vendor.rich.consoler1rrrrprintr)r)r)r*s`   ,