Check width of entire next word including codes

This results in a tiny bit of premature wrapping for color codes, but
that isn't a problem.
weechat-hashes
Curtis McEnroe 2018-09-14 18:54:18 -04:00
parent 6aa42b852b
commit 714a703935
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
1 changed files with 9 additions and 1 deletions

10
ui.c
View File

@ -193,6 +193,14 @@ static void addFormat(WINDOW *win, const struct Format *format) {
waddnwstr(win, format->str, format->len); waddnwstr(win, format->str, format->len);
} }
static int printWidth(const wchar_t *str, size_t len) {
int width = 0;
for (size_t i = 0; i < len; ++i) {
if (iswprint(str[i])) width += wcwidth(str[i]);
}
return width;
}
static int addWrap(WINDOW *win, const wchar_t *str) { static int addWrap(WINDOW *win, const wchar_t *str) {
int lines = 0; int lines = 0;
@ -205,7 +213,7 @@ static int addWrap(WINDOW *win, const wchar_t *str) {
int _, x, xMax; int _, x, xMax;
getyx(win, _, x); getyx(win, _, x);
getmaxyx(win, _, xMax); getmaxyx(win, _, xMax);
if (xMax - x - 1 < wcswidth(format.str, format.len)) { if (xMax - x - 1 < printWidth(format.str, word)) {
if (format.str[0] == L' ') { if (format.str[0] == L' ') {
format.str++; format.str++;
format.len--; format.len--;