Count the number of characters in `line_str` that would fit in a terminal or editor of `max_width` (which respects Unicode East Asian Width).
(line_str: str, max_width: int)
| 378 | |
| 379 | |
| 380 | def count_chars_in_width(line_str: str, max_width: int) -> int: |
| 381 | """Count the number of characters in `line_str` that would fit in a |
| 382 | terminal or editor of `max_width` (which respects Unicode East Asian |
| 383 | Width). |
| 384 | """ |
| 385 | total_width = 0 |
| 386 | for i, char in enumerate(line_str): |
| 387 | width = char_width(char) |
| 388 | if width + total_width > max_width: |
| 389 | return i |
| 390 | total_width += width |
| 391 | return len(line_str) |
no test coverage detected