fix scrolling text which contains both normal and wide characters

This commit is contained in:
Andrzej Rybczak
2009-08-26 03:39:14 +02:00
parent 89e18096d9
commit 56a1d7456c
2 changed files with 8 additions and 12 deletions

View File

@@ -368,22 +368,16 @@ std::basic_string<my_char_t> Scroller(const std::basic_string<my_char_t> &str, s
std::basic_string<my_char_t>::const_iterator b = s.begin(), e = s.end(); std::basic_string<my_char_t>::const_iterator b = s.begin(), e = s.end();
for (std::basic_string<my_char_t>::const_iterator it = b+pos; it < e && len < width; ++it) for (std::basic_string<my_char_t>::const_iterator it = b+pos; it < e && len < width; ++it)
{ {
# ifdef _UTF8 if ((len += wcwidth(*it)) > width)
len += wcwidth(*it); break;
# else
len++;
# endif
result += *it; result += *it;
} }
if (++pos >= s.length()) if (++pos >= s.length())
pos = 0; pos = 0;
for (; len < width; ++b) for (; len < width; ++b)
{ {
# ifdef _UTF8 if ((len += wcwidth(*b)) > width)
len += wcwidth(*b); break;
# else
len++;
# endif
result += *b; result += *b;
} }
} }

View File

@@ -169,7 +169,8 @@ template <typename C> void NCurses::basic_buffer<C>::Write(Window &w, size_t &po
LoadAttribute(w, lb->Value); LoadAttribute(w, lb->Value);
++lb; ++lb;
} }
len += wcwidth(s[i]); if ((len += wcwidth(s[i])) > width)
break;
w << s[i]; w << s[i];
} }
if (++pos >= s.length()) if (++pos >= s.length())
@@ -184,7 +185,8 @@ template <typename C> void NCurses::basic_buffer<C>::Write(Window &w, size_t &po
LoadAttribute(w, lb->Value); LoadAttribute(w, lb->Value);
++lb; ++lb;
} }
len += wcwidth(s[i]); if ((len += wcwidth(s[i])) > width)
break;
w << s[i]; w << s[i];
} }
// load all remained attributes to clean up // load all remained attributes to clean up