platform_posix.pyx 254 B

12345678910
  1. cdef extern from "wchar.h":
  2. cdef int wcswidth(const Py_UNICODE *str, size_t n)
  3. def swidth(s):
  4. str_len = len(s)
  5. terminal_width = wcswidth(s, str_len)
  6. if terminal_width >= 0:
  7. return terminal_width
  8. else:
  9. return str_len