MCPcopy
hub / github.com/Textualize/rich / cell_len

Function cell_len

rich/cells.py:98–110  ·  view source on GitHub ↗

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.

(text: str, unicode_version: str = "auto")

Source from the content-addressed store, hash-verified

96
97
98def cell_len(text: str, unicode_version: str = "auto") -> int:
99 """Get the cell length of a string (length as it appears in the terminal).
100
101 Args:
102 text: String to measure.
103 unicode_version: Unicode version, `"auto"` to auto detect, `"latest"` for the latest unicode version.
104
105 Returns:
106 Length of string in terminal cells.
107 """
108 if len(text) < 512:
109 return cached_cell_len(text, unicode_version)
110 return _cell_len(text, unicode_version)
111
112
113def _cell_len(text: str, unicode_version: str) -> int:

Callers 15

test_split_graphemesFunction · 0.90
test_nerd_fontFunction · 0.90
test_zwjFunction · 0.90
test_non_printableFunction · 0.90
test_split_cells_mixedFunction · 0.90
test_split_cells_doublesFunction · 0.90
test_split_cells_singleFunction · 0.90
export_svgMethod · 0.90
cell_lenMethod · 0.85
__rich_measure__Method · 0.85
truncateMethod · 0.85
alignMethod · 0.85

Calls 2

cached_cell_lenFunction · 0.85
_cell_lenFunction · 0.85

Tested by 7

test_split_graphemesFunction · 0.72
test_nerd_fontFunction · 0.72
test_zwjFunction · 0.72
test_non_printableFunction · 0.72
test_split_cells_mixedFunction · 0.72
test_split_cells_doublesFunction · 0.72
test_split_cells_singleFunction · 0.72