r""" Determine the width that a character is likely to be displayed as in a monospaced terminal. The width for a printable character will always be 0, 1, or 2. Nonprintable or control characters will return -1, a convention that comes from wcwidth. >>> character_width('車')
(char: str)
| 14 | |
| 15 | |
| 16 | def character_width(char: str) -> int: |
| 17 | r""" |
| 18 | Determine the width that a character is likely to be displayed as in |
| 19 | a monospaced terminal. The width for a printable character will |
| 20 | always be 0, 1, or 2. |
| 21 | |
| 22 | Nonprintable or control characters will return -1, a convention that comes |
| 23 | from wcwidth. |
| 24 | |
| 25 | >>> character_width('車') |
| 26 | 2 |
| 27 | >>> character_width('A') |
| 28 | 1 |
| 29 | >>> character_width('\N{ZERO WIDTH JOINER}') |
| 30 | 0 |
| 31 | >>> character_width('\n') |
| 32 | -1 |
| 33 | """ |
| 34 | return int(wcwidth(char)) |
| 35 | |
| 36 | |
| 37 | def monospaced_width(text: str) -> int: |
no outgoing calls
no test coverage detected