U
    ;»{j
  ã                   @  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ƒ qöe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   ú7/tmp/pip-install-zsn1f9xv/pip/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 )z³Get 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 )z±Get 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rÈt|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>    ú
þÿ
#%

