
    жvg                       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    rd 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             )dS dS ))    )annotationsN)	lru_cache)Callable   )CELL_WIDTHSu   ^[ -o ˿Ͱ-҂]*$i   textstrreturnintc                L    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   | ]} |          V  d S N .0	character	_get_sizes     S/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/pip/_vendor/rich/cells.py	<genexpr>z"cached_cell_len.<locals>.<genexpr>   -      @@iYYy))@@@@@@    )get_character_cell_sizesum)r   
total_sizer   s     @r   cached_cell_lenr      s2     (I@@@@4@@@@@Jr   	_cell_lenCallable[[str], int]c                    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   | ]} |          V  d S r   r   r   s     r   r   zcell_len.<locals>.<genexpr>+   r   r   )lenr   r   )r   r   r   r   s      @r   cell_lenr!      sO     4yy3y'I@@@@4@@@@@Jr   )maxsizer   c                :    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	NN333r   	codepointc                    t           }d}t          |          dz
  }||z   dz  }	 ||         \  }}}| |k     r|dz
  }n| |k    r|dz   }n
|dk    rdn|S ||k     rn	||z   dz  }>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      T)r   r    )r&   _tablelower_boundupper_boundindexstartendwidths           r   r$   r$   <   s     FKf++/K;&1,E
1"5MsEu!)KK__!)KK11.$${*q0
1 1r   totalc                   t          |           r*t          |           }||k     r| d||z
  z  z   S | d|         S |dk    rdS 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 ||k    r|}n|}g)	z?Set the length of a string to fit within given number of cells. Nr    Tr(   r   r)   )_is_single_cell_widthsr    r!   )	r   r1   size	cell_sizer.   r/   posbefore
before_lens	            r   set_cell_sizer;   Y   s8    d## 4yy%<<#...FUF|zzrIE5cUY.///E
d))Cs{q iaif%%
""xr
';';q'@'@#2#;$$MCCEr   r0   	list[str]c                    t           }g g}|j        }|d         j        }d}| D ]D} ||          }||z   |k    }	|	r ||g           |d         j        }|}4 ||           ||z  }Ed |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                8    g | ]}d                      |          S )r4   )join)r   lines     r   
<listcomp>zchop_cells.<locals>.<listcomp>   s"    ,,,dBGGDMM,,,r   )r   append)
r   r0   _get_character_cell_sizelinesappend_new_lineappend_to_last_linetotal_widthr   
cell_widthchar_doesnt_fits
             r   
chop_cellsrJ   |   s      7 TElO)*K 
& 
&	--i88
%
2U: 	&OYK((("')"2$KK	***:%KK,,e,,,,r   __main__u   😽u]   这是对亚洲语言支持的测试。面对模棱两可的想法，拒绝猜测的诱惑。   P   r)   |x)r   r	   r
   r   )r   r	   r   r   r
   r   )r   r	   r
   r   )r&   r   r
   r   )r   r	   r1   r   r
   r	   )r   r	   r0   r   r
   r<   )
__future__r   re	functoolsr   typingr   _cell_widthsr   compilematchr5   r   r!   r   r$   r;   rJ   __name__printr@   rangenr   r   r   <module>r[      s   " " " " " " 				             % % % % % % $$QRRX  4   " ;J       4	4 	4 	4 	4 4   8       F"- "- "- "-J z	E
!
!&
)
)***
~  AB  C  C  dU2q"  mm  BC  D  D  GJ  J  	K  	K  	KcAg  r   