MCPcopy Create free account
hub / github.com/pytest-dev/pytest / wcswidth

Function wcswidth

src/_pytest/_io/wcwidth.py:44–55  ·  view source on GitHub ↗

Determine how many columns are needed to display a string in a terminal. Returns -1 if the string contains non-printable characters.

(s: str)

Source from the content-addressed store, hash-verified

42
43
44def wcswidth(s: str) -> int:
45 """Determine how many columns are needed to display a string in a terminal.
46
47 Returns -1 if the string contains non-printable characters.
48 """
49 width = 0
50 for c in unicodedata.normalize("NFC", s):
51 wc = wcwidth(c)
52 if wc < 0:
53 return -1
54 width += wc
55 return width

Callers 5

_format_trimmedFunction · 0.90
checkFunction · 0.90
test_wcswidthFunction · 0.90
width_of_current_lineMethod · 0.85

Calls 1

wcwidthFunction · 0.85

Tested by 2

checkFunction · 0.72
test_wcswidthFunction · 0.72