
    "Te                       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j                  d      j                  Z ed      dd	       Zefdd
Z ed      dd       Z ed      dd       ZddZ	 	 	 	 	 	 ddZedk(  rQ e ed              edd      D ]
  Z ee         eddd      D ]  Z e ede      dz           edez         ! yy)    )annotationsN)	lru_cache)Callable   )CELL_WIDTHSu   ^[ -o ˿Ͱ-҂]*$i   c                <    t         t        f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  .   K   | ]  } |        y wN .0	character	_get_sizes     ,/usr/lib/python3/dist-packages/rich/cells.py	<genexpr>z"cached_cell_len.<locals>.<genexpr>        @iYy)@   )get_character_cell_sizesum)text
total_sizer   s     @r   cached_cell_lenr      s      (I@4@@J    c                h    t        |       dk  r ||       S t        t        f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  .   K   | ]  } |        y wr
   r   r   s     r   r   zcell_len.<locals>.<genexpr>+   r   r   )lenr   r   )r   	_cell_lenr   r   s      @r   cell_lenr      s5     4y3'I@4@@Jr   )maxsizec                *    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   s    r   r   r   /   s     $C	N33r   c                    t         }d}t        |      dz
  }||z   dz  }	 ||   \  }}}| |k  r|dz
  }n| |kD  r|dz   }n	|dk(  rdS |S ||k  r	 y||z   dz  }8)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   )	codepoint_tablelower_boundupper_boundindexstartendwidths           r   r!   r!   <   s     FKf+/K;&1,E
"5MsEu!)K_!)K1..$ {*q0 r   c                `   t        |       r t        |       }||k  r| d||z
  z  z   S | d| S |dk  ryt        |       }||k(  r| S ||k  r| d||z
  z  z   S d}t        |       }	 ||z   dz  }| d|dz    }t        |      }||dz   k(  rt        |d         dk(  r|dd dz   S ||k(  r|S ||kD  r|}n|}N)z?Set the length of a string to fit within given number of cells. Nr    r$   r   r%   )_is_single_cell_widthsr   r   )	r   totalsize	cell_sizer+   r,   posbefore
before_lens	            r   set_cell_sizer8   Y   s    d#4y%<#...FU|zIE5cUY.///E
d)C s{q iaf%
"xr
';q'@#2;$$MCE r   c                   t         }g g}|j                  }|d   j                  }d}| D ]<  } ||      }||z   |kD  }	|	r ||g       |d   j                  }|}0 ||       ||z  }> |D 
cg c]  }
dj                  |
       c}
S c c}
w )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   r0   )r   appendjoin)r   r-   _get_character_cell_sizelinesappend_new_lineappend_to_last_linetotal_widthr   
cell_widthchar_doesnt_fitlines              r   
chop_cellsrD   |   s      7 TEllO)**K 
&	-i8
%
2U:YK("')"2"2$K	*:%K
& ',,dBGGDM,,,s   ,B__main__u   😽u]   这是对亚洲语言支持的测试。面对模棱两可的想法，拒绝猜测的诱惑。   P   r%   |x)r   strreturnint)r   rJ   r   zCallable[[str], int]rK   rL   )r   rJ   rK   rL   )r&   rL   rK   rL   )r   rJ   r2   rL   rK   rJ   )r   rJ   r-   rL   rK   z	list[str])
__future__r   re	functoolsr   typingr   _cell_widthsr   compilematchr1   r   r   r   r!   r8   rD   __name__printrC   rangenr   r   r   <module>rX      s7   " 	   % $$QRXX  4 " ;J   4	4 	4 4 8 F"-
"-"- "-J z	
!&
)*~  AB  C d2q" m  BC  D  GJ  J  	KcAg	 r   