U
    ;»{jã+  ã                   @   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r¬d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*   ú7/tmp/pip-install-zsn1f9xv/pip/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pôd }|�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�r¤t|
 "|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     
û