a
    $lJhL                     @  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rd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 )zYields 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	   positionZ
word_matchstartendword r   H/var/www/shaz/venv/lib/python3.9/site-packages/pip/_vendor/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|rt|	|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   Zbreak_positionsr   Zcell_offsetZ	_cell_lenr   Z_endr   Zword_lengthZremaining_spaceZword_fits_remaining_spaceZ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   Z_loopr   cellsr   r   compiler   r   r    __name__consoler"   printZruler   r   r   r   <module>   s"   
7



