Skip to content

Commit

Permalink
fall back to len() if wcswidth returns negative value
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWaldmann committed May 24, 2016
1 parent e134f65 commit 7673aa4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion borg/platform_posix.pyx
Expand Up @@ -2,4 +2,9 @@ cdef extern from "wchar.h":
cdef int wcswidth(const Py_UNICODE *str, size_t n)

def swidth(s):
return wcswidth(s, len(s))
str_len = len(s)
terminal_width = wcswidth(s, str_len)
if terminal_width >= 0:
return terminal_width
else:
return str_len

0 comments on commit 7673aa4

Please sign in to comment.