U
    EZh+                     @   s  d dl mZmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZmZ ddlmZmZ dd	lmZ dd
lmZmZ ddlmZmZ erddlmZmZmZmZ G dd deZe dkrddlmZ e Z!ddlm"Z"mZ ddlmZ eddde"ddZ#e!$  e!$e# dS )    )TYPE_CHECKINGOptional   )AlignMethod)ROUNDEDBox)cell_len)JupyterMixin)Measurementmeasure_renderables)PaddingPaddingDimensions)Segment)Style	StyleType)TextTextType)ConsoleConsoleOptionsRenderableTypeRenderResultc                   @   s  e Zd ZdZefdddddddddddddd	eee eee eee	 e	e
e
ee ee ee	dd
ddZeefddddddddddddd	eee eee eee	 e
e
ee ee ee	d dddZeee dddZeee dddZddddddZddddddZdS )PanelaX  A 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.
        title (Optional[TextType], optional): Optional title displayed in panel header. Defaults to None.
        title_align (AlignMethod, optional): Alignment of title. Defaults to "center".
        subtitle (Optional[TextType], optional): Optional subtitle displayed in panel footer. Defaults to None.
        subtitle_align (AlignMethod, optional): Alignment of subtitle. Defaults to "center".
        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.
    NcenterTnone)r   r   F)titletitle_alignsubtitlesubtitle_alignsafe_boxexpandstyleborder_stylewidthheightpadding	highlightr   )
renderableboxr   r   r   r   r   r   r    r!   r"   r#   r$   r%   returnc                C   sX   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	|| _
|| _|| _|| _d S )N)r&   r'   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   )selfr&   r'   r   r   r   r   r   r   r    r!   r"   r#   r$   r%    r*   :/tmp/pip-unpacked-wheel-36xvkur8/pip/_vendor/rich/panel.py__init__(   s    zPanel.__init__)r   r   r   r   r   r    r!   r"   r#   r$   r%   )r&   r'   r   r   r   r   r   r    r!   r"   r#   r$   r%   r(   c                C   s$   | |||||||||	|
|||ddS )z2An alternative constructor that sets expand=False.F)r   r   r   r   r   r    r!   r"   r#   r$   r%   r   r*   )clsr&   r'   r   r   r   r   r   r    r!   r"   r#   r$   r%   r*   r*   r+   fitI   s     z	Panel.fit)r(   c                 C   s^   | j rZt| j trt| j n| j  }d|_|jdd|_d|_	|
  |d |S d S N 
 Tr   )r   
isinstancestrr   from_markupcopyendplainreplaceno_wrapexpand_tabspad)r)   
title_textr*   r*   r+   _titlem   s    

zPanel._titlec                 C   s^   | j rZt| j trt| j n| j  }d|_|jdd|_d|_	|
  |d |S d S r/   )r   r3   r4   r   r5   r6   r7   r8   r9   r:   r;   r<   )r)   subtitle_textr*   r*   r+   	_subtitle}   s    

zPanel._subtitler   r   r   )consoleoptionsr(   c                 #   s  t | j}t|r t | j|n| j} | j} | j}|| }| jd krV|j	nt
|j	| j}| jd krt jn| j}	| jj||	d}
ttttttd fdd}| j}|d k	r|| | jr|d n j|||d dj}| jp|jpd }|r|d8 }|d k	r*t
|j	d t||jd }|d }|j||| jd} j|||d}t|
j|}t|
j  |}t! }|d ks|d	krt|
"|d g|V  n\|||d	 | j#|
j$|}t|
j%|
j$ |V   &|||d	 E d H  t|
j$|
j' |V  |V  |D ]"}|V  |E d H  |V  |V  q
| j(}|d k	rH|| |d ks\|d	krvt|
)|d g|V  n\|||d	 | j*|
j+|}t|
j,|
j+ |V   &|||d	 E d H  t|
j+|
j- |V  |V  d S )
N)safe)textr"   align	characterr    r(   c                    s   |   } | | |t| j }| jr8|  | j |r|dkr^tj| || |fdddS |dkr|d }tj|| |f| |||  |fdddS tj|| |f| dddS | S )ac  Gets 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:   r7   r      )	r6   truncater   r8   r    Zstylize	get_styler   Zassemble)rD   r"   rE   rF   r    Zexcess_spacerG   rA   r*   r+   
align_text   s:    



z*Panel.__rich_console__.<locals>.align_textrH   )rB   )r"   r#   r%   )r       ).r   unpackr$   anyr&   rJ   r    r!   r"   	max_widthminr   r'   
substituter   intr4   r   r>   Zstylize_beforer   measureupdate_widthmaximumr#   maxr   updater%   Zrender_linesr   Zmid_leftZ	mid_rightlineZget_topr   topZtop_leftrenderZ	top_rightr@   Z
get_bottomr   ZbottomZbottom_leftZbottom_right)r)   rA   rB   Z_paddingr&   r    Zpartial_border_styler!   r"   r   r'   rL   r=   Zchild_widthZchild_heightZchild_optionslinesZ
line_startZline_endnew_linerY   r?   r*   rK   r+   __rich_console__   s        /

 
   



 
zPanel.__rich_console__r
   c           
      C   sz   | j }t| j\}}}}|| }|r0| j|gn| jg}| jd krjt|||j| d |j	| d }	n| j}	t
|	|	S )NrH   )r>   r   rN   r$   r&   r"   r   rU   rP   rV   r
   )
r)   rA   rB   r>   _rightrG   r$   Zrenderablesr"   r*   r*   r+   __rich_measure__  s"    

zPanel.__rich_measure__)__name__
__module____qualname____doc__r   r   r   r   r   boolr   rS   r   r,   classmethodr.   propertyr   r>   r@   r^   ra   r*   r*   r*   r+   r      s   !#   r   __main__)r   )DOUBLEr   )r   zHello, World!z
rich.Panelzwhite on blue)r   r    r'   r$   N)%typingr   r   rE   r   r'   r   r   cellsr   Zjupyterr	   rT   r
   r   r$   r   r   segmentr   r    r   r   rD   r   r   rA   r   r   r   r   r   rb   crj   pprintr*   r*   r*   r+   <module>   s8     
