o
    Ú­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„Zd d!dd„Zedkrbd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 dS )"é    )ÚannotationsN)ÚIterableé   )Ú	loop_last)Úcell_lenÚ
chop_cellsz	\s*\S+\s*ÚtextÚstrÚreturnúIterable[tuple[int, int, str]]c                 c  sX   � d}t  | |¡}|dur*| ¡ \}}| d¡}|||fV  t  | |¡}|dusdS 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   úG/var/www/html/CropPilot/venv/lib/python3.10/site-packages/rich/_wrap.pyÚwords   s   €
ür   TÚwidthÚintÚfoldÚboolú	list[int]c                 C  sØ   g }|j }d}t}t| ƒD ]\\}}}	||	 ¡ ƒ}
|| }||
k}|r)|||	ƒ7 }q|
|kr]|rRt|	|d�}t|ƒD ]\}}|rC||ƒ |rJ||ƒ}q9|t|ƒ7 }q9q|rX||ƒ ||	ƒ}q|ri|ri||ƒ ||	ƒ}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   s8   
ú	
€r+   Ú__main__)ÚConsoleé
   r   z@12345 abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ 12345Úabcdefghijklmnopqrstuvwxyzé   uR   Textualã�¯Pythonã�®é«˜é€Ÿã‚¢ãƒ—ãƒªã‚±ãƒ¼ã‚·ãƒ§ãƒ³é–‹ç™ºãƒ•ãƒ¬ãƒ¼ãƒ ãƒ¯ãƒ¼ã‚¯ã�§ã�™u4   ã‚¢ãƒ—ãƒªã‚±ãƒ¼ã‚·ãƒ§ãƒ³ã�¯1670ä¸‡è‰²ã‚’ä½¿ç”¨ã�§ã��)r   r	   r
   r   )T)r   r	   r   r   r   r   r
   r   )Ú
__future__r   ÚreÚtypingr   Ú_loopr   Úcellsr   r   Úcompiler   r   r+   Ú__name__Úconsoler-   ÚprintÚruler   r   r   r   Ú<module>   s&    

7



ô