o
    1 i                     @   s   d dl mZmZmZmZ d dlmZ d dlmZ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 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 G dd dZG dd deZ dS )    )AnyDictListOptional)loop_first_last)ConsoleConsoleOptionsRenderableTypeRenderResult)Segment)StyleText)Literal)	Container)CursorOffsetElement)Form)Progress)	BaseStylec                   @   s   e Zd Z					ddededee deeeef  dee	 dee
 d	e	d
dfddZdded
efddZdeee  d
eee  fddZ					
	dddZdS )
FancyPanelNF
renderablestyletitlemetadatais_animatedanimation_counterdonereturnc                 C   sB   || _ || _|p	i | _d | _d| _|| _|pd| _|| _|| _d S )NTr   )	r   _titler   widthexpandr   counterr   r   )selfr   r   r   r   r   r   r    r$   e/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/rich_toolkit/styles/fancy.py__init__   s   



zFancyPanel.__init__ suffixc                 C   s`   | j drdnd}| j o| j}|rdnd}| jjdd|d| jd  }t|| t	|d	S )
Nr   u   ┌u   ◆startedstopped   T)ZstepsZbreatheanimation_statusr   )
r   getr   r   r   Z_get_animation_colorsr"   r   r   
from_color)r#   r(   charZanimatedr,   colorr$   r$   r%   _get_decoration&   s   
zFancyPanel._get_decorationlinesc                 C   s@   |rt dd |d D r|  |rt dd |d D s|S )Nc                 s   s    | ]
}|j  d kV  qdS )r'   N)textstrip).0segmentr$   r$   r%   	<genexpr>:   s    z6FancyPanel._strip_trailing_newlines.<locals>.<genexpr>)allpop)r#   r3   r$   r$   r%   _strip_trailing_newlines5   s   z#FancyPanel._strip_trailing_newlinesconsoler   optionsr   r
   c                 c   s    | j }||}| |}|  }t }| jd ur'|V  tdV  | jV  t|D ];\}}}	|rG| jsG| j	ddr@tdn| jdd}
n|rU| j	ddrUtd}
ntd	}
|
V  |	E d H  |sf|V  q+d S )
N r   Fu   ┌ )r(   r)   Tu   └ u   │ )
r   render_linesr<   r2   r   liner   r   r   r.   )r#   r=   r>   r   r3   
line_startnew_linefirstlastrA   Z
decorationr$   r$   r%   __rich_console__?   s2   








zFancyPanel.__rich_console__)NNNNF)r'   )r=   r   r>   r   r   r
   )__name__
__module____qualname__r	   r   r   strr   r   boolintr&   r   r2   r   r<   rF   r$   r$   r$   r%   r      sH    	




r   c                       s   e Zd ZdZd fddZddedee defdd	Z				dded
ededee dede
f fddZdefddZ	ddedee defddZ  ZS )
FancyStyleFr   Nc                    s"   t  j|i | d| _d| _d S )N   )superr&   cursor_offsetdecoration_size)r#   argskwargs	__class__r$   r%   r&   f   s   
zFancyStyle.__init__elementparentc                 C   s   t |ttf S N)
isinstancer   r   r#   rV   rW   r$   r$   r%   _should_decoratel   s   zFancyStyle._should_decorate	is_activer   r   c           	   	      s`   d }d}t |tr|j}d}t jd||||d|}| ||r.t|||||| j| d}|S )NFT)rV   r\   r   rW   )r   r   r   r   r   r   r$   )rY   r   r   rO   render_elementr[   r   r   )	r#   rV   r\   r   rW   r   r   r   renderedrT   r$   r%   r]   o   s*   

zFancyStyle.render_elementc                 C   s   t dddS )zuReturn an empty line with decoration.

        Returns:
            A text object representing an empty line
        u   │zfancy.normalr-   r   )r#   r$   r$   r%   
empty_line   s   zFancyStyle.empty_linec                 C   s*   t |tr|jS t|jj| j|jj dS )zGet the cursor offset for an element.

        Args:
            element: The element to get the cursor offset for

        Returns:
            The cursor offset
        )topleft)rY   r   rP   r   r`   rQ   ra   rZ   r$   r$   r%   get_cursor_offset_for_element   s   
z(FancyStyle.get_cursor_offset_for_element)r   NrX   )FFN)rG   rH   rI   Z_should_show_progress_titler&   r   r   r   rK   r[   r	   r]   r   r_   r   rb   __classcell__r$   r$   rT   r%   rM   c   s:    !	rM   N)!typingr   r   r   r   Z
rich._loopr   Zrich.consoler   r   r	   r
   Zrich.segmentr   Z
rich.styler   Z	rich.textr   Ztyping_extensionsr   Zrich_toolkit.containerr   Zrich_toolkit.elementr   r   Zrich_toolkit.formr   Zrich_toolkit.progressr   Zrich_toolkit.styles.baser   r   rM   r$   r$   r$   r%   <module>   s    R