Visible width of a printed string. ANSI color codes are removed. >>> _visible_width('\x1b[31mhello\x1b[0m'), _visible_width("world") (5, 5)
(s)
| 1122 | |
| 1123 | |
| 1124 | def _visible_width(s): |
| 1125 | """Visible width of a printed string. ANSI color codes are removed. |
| 1126 | |
| 1127 | >>> _visible_width('\x1b[31mhello\x1b[0m'), _visible_width("world") |
| 1128 | (5, 5) |
| 1129 | |
| 1130 | """ |
| 1131 | # optional wide-character support |
| 1132 | if wcwidth is not None and WIDE_CHARS_MODE: |
| 1133 | len_fn = wcwidth.wcswidth |
| 1134 | else: |
| 1135 | len_fn = len |
| 1136 | if isinstance(s, (str, bytes)): |
| 1137 | return len_fn(_strip_ansi(s)) |
| 1138 | else: |
| 1139 | return len_fn(str(s)) |
| 1140 | |
| 1141 | |
| 1142 | def _is_multiline(s): |
nothing calls this directly
no test coverage detected