U
    EZh
                     @  s:  U d dl mZ d dlmZ d dlmZ ddlmZ dddd	d
dgZde	d< e
dd eD ZejZde	d< eddddddZefddddddZedddddddZdddd d!d"Zddd#d$d%d&Zed'kr6eed( ed)d*D ]Zee qed+dd,D ]$Zeed)ed-  ed.e  qd/S )0    )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_startZ_end	character r   :/tmp/pip-unpacked-wheel-36xvkur8/pip/_vendor/rich/cells.py
<listcomp>   s    r   zCallable[[str], bool]_is_single_cell_widthsi   strint)textreturnc                 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   zCallable[[str], int])r   	_cell_lenr   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    )maxsize)r   r   c           	      C  s   t | }t}d}t|d }|| d }|| \}}}||k rH|d }n"||krZ|d }n|dkrfdS |S ||k rtq|| d }q(d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.
    r   r      )ordr   r   )	r   	codepointZ_tableZlower_boundZupper_boundindexstartendwidthr   r   r   r   C   s    


r   )r   totalr   c           	      C  s   t | r4t| }||k r(| d||   S | d| S |dkr@dS t| }||krT| S ||k rl| d||   S d}t| }|| d }| d|d  }t|}||d krt|d dkr|dd d S ||kr|S ||kr|}qx|}qxdS )z?Set the length of a string to fit within given number of cells. Nr    r"   r   r#   )r   r   r    )	r   r*   sizeZ	cell_sizer'   r(   posbeforeZ
before_lenr   r   r   set_cell_size`   s0    r0   z	list[str])r   r)   r   c           
      C  sx   t }g g}|j}|d j}d}| D ]F}||}|| |k}	|	rX||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   r      s     zchop_cells.<locals>.<listcomp>)r   append)
r   r)   Z_get_character_cell_sizelinesZappend_new_lineZappend_to_last_lineZtotal_widthr   Z
cell_widthZchar_doesnt_fitr   r   r   
chop_cells   s    



r5   __main__u   😽u]   这是对亚洲语言支持的测试。面对模棱两可的想法，拒绝猜测的诱惑。   P   r#   |xN)
__future__r   	functoolsr   typingr   Z_cell_widthsr   r   __annotations__	frozensetZ_SINGLE_CELLS
issupersetr   r   r    r   r0   r5   __name__printr2   r   nr   r   r   r   <module>   s>    

#%

