Explorar o código

fall back to len() if wcswidth returns neg. value, fixes #1090

Thomas Waldmann %!s(int64=9) %!d(string=hai) anos
pai
achega
c4c11d75a1
Modificáronse 1 ficheiros con 6 adicións e 1 borrados
  1. 6 1
      borg/platform_posix.pyx

+ 6 - 1
borg/platform_posix.pyx

@@ -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