File: //opt/saltstack/salt/lib/python3.10/site-packages/rich/__pycache__/_wrap.cpython-310.pyc
o
;jL
� @ s� d dl mZ d dlZd dlmZ ddlmZ ddlmZm Z e�
d�Zddd
�Zd d!dd�Z
edkrbddlmZ edd�Ze�d� ee dd�� edd�Ze�� e�d� e�� e�d� dS dS )"� )�annotationsN)�Iterable� )� loop_last)�cell_len�
chop_cellsz \s*\S+\s*�text�str�return�Iterable[tuple[int, int, str]]c c sX � d}t �| |�}|dur*|�� \}}|�d�}|||fV t �| |�}|dus
dS dS )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 �positionZ
word_match�start�end�word� r �>/opt/saltstack/salt/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
|
|kr]|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 Zbreak_positionsr Zcell_offsetZ _cell_lenr Z_endr Zword_lengthZremaining_spaceZword_fits_remaining_spaceZfolded_word�last�liner r r �divide_line s8
�
�r"