o
    Rh
                     @  s  U d dl mZ d dlmZ d dlmZ ddlmZ g dZde	d< e
d	d
 eD ZejZde	d< edd,ddZefd-ddZeddd.ddZd/ddZd0d!d"Zed#kreed$ ed%d&D ]Zee qded'dd(D ]Zeed%ed)  ed*e  qqd+S d+S )1    )annotations)	lru_cache)Callable   )CELL_WIDTHS))    ~   )      )   i  )ip  i  )i %  i%  )i (  i(  zlist[tuple[int, int]]_SINGLE_CELL_UNICODE_RANGESc                 C  s.   g | ]\}}t tt||d  D ]}|qqS )r   )mapchrrange).0_start_end	character r   L/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/rich/cells.py
<listcomp>   s    r   zCallable[[str], bool]_is_single_cell_widthsi   textstrreturnintc                 C  s   t | rt| S ttt| 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.
    )r   lensumr   get_character_cell_size)r   r   r   r   cached_cell_len!   s   r   	_cell_lenCallable[[str], int]c                 C  s2   t | dk r
|| S t| rt | S ttt| 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   )r   r   r   r   r   )r   r    r   r   r   cell_len3   s
   	r"   )maxsizer   c           	      C  s   t | }t}d}t|d }|| d }	 || \}}}||k r%|d }n||kr.|d }n|dkr4dS |S ||k r=	 dS || d }q)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.
    r   r      T)ordr   r   )	r   	codepoint_tablelower_boundupper_boundindexstartendwidthr   r   r   r   C   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%   )r   r   r"   )	r   r/   size	cell_sizer,   r-   posbefore
before_lenr   r   r   set_cell_size`   s4   r7   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 )r1   )join)r   liner   r   r   r      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   



rC   __main__u   😽u]   这是对亚洲语言支持的测试。面对模棱两可的想法，拒绝猜测的诱惑。   P   r%   |xN)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   r8   )
__future__r   	functoolsr   typingr   _cell_widthsr   r   __annotations__	frozenset_SINGLE_CELLS
issupersetr   r   r"   r   r7   rC   __name__printr:   r   nr   r   r   r   <module>   s6    



#%
