From c4c11d75a14cf8c67f3e141ca925b6890bf86674 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Tue, 24 May 2016 22:16:47 +0200 Subject: [PATCH] fall back to len() if wcswidth returns neg. value, fixes #1090 --- borg/platform_posix.pyx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/borg/platform_posix.pyx b/borg/platform_posix.pyx index f2a8e1773..8d74f19e8 100644 --- a/borg/platform_posix.pyx +++ b/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