MCPcopy Create free account
hub / github.com/astanin/python-tabulate / _visible_width

Function _visible_width

tabulate/__init__.py:1124–1139  ·  view source on GitHub ↗

Visible width of a printed string. ANSI color codes are removed. >>> _visible_width('\x1b[31mhello\x1b[0m'), _visible_width("world") (5, 5)

(s)

Source from the content-addressed store, hash-verified

1122
1123
1124def _visible_width(s):
1125 """Visible width of a printed string. ANSI color codes are removed.
1126
1127 >>> _visible_width('\x1b[31mhello\x1b[0m'), _visible_width("world")
1128 (5, 5)
1129
1130 """
1131 # optional wide-character support
1132 if wcwidth is not None and WIDE_CHARS_MODE:
1133 len_fn = wcwidth.wcswidth
1134 else:
1135 len_fn = len
1136 if isinstance(s, (str, bytes)):
1137 return len_fn(_strip_ansi(s))
1138 else:
1139 return len_fn(str(s))
1140
1141
1142def _is_multiline(s):

Callers

nothing calls this directly

Calls 1

_strip_ansiFunction · 0.85

Tested by

no test coverage detected