U cf@s.ddlmZddlZddlmZddlmZddlmZe dj Z edd d d d d Z e fd dd dddZ eddd d dddZeddd d dddZd d d dddZd d ddddZed kr*eed!ed"d#D] Zeeqed$dd%D]$Zeed"ed&ed'eqdS)() annotationsN) lru_cache)Callable) CELL_WIDTHSu^[ -o ˿Ͱ-҂]*$istrint)textreturncsttfdd|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. c3s|]}|VqdSN.0 character _get_sizer D/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/rich/cells.py sz"cached_cell_len..)get_character_cell_sizesum)r total_sizer rrcached_cell_len s rzCallable[[str], int])r _cell_lenr cs2t|dkr||Sttfdd|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. ic3s|]}|VqdSr r r rr rr+szcell_len..)lenrr)r rrr rrcell_lens r)maxsize)rr cCs tt|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_sizeord)rr r rr/s r) codepointr cCs~t}d}t|d}||d}||\}}}||kr@|d}n"||krR|d}n|dkr^dS|S||krlqz||d}q dS)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. rr)rr)r_table lower_bound upper_boundindexstartendwidthr r rr<s     r)r totalr c Cst|r4t|}||kr(|d||S|d|S|dkr@dSt|}||krT|S||krl|d||Sd}t|}||d}|d|d}t|}||dkrt|ddkr|dddS||kr|S||kr|}qx|}qxdS)z?Set the length of a string to fit within given number of cells. Nrrrr )_is_single_cell_widthsrr) r r(size cell_sizer%r&posbefore before_lenr r r set_cell_sizeYs0  r1z list[str])r r'r c Csxt}gg}|j}|dj}d}|D]F}||}|||k} | rX||g|dj}|}q"||||7}q"dd|DS)ahSplit 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 rcSsg|]}d|qS)r*)join)rliner r r szchop_cells..)rappend) r r'_get_character_cell_sizelinesZappend_new_lineZappend_to_last_line total_widthrZ cell_widthZchar_doesnt_fitr r r chop_cells|s     r9__main__u😽u]这是对亚洲语言支持的测试。面对模棱两可的想法,拒绝猜测的诱惑。Pr |x) __future__rre functoolsrtypingr _cell_widthsrcompilematchr+rrrrr1r9__name__printr3rangenr r r rs*      #%