瀏覽代碼

Merge pull request #1091 from ThomasWaldmann/swidth-fallback

fall back to len() if wcswidth returns negative value
TW 9 年之前
父節點
當前提交
4c4aa64410
共有 1 個文件被更改,包括 6 次插入1 次删除
  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)
     cdef int wcswidth(const Py_UNICODE *str, size_t n)
  
  
 def swidth(s):
 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