a
    )ñ»jL  ã                   @  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m	Z	 e 
d¡Zdd	d
œdd„Zddddddœdd„ZedkrÐddlmZ edd�Ze d¡ ee	ddƒƒ edd�Ze ¡  e d¡ e ¡  e d¡ dS )é    )ÚannotationsN)ÚIterableé   )Ú	loop_last)Úcell_lenÚ
chop_cellsz	\s*\S+\s*ÚstrzIterable[tuple[int, int, str]])ÚtextÚreturnc                 c  sL   d}t  | |¡}|durH| ¡ \}}| d¡}|||fV  t  | |¡}qdS )z·Yields each word from the text as a tuple
    containing (start_index, end_index, word). A "word" in this context may
    include the actual word and any whitespace to the right.
    r   N)Úre_wordÚmatchÚspanÚgroup)r	   ÚpositionÚ
word_matchÚstartÚendÚword© r   ú0E:\soccer\ml_env\Lib\site-packages\rich/_wrap.pyÚwords   s    
r   TÚintÚboolz	list[int])r	   ÚwidthÚfoldr
   c                 C  sØ   g }|j }d}t}t| ƒD ]¸\}}}	||	 ¡ ƒ}
|| }||
k}|rR|||	ƒ7 }q|
|krº|r¤t|	|d�}t|ƒD ].\}}|r†||ƒ |r”||ƒ}qr|t|ƒ7 }qrqÒ|r°||ƒ ||	ƒ}q|r|r||ƒ ||	ƒ}q|S )aœ  Given a string of text, and a width (measured in cells), return a list
    of cell offsets which the string should be split at in order for it to fit
    within the given width.

    Args:
        text: The text to examine.
        width: The available cell width.
        fold: If True, words longer than `width` will be folded onto a new line.

    Returns:
        A list of indices to break the line at.
    r   ©r   )Úappendr   r   Úrstripr   r   Úlen)r	   r   r   Úbreak_positionsr   Úcell_offsetÚ	_cell_lenr   Ú_endr   Úword_lengthÚremaining_spaceÚword_fits_remaining_spaceÚfolded_wordÚlastÚliner   r   r   Údivide_line   s4    


r)   Ú__main__)ÚConsoleé
   r   z@12345 abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ 12345Úabcdefghijklmnopqrstuvwxyzé   uR   Textualã�¯Pythonã�®é«˜é€Ÿã‚¢ãƒ—ãƒªã‚±ãƒ¼ã‚·ãƒ§ãƒ³é–‹ç™ºãƒ•ãƒ¬ãƒ¼ãƒ ãƒ¯ãƒ¼ã‚¯ã�§ã�™u4   ã‚¢ãƒ—ãƒªã‚±ãƒ¼ã‚·ãƒ§ãƒ³ã�¯1670ä¸‡è‰²ã‚’ä½¿ç”¨ã�§ã��)T)Ú
__future__r   ÚreÚtypingr   Ú_loopr   Úcellsr   r   Úcompiler   r   r)   Ú__name__Úconsoler+   ÚprintÚruler   r   r   r   Ú<module>   s"   
7



