a
    0f                     @  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ddZefd	dd
dddZed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r*e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 )(    )annotationsN)	lru_cache)Callable   )CELL_WIDTHSu   ^[ -o ˿Ͱ-҂]*$i   strint)textreturnc                   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  s   | ]} |V  qd S N .0	character	_get_sizer   O/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pip/_vendor/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   zCallable[[str], int])r	   	_cell_lenr
   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  s   | ]} |V  qd S 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   )maxsize)r   r
   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   )	codepointr
   c                 C  s~   t }d}t|d }|| d }|| \}}}| |k r@|d }n"| |krR|d }n|dkr^dS |S ||k rlqz|| d }q dS )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      )r   r   )r   _tablelower_boundupper_boundindexstartendwidthr   r   r   r   <   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!   )_is_single_cell_widthsr   r   )	r	   r)   size	cell_sizer&   r'   posbefore
before_lenr   r   r   set_cell_sizeY   s0    r2   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   
<listcomp>   r   zchop_cells.<locals>.<listcomp>)r   append)
r	   r(   _get_character_cell_sizelinesZappend_new_lineZappend_to_last_linetotal_widthr   Z
cell_widthZchar_doesnt_fitr   r   r   
chop_cells|   s    



r:   __main__u   😽u]   这是对亚洲语言支持的测试。面对模棱两可的想法，拒绝猜测的诱惑。   P   r!   |x)
__future__r   re	functoolsr   typingr   _cell_widthsr   compilematchr,   r   r   r   r   r2   r:   __name__printr4   rangenr   r   r   r   <module>   s*   #%

