Number of terminal columns occupied by s, ignoring ANSI escapes.
(s: str)
| 25 | |
| 26 | |
| 27 | def _visible_width(s: str) -> int: |
| 28 | """Number of terminal columns occupied by s, ignoring ANSI escapes.""" |
| 29 | s = ANSI_RE.sub("", s) |
| 30 | w = 0 |
| 31 | for ch in s: |
| 32 | if ch == "\n": |
| 33 | continue |
| 34 | if unicodedata.east_asian_width(ch) in ("W", "F"): |
| 35 | w += 2 |
| 36 | else: |
| 37 | w += 1 |
| 38 | return w |
| 39 | |
| 40 | |
| 41 | def _wrapped_rows(s: str, term_w: int) -> int: |