
    [.ib*                       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eD  cg c]  \  } } ee e| |d
z               D ]  }| ! c}}}       Zej0                  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#yc c}}} w )"    )annotations)	lru_cache)
itemgetter)Callable
NamedTupleSequenceTuple)load   ))    ~   )      )   i  )ip  i  )i %  i%  )i (  i(  zlist[tuple[int, int]]_SINGLE_CELL_UNICODE_RANGES   zCallable[[str], bool]_is_single_cell_widthsc                  0    e Zd ZU dZded<   ded<   ded<   y)		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__     F/mnt/e/genesis-system/.venv/lib/python3.12/site-packages/rich/cells.pyr   r   &   s    N**""r    r   i   )maxsizec                   t        |       }|r|dk  sd|cxk  rdk  ry nyt        |      j                  }|d   }||d   kD  ryd}t        |      dz
  }||k  r/||z   dz	  }||   \  }}	}
||k  r|dz
  }n||	kD  r|dz   }n|
S ||k  r/y)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)	characterr   	codepointtable
last_entrylower_boundupper_boundindexstartendwidths              r!   get_character_cell_sizer3   .   s     IIY^u	'AE'A (BO,33ErJ:a= Ke*q.K

${*q0!%LsEu!)K_!)KL 
$ r    c                    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textr   s     r!   cached_cell_lenr8   Q   s     T?++r    c                N    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   )r(   r8   r5   r6   s     r!   cell_lenr;   b   s)     4y3t_55T?++r    c                J   t        |       rt        |       S d| vrd| vrt        fd| D              S t              }d}d}ddh}d}t        |       }||k  rJ| |   }||v r!|dk(  r|dz  }n+|r)|||j                  v z  }d}nt        |      x}	r|}||	z  }|dz  }||k  rJ|S )r:      ‍   ️c              3  6   K   | ]  }t        |        y w)N)r3   ).0r)   r   s     r!   	<genexpr>z_cell_len.<locals>.<genexpr>   s      
DM#I?
s   r   Nr   )r   r(   sumr'   r   r3   )
r7   r   
cell_tabletotal_widthlast_measured_characterSPECIALr/   character_countr)   character_widths
    `        r!   r5   r5   q   s     d#4y t 4 
QU
 
 	
 !1JK*."GE$iO
/
!K	H$
(6*:S:SSS*.'"9)_"UUU*3'.
 /
! r    c                   t        |      }t        |       }d}d}d}g }ddh}||k  r| |   x}	|v rS|	dk(  r|dz  }|rF|d   \  }
}}|
||f|d<   n4|r2|dz  }|r+|d   \  }
}}||j                  v rd}|dz  }|dz  }|
||f|d<   at        |	|      x}r!|	}|j	                  ||dz   x}|f       ||z  }n|r|d   \  }
}}|
|dz   x}|f|d<   ||k  r||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   Nr=   r>   r   r%   r   )r'   r(   r   r3   append)r7   r   rC   codepoint_countr/   rE   rD   spansrF   r)   r0   _endcell_lengthrH   s                 r!   split_graphemesrO      s^    !1J$iOE*.K(*E"G
/
!e$I0H$
/4Ry,E4!&{ ;E"I(
/4Ry,E4.*2K2KK26/#q(#q(!&{ ;E"I5iQQ?Q&/#LL%%!)!3_EF?*K',Ry$E4 2K@E"I7 /
!: ;r    c                   |dk  rd| fS t        | |      \  }}t        ||z  t        |      z        }t        t	        t
        |d|             }	 ||k(  r$|t        |      k\  r| dfS ||   d   }| d| | |d fS ||k  r,||   \  }}	}
||
z   |kD  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    N r   )rO   intr(   rB   map_span_get_cell_len)r7   cell_positionr   rL   rN   offset	left_sizesplit_indexr0   r1   	cell_sizes              r!   _split_textr\      sS    4x(?E; -+-U;<FC*E'6N;<I
%U#Rx-*K%tKL'999}$$)&M!E3	9$}4FU|c)3cd+;;;aKF"I$)&1*$5!E3	9$}4FU|c)3cd+;;;aKF"I# r    c                F    t        |       r
| d| | |d fS t        | ||      S )rQ   N)r   r\   )r7   rW   r   s      r!   
split_textr^     s4     d#N]#T-.%999t]O<<r    c                    t        |       r t        |       }||k  r| d||z
  z  z   S | d| S |dk  ry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.
    rS   Nr   rR   )r   r(   r;   r\   )r7   totalr   sizer[   _s         r!   set_cell_sizerc     s     d#4y%<#...FU|zIE5cUY.///$7GD!Kr    c                0   t        |       r*t        dt        |       |      D cg c]
  }| |||z     c}S t        | |      \  }}d}g }d}|D ]+  \  }	}
}||z   |kD  r|j	                  | ||	        |	}d}||z  }- |r|j	                  | |d        |S c c}w )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.
    r   N)r   ranger(   rO   rJ   )r7   r2   r   r/   rL   rb   	line_sizelinesline_offsetr0   r1   r[   s               r!   
chop_cellsri   1  s     d#9>q#d)U9STUUU]+TTt_5HE1IEK!& sIy 5(LLk%01KIY	 T+,'(L Us   BN)auto)r)   r   r   r   returnrT   )r7   r   r   r   rk   rT   )r7   r   r   r   rk   z'tuple[list[CellSpan], int]')r7   r   rW   rT   r   r   rk   ztuple[str, str])r7   r   r`   rT   r   r   rk   r   )r7   r   r2   rT   r   r   rk   z	list[str])$
__future__r   	functoolsr   operatorr   typingr   r   r   r	   rich._unicode_datar
   r'   rT   CellSpanrV   r   r   	frozensetrU   chrre   _SINGLE_CELLS
issupersetr   r   r3   r8   r;   r5   rO   r\   r^   rc   ri   )_startrM   r)   s   000r!   <module>rw      s|   "   8 8 6c3] 6 2   8 FDS%q"9:  	 1>0H0H - H#
 # 4 D 4, , ,-b '-2 
2  #2 !2 l ;A)#
)#!)#47)#)#Z ;A=
=!=47==(6os   $C*