From 5ded28e38475e265c8cd27742d079a42ad3d39e0 Mon Sep 17 00:00:00 2001 From: Stephan Williams Date: Wed, 26 Jul 2017 20:30:59 -0400 Subject: [PATCH] Truncate should use display width instead of # characters --- src/musikcube/cursespp/Text.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/musikcube/cursespp/Text.cpp b/src/musikcube/cursespp/Text.cpp index 1663d82f3..976d78b20 100755 --- a/src/musikcube/cursespp/Text.cpp +++ b/src/musikcube/cursespp/Text.cpp @@ -51,8 +51,10 @@ namespace cursespp { auto it = str.begin(); auto end = str.end(); - size_t c = 0; - while (c < len && it != str.end()) { + size_t cols = 0; + while (it != str.end()) { + auto prev = it; + try { utf8::next(it, end); } @@ -61,10 +63,13 @@ namespace cursespp { ++it; } - ++c; - } + size_t c = u8cols(std::string(prev, it)); + if (cols + c > len) { + return std::string(str.begin(), prev); + } - return std::string(str.begin(), it); + cols += c; + } } return str;