Calculate the extra amount of width space the given source code segment might take if it were to be displayed on a fixed width output device. Supports wide unicode characters and emojis.
(line, offset=None)
| 974 | _WIDE_CHAR_SPECIFIERS = "WF" |
| 975 | |
| 976 | def _display_width(line, offset=None): |
| 977 | """Calculate the extra amount of width space the given source |
| 978 | code segment might take if it were to be displayed on a fixed |
| 979 | width output device. Supports wide unicode characters and emojis.""" |
| 980 | |
| 981 | if offset is None: |
| 982 | offset = len(line) |
| 983 | |
| 984 | # Fast track for ASCII-only strings |
| 985 | if line.isascii(): |
| 986 | return offset |
| 987 | |
| 988 | import unicodedata |
| 989 | |
| 990 | return sum( |
| 991 | 2 if unicodedata.east_asian_width(char) in _WIDE_CHAR_SPECIFIERS else 1 |
| 992 | for char in line[:offset] |
| 993 | ) |
| 994 | |
| 995 | |
| 996 | def _format_note(note, indent, theme): |
no test coverage detected
searching dependent graphs…