MCPcopy
hub / github.com/rspeer/python-ftfy / character_width

Function character_width

ftfy/formatting.py:16–34  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

14
15
16def 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
37def monospaced_width(text: str) -> int:

Callers 3

display_ljustFunction · 0.85
display_rjustFunction · 0.85
display_centerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected