Return the width of `line_str` as it would be displayed in a terminal or editor (which respects Unicode East Asian Width). You could utilize this function to determine, for example, if a string is too wide to display in a terminal or editor.
(line_str: str)
| 309 | |
| 310 | |
| 311 | def str_width(line_str: str) -> int: |
| 312 | """Return the width of `line_str` as it would be displayed in a terminal |
| 313 | or editor (which respects Unicode East Asian Width). |
| 314 | |
| 315 | You could utilize this function to determine, for example, if a string |
| 316 | is too wide to display in a terminal or editor. |
| 317 | """ |
| 318 | if line_str.isascii(): |
| 319 | # Fast path for a line consisting of only ASCII characters |
| 320 | return len(line_str) |
| 321 | return sum(map(char_width, line_str)) |
| 322 | |
| 323 | |
| 324 | def count_chars_in_width(line_str: str, max_width: int) -> int: |
no outgoing calls
no test coverage detected