U
    祡c                     @   s   d dl mZ ddlmZ ddlmZmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ G d
d deZedkrd dlZd dlmZ zejd ZW n ek
r   dZY nX e Zeeed e Zejeddd dS )    )Union   )AlignMethod)cell_lenset_cell_size)ConsoleConsoleOptionsRenderResult)JupyterMixinMeasurement)Style)Textc                	   @   s   e Zd ZdZddddddeeef eeeef eedd	d
dZ	edddZ
eeedddZeeedddZeeedddZdS )Ruleu  A console renderable to draw a horizontal rule (line).

    Args:
        title (Union[str, Text], optional): Text to render in the rule. Defaults to "".
        characters (str, optional): Character(s) used to draw the line. Defaults to "─".
        style (StyleType, optional): Style of Rule. Defaults to "rule.line".
        end (str, optional): Character at end of Rule. defaults to "\\n"
        align (str, optional): How to align the title, one of "left", "center", or "right". Defaults to "center".
     u   ─z	rule.line
center)
charactersstyleendalignN)titler   r   r   r   returnc                C   sN   t |dk rtd|dkr,td|d|| _|| _|| _|| _|| _d S )Nr   z:'characters' argument must have a cell width of at least 1)leftr   rightzAinvalid value for align, expected "left", "center", "right" (not ))r   
ValueErrorr   r   r   r   r   )selfr   r   r   r   r    r   -/tmp/pip-unpacked-wheel-qkhzhrww/rich/rule.py__init__   s    	
zRule.__init__)r   c                 C   s   d| j d| jdS )NzRule(z, r   )r   r   )r   r   r   r   __repr__.   s    zRule.__repr__)consoleoptionsr   c                 c   s4  |j }ttdd pdd }|jr.|| js.dn| j}t|}| jsT| ||V  d S t| jt	rh| j}n|j
| jdd}|jdd|_|  | jd	krd
nd}td|| }	|	s| ||V  d S t	| jd}
| jd	kr|j|	dd |t|j d }t	||| d  }||d  |t|j t|j }t	||| d  }|| |
|jd | j |
| |
d|j | j n| jdkr|j|	dd |
| |
d |
|||
j  | j nJ| jdkr|j|	dd |
|||j d  | j |
d |
| t|
j||
_|
V  d S )Nisasciic                 S   s   t dd | D S )Nc                 s   s   | ]}t |d k V  qdS )   N)ord).0cr   r   r   	<genexpr>8   s     z:Rule.__rich_console__.<locals>.<lambda>.<locals>.<genexpr>)all)sr   r   r   <lambda>8       z'Rule.__rich_console__.<locals>.<lambda>-z	rule.text)r   r    r         r   )r   Zellipsis)Zoverflowr   r   r   )	max_widthgetattrstrZ
ascii_onlyr   r   r   
_rule_line
isinstancer   Z
render_strplainreplaceexpand_tabsr   maxr   truncateappendr   r   )r   r"   r#   widthr$   r   	chars_lenZ
title_textZrequired_spaceZtruncate_width	rule_textZ
side_widthr   Zright_lengthr   r   r   r   __rich_console__1   s`    





zRule.__rich_console__)r>   r=   r   c                 C   s6   t | j|| d  | j}|| t|j||_|S Nr   )r   r   r   r;   r   r7   )r   r>   r=   r?   r   r   r   r5   m   s    
zRule._rule_linec                 C   s
   t ddS rA   r   )r   r"   r#   r   r   r   __rich_measure__s   s    zRule.__rich_measure__)r   )__name__
__module____qualname____doc__r   r4   r   r   r   r    r!   r   r   r	   r@   intr5   r   rB   r   r   r   r   r      s2    

 < r   __main__N)r   zHello, World)r   Zfoor0   )r=   )typingr   r   r   cellsr   r   r"   r   r   r	   Zjupyterr
   Zmeasurer   r   r   textr   r   rC   sysZrich.consoleargv
IndexErrorprintr   r   r   r   <module>   s&   m
