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

Function set_cell_size

rich/cells.py:299–323  ·  view source on GitHub ↗

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.

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

Source from the content-addressed store, hash-verified

297
298
299def set_cell_size(text: str, total: int, unicode_version: str = "auto") -> str:
300 """Adjust a string by cropping or padding with spaces such that it fits within the given number of cells.
301
302 Args:
303 text: String to adjust.
304 total: Desired size in cells.
305 unicode_version: Unicode version.
306
307 Returns:
308 A string with cell size equal to total.
309 """
310 if _is_single_cell_widths(text):
311 size = len(text)
312 if size < total:
313 return text + " " * (total - size)
314 return text[:total]
315 if total <= 0:
316 return ""
317 cell_size = cell_len(text)
318 if cell_size == total:
319 return text
320 if cell_size < total:
321 return text + " " * (total - cell_size)
322 text, _ = _split_text(text, total, unicode_version)
323 return text
324
325
326def chop_cells(text: str, width: int, unicode_version: str = "auto") -> list[str]:

Callers 4

truncateMethod · 0.85
__rich_console__Method · 0.85
_rule_lineMethod · 0.85
adjust_line_lengthMethod · 0.85

Calls 2

cell_lenFunction · 0.85
_split_textFunction · 0.85

Tested by

no test coverage detected