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")
| 297 | |
| 298 | |
| 299 | def 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 | |
| 326 | def chop_cells(text: str, width: int, unicode_version: str = "auto") -> list[str]: |
no test coverage detected