MCPcopy Create free account
hub / github.com/psf/black / str_width

Function str_width

src/black/strings.py:311–321  ·  view source on GitHub ↗

Return the width of `line_str` as it would be displayed in a terminal or editor (which respects Unicode East Asian Width). You could utilize this function to determine, for example, if a string is too wide to display in a terminal or editor.

(line_str: str)

Source from the content-addressed store, hash-verified

309
310
311def str_width(line_str: str) -> int:
312 """Return the width of `line_str` as it would be displayed in a terminal
313 or editor (which respects Unicode East Asian Width).
314
315 You could utilize this function to determine, for example, if a string
316 is too wide to display in a terminal or editor.
317 """
318 if line_str.isascii():
319 # Fast path for a line consisting of only ASCII characters
320 return len(line_str)
321 return sum(map(char_width, line_str))
322
323
324def count_chars_in_width(line_str: str, max_width: int) -> int:

Callers 3

do_transformMethod · 0.90
do_splitter_matchMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected