o
    %if                     @  s  d dl mZ d dlZd dlmZ d dlmZ ddlmZ e	dj
Zedd)ddZefd*ddZeddd+ddZeddd,ddZd-ddZd.dd Zed!kr~eed" ed#d$D ]Zee q_ed%dd&D ]Zeed#ed'  ed(e  qldS dS )/    )annotationsN)	lru_cache)Callable   )CELL_WIDTHSu   ^[ -o ˿Ͱ-҂]*$i   textstrreturnintc                   s   t  t fdd| D }|S )a/  Get the number of cells required to display text.

    This method always caches, which may use up a lot of memory. It is recommended to use
    `cell_len` over this method.

    Args:
        text (str): Text to display.

    Returns:
        int: Get the number of cells required to display text.
    c                 3      | ]} |V  qd S N .0	character	_get_sizer   C/var/www/html/corbot_env/lib/python3.10/site-packages/rich/cells.py	<genexpr>       z"cached_cell_len.<locals>.<genexpr>)get_character_cell_sizesum)r   
total_sizer   r   r   cached_cell_len   s   r   	_cell_lenCallable[[str], int]c                   s2   t | dk r
|| S t t fdd| D }|S )zGet the number of cells required to display text.

    Args:
        text (str): Text to display.

    Returns:
        int: Get the number of cells required to display text.
    i   c                 3  r   r   r   r   r   r   r   r   +   r   zcell_len.<locals>.<genexpr>)lenr   r   )r   r   r   r   r   r   cell_len   s
   	r   )maxsizer   c                 C  s   t t| S )zGet the cell size of a character.

    Args:
        character (str): A single character.

    Returns:
        int: Number of cells (0, 1 or 2) occupied by that character.
    )_get_codepoint_cell_sizeord)r   r   r   r   r   /   s   
r   	codepointc                 C  s   t }d}t|d }|| d }	 || \}}}| |k r!|d }n| |kr*|d }n|dkr0dS |S ||k r9	 dS || d }q)zGet the cell size of a character.

    Args:
        codepoint (int): Codepoint of a character.

    Returns:
        int: Number of cells (0, 1 or 2) occupied by that character.
    r   r      T)r   r   )r!   _tablelower_boundupper_boundindexstartendwidthr   r   r   r   <   s    

r   totalc           	      C  s   t | rt| }||k r| d||   S | d| S |dkr dS t| }||kr*| S ||k r6| d||   S d}t| }	 || d }| d|d  }t|}||d kret|d dkre|dd d S ||krk|S ||krr|}n|}q=)	z?Set the length of a string to fit within given number of cells. Nr    Tr"   r   r#   )_is_single_cell_widthsr   r   )	r   r+   size	cell_sizer(   r)   posbefore
before_lenr   r   r   set_cell_sizeY   s4   r4   r*   	list[str]c           
      C  sx   t }g g}|j}|d j}d}| D ]#}||}|| |k}	|	r,||g |d j}|}q|| ||7 }qdd |D S )ah  Split text into lines such that each line fits within the available (cell) width.

    Args:
        text: The text to fold such that it fits in the given width.
        width: The width available (number of cells).

    Returns:
        A list of strings such that each string in the list has cell width
        less than or equal to the available width.
    r#   r   c                 S  s   g | ]}d  |qS )r-   )join)r   liner   r   r   
<listcomp>   s    zchop_cells.<locals>.<listcomp>)r   append)
r   r*   _get_character_cell_sizelinesappend_new_lineappend_to_last_linetotal_widthr   
cell_widthchar_doesnt_fitr   r   r   
chop_cells|   s   



rA   __main__u   😽u]   这是对亚洲语言支持的测试。面对模棱两可的想法，拒绝猜测的诱惑。   P   r#   |x)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   r   r*   r
   r	   r5   )
__future__r   re	functoolsr   typingr   _cell_widthsr   compilematchr.   r   r   r   r   r4   rA   __name__printr7   rangenr   r   r   r   <module>   s0    

#%
