U cf)@sddlmZmZddlmZddlmZmZddlm Z ddl m Z ddl m Z mZddlmZmZdd lmZdd lmZmZdd lmZmZerdd lmZmZmZmZGd dde Ze dkrddlmZeZ!ddlm"Z"mZddlmZeddde"ddZ#e!$e!$e#dS)) TYPE_CHECKINGOptional) AlignMethod)ROUNDEDBox)cell_len) JupyterMixin) Measurementmeasure_renderables)PaddingPaddingDimensions)Segment)Style StyleType)TextTextType)ConsoleConsoleOptionsRenderableType RenderResultc@seZdZdZefddddddddddddd d eeeeeeeee e e e ee ee e e dd d d Z eefdddddddddddd d eeeeeeeee e e ee ee e e ddddZeeedddZeeedddZddddddZddddddZdS)PanelaA console renderable that draws a border around its contents. Example: >>> console.print(Panel("Hello, World!")) Args: renderable (RenderableType): A console renderable object. box (Box, optional): A Box instance that defines the look of the border (see :ref:`appendix_box`. Defaults to box.ROUNDED. safe_box (bool, optional): Disable box characters that don't display on windows legacy terminal with *raster* fonts. Defaults to True. expand (bool, optional): If True the panel will stretch to fill the console width, otherwise it will be sized to fit the contents. Defaults to True. style (str, optional): The style of the panel (border and contents). Defaults to "none". border_style (str, optional): The style of the border. Defaults to "none". width (Optional[int], optional): Optional width of panel. Defaults to None to auto-detect. height (Optional[int], optional): Optional height of panel. Defaults to None to auto-detect. padding (Optional[PaddingDimensions]): Optional padding around renderable. Defaults to 0. highlight (bool, optional): Enable automatic highlighting of panel title (if str). Defaults to False. NcenterTnone)rrF) title title_alignsubtitlesubtitle_alignsafe_boxexpandstyle border_stylewidthheightpadding highlightr) renderableboxrrrrrrr r!r"r#r$r%returnc CsX||_||_||_||_||_||_||_||_| |_| |_ | |_ | |_ | |_ ||_ dS)N)r&r'rrrrrrr r!r"r#r$r%)selfr&r'rrrrrrr r!r"r#r$r%r*D/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/rich/panel.py__init__&szPanel.__init__) rrrrrr r!r"r#r$r%)r&r'rrrrrr r!r"r#r$r%r(c Cs$|||||||||| | | | | ddS)z2An alternative constructor that sets expand=False.F) rrrrrr r!r"r#r$r%rr*)clsr&r'rrrrrr r!r"r#r$r%r*r*r+fitGs z Panel.fit)r(cCs^|jrZt|jtrt|jn|j}d|_|jdd|_d|_ | | d|SdSN  Tr) r isinstancestrr from_markupcopyendplainreplaceno_wrap expand_tabspad)r) title_textr*r*r+_titleks  z Panel._titlecCs^|jrZt|jtrt|jn|j}d|_|jdd|_d|_ | | d|SdSr/) rr3r4rr5r6r7r8r9r:r;r<)r) subtitle_textr*r*r+ _subtitle{s  zPanel._subtitlerrr)consoleoptionsr(ccst|j}t|r t|j|n|j}||j}|||j}|jdkrR|j n t |j |j}|j dkrp|j n|j }|j j ||d} ttttttddd} |j} | dk r| ||jr|dn|j|||ddj} |jp|jpd} | r| d8} | dk r t |j dt| | jd} | d}|j| | |jd}|j|||d}t| j|}t| j |}t!}| dks|d krt| "|dg|Vn\| | |d |j#| j$|} t| j%| j$|V|&| ||d EdHt| j$| j'|V|V|D]"}|V|EdH|V|Vq|j(}|dk r>|||dksR|d krlt| )|dg|Vn\| ||d |j*| j+|}t| j,| j+|V|&|||d EdHt| j+| j-|V|VdS) N)safe)textr"align characterr r(cSs|}|||t|j}|r|dkrFtj||||fdddS|dkr~|d}tj|||f|||||fdddStj|||f|dddS|S)acGets new aligned text. Args: text (Text): Title or subtitle text. width (int): Desired width. align (str): Alignment. character (str): Character for alignment. style (Style): Border style Returns: Text: New text instance leftTr0)r:r7r)r6truncaterr8rassemble)rDr"rErFr excess_spacerGr*r*r+ align_texts6    z*Panel.__rich_console__..align_textrH)rB)r"r#r%)r ).r unpackr$anyr& get_styler r!r" max_widthminrr' substituterintr4rr>stylize_beforermeasure update_widthmaximumr#maxrupdater% render_linesrmid_left mid_rightlineget_toprtoptop_leftrender top_rightr@ get_bottomrbottom bottom_left bottom_right)r)rArB_paddingr&r r!r"rr'rLr= child_width child_height child_optionslines line_startline_endnew_liner^r?r*r*r+__rich_console__s    ,          zPanel.__rich_console__r c Csz|j}t|j\}}}}||}|r0|j|gn|jg}|jdkrjt|||j|d|j |d} n|j} t | | S)NrH) r>r rNr$r&r"r rWrQrXr ) r)rArBr>_rightrGr$ renderablesr"r*r*r+__rich_measure__s"  zPanel.__rich_measure__)__name__ __module__ __qualname____doc__rrrrrboolrrTr r, classmethodr.propertyrr>r@rprtr*r*r*r+rs !# r__main__)r)DOUBLEr)r z Hello, World!z rich.Panelz white on blue)rr r'r$N)%typingrrrErr'rrcellsrjupyterr rVr r r$r r segmentrr rrrDrrrArrrrrrucr}pprintr*r*r*r+s8