
    Pib*                       U d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	m
Z
 d dlmZ e
eeef         Z ed          Zg dZded	<    ed
 eD                       Zej        Zded<    G d de          Z ed          d(d)d            Z ed          d(d*d            Zd(d*dZd*dZ	 d(d+dZ	 d(d,d Z	 d(d,d!Zd(d-d#Zd(d.d&Z d'S )/    )annotations)	lru_cache)
itemgetter)Callable
NamedTupleSequenceTuple)load   ))    ~   )      )   i  )ip  i  )i %  i%  )i (  i(  zlist[tuple[int, int]]_SINGLE_CELL_UNICODE_RANGESc           
     j    g | ]0\  }}t          t          t          ||d z                       D ]}|1S )   )mapchrrange).0_start_end	characters       ^/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/rich/cells.py
<listcomp>r      s[       FDS%q"9"9::   	       zCallable[[str], bool]_is_single_cell_widthsc                  2    e Zd ZU dZded<   ded<   ded<   dS )		CellTablezDContains unicode data required to measure the cell widths of glyphs.strunicode_versionzSequence[tuple[int, int, int]]widthszfrozenset[str]narrow_to_wideN)__name__
__module____qualname____doc____annotations__ r   r   r    r    &   s<         NN****""""""r   r    i   )maxsizeautor   r!   r"   returnintc                H   t          |           }|r|dk     sd|cxk    rdk     rn ndS t          |          j        }|d         }||d         k    rdS d}t          |          dz
  }||k    r4||z   dz	  }||         \  }}	}
||k     r|dz
  }n||	k    r|dz   }n|
S ||k    4dS )a  Get the cell size of a character.

    Args:
        character (str): A single character.
        unicode_version: Unicode version, `"auto"` to auto detect, `"latest"` for the latest unicode version.

    Returns:
        int: Number of cells (0, 1 or 2) occupied by that character.
    r      r   r   r   )ordload_cell_tabler#   len)r   r"   	codepointtable
last_entrylower_boundupper_boundindexstartendwidths              r   get_character_cell_sizer>   .   s     II Y^^u	'A'A'A'AE'A'A'A'A'AqO,,3ErJ:a=  qKe**q.K

$
${*q0!%LsEu!)KK__!)KKL 
$
$ 1r   textc                "    t          | |          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.
        unicode_version: Unicode version, `"auto"` to auto detect, `"latest"` for the latest unicode version.

    Returns:
        int: Get the number of cells required to display text.
    )	_cell_lenr?   r"   s     r   cached_cell_lenrC   Q   s     T?+++r   c                h    t          |           dk     rt          | |          S t          | |          S )   Get the cell length of a string (length as it appears in the terminal).

    Args:
        text: String to measure.
        unicode_version: Unicode version, `"auto"` to auto detect, `"latest"` for the latest unicode version.

    Returns:
        Length of string in terminal cells.
    i   )r4   rC   rA   rB   s     r   cell_lenrF   b   s3     4yy3t_555T?+++r   c                   t          |           rt          |           S d| vrd| vrt          fd| D                       S t                    }d}d}ddh}d}t          |           }||k     rM| |         }||v r|dk    r|dz  }n*|r|||j        v z  }d}nt          |          x}	r|}||	z  }|dz  }||k     M|S )rE      ‍   ️c              3  8   K   | ]}t          |          V  d S )N)r>   )r   r   r"   s     r   	<genexpr>z_cell_len.<locals>.<genexpr>   s?       
 
DM#I??
 
 
 
 
 
r   r   Nr   )r   r4   sumr3   r$   r>   )
r?   r"   
cell_tabletotal_widthlast_measured_characterSPECIALr:   character_countr   character_widths
    `        r   rA   rA   q   s@    d## 4yy t 4 4 
 
 
 
QU
 
 
 
 
 	
 !11JK*."GE$iiO
/
!
!K	H$$
( /6*:SSS*.'"9)_"U"UU /*3'.
 /
!
! r   'tuple[list[CellSpan], int]'c                   t          |          }t          |           }d}d}d}g }ddh}||k     r| |         x}	|v rU|	dk    r|dz  }|r|d         \  }
}}|
||f|d<   n2|r0|dz  }|r)|d         \  }
}}||j        v rd}|dz  }|dz  }|
||f|d<   gt          |	|          x}r%|	}|                    ||dz   x}|f           ||z  }n|r|d         \  }
}}|
|dz   x}|f|d<   ||k     ||fS )zDivide text into spans that define a single grapheme.

    Args:
        text: String to split.
        unicode_version: Unicode version, `"auto"` to auto detect, `"latest"` for the latest unicode version.

    Returns:
        List of spans.
    r   NrH   rI   r   r1   r   )r3   r4   r$   r>   append)r?   r"   rM   codepoint_countr:   rO   rN   spansrP   r   r;   r   cell_lengthrR   s                 r   split_graphemesrY      s    !11J$iiOE*.K(*E"G
/
!
!e$I00H$$
 </4Ry,E4!&{ ;E"I( 	<
 </4Ry,E4.*2KKK26/#q(#q(!&{ ;E"I5iQQQ? 	A&/#LL%%!)!3_EFFF?*KK 	A',Ry$E4 2K@E"I7 /
!
!: ;r   cell_positiontuple[str, str]c                N   |dk    rd| fS t          | |          \  }}t          ||z  t          |          z            }t          t	          t
          |d|                             }	 ||k    r9|t          |          k    r| dfS ||         d         }| d|         | |d         fS ||k     r:||         \  }}	}
||
z   |k    r| d|         dz   d| |	d         z   fS |dz  }||
z  }n<||dz
           \  }}	}
||
z
  |k     r| d|         dz   d| |	d         z   fS |dz  }||
z  })p  Split text by cell position.

    If the cell position falls within a double width character, it is converted to two spaces.

    Args:
        text: Text to split.
        cell_position Offset in cells.
        unicode_version: Unicode version, `"auto"` to auto detect, `"latest"` for the latest unicode version.

    Returns:
        Tuple to two split strings.
    r    NT r   )rY   r.   r4   rL   r   _span_get_cell_len)r?   rZ   r"   rW   rX   offset	left_sizesplit_indexr;   r<   	cell_sizes              r   _split_textre      s    4x(??E; -+-U;<<FC*E'6'N;;<<I#%%U##Rx-*K%tKLL'999}$$$)&M!E3	9$}44FUF|c)3cdd+;;;aKF"II$)&1*$5!E3	9$}44FUF|c)3cdd+;;;aKF"I##r   c                j    t          |           r| d|         | |d         fS t          | ||          S )r]   N)r   re   )r?   rZ   r"   s      r   
split_textrg     sC     d## :N]N#T-..%999t]O<<<r   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 t          | ||          \  } }| S )a$  Adjust a string by cropping or padding with spaces such that it fits within the given number of cells.

    Args:
        text: String to adjust.
        total: Desired size in cells.
        unicode_version: Unicode version.

    Returns:
        A string with cell size equal to total.
    r_   Nr   r^   )r   r4   rF   re   )r?   rh   r"   sizerd   _s         r   set_cell_sizerl     s     d## 4yy%<<#...FUF|zzrIE5cUY.///$77GD!Kr   r=   	list[str]c                ^    t                     r+ fdt          dt                               D             S t           |          \  }}d}g }d}|D ]5\  }}	}
||
z   k    r!|                     ||                    |}d}||
z  }6|r|                     |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.
    c                *    g | ]}||z            S r*   r*   )r   r:   r?   r=   s     r   r   zchop_cells.<locals>.<listcomp>=  s'    TTTUUU]*+TTTr   r   N)r   r   r4   rY   rU   )r?   r=   r"   rW   rk   	line_sizelinesline_offsetr;   r<   rd   s   ``         r   
chop_cellsrs   1  s     d## UTTTTTq#d))U9S9STTTTt_55HE1IEK!&  sIy 5((LLk%/0111KIY		 )T+,,'(((Lr   N)r,   )r   r!   r"   r!   r-   r.   )r?   r!   r"   r!   r-   r.   )r?   r!   r"   r!   r-   rS   )r?   r!   rZ   r.   r"   r!   r-   r[   )r?   r!   rh   r.   r"   r!   r-   r!   )r?   r!   r=   r.   r"   r!   r-   rm   )!
__future__r   	functoolsr   operatorr   typingr   r   r   r	   rich._unicode_datar
   r3   r.   CellSpanr`   r   r)   	frozenset_SINGLE_CELLS
issupersetr   r    r>   rC   rF   rA   rY   re   rg   rl   rs   r*   r   r   <module>r}      sQ   " " " " " " "             8 8 8 8 8 8 8 8 8 8 8 8 6 6 6 6 6 6c3Z]] 6 6 6      	 7    1>0H  H H H H# # # # #
 # # # 4    D 4, , , , , , , , , ,- - - -b '-2  2  2  2  2 l ;A)# )# )# )# )#Z ;A= = = = =(    6      r   