fix error in line printing

This commit is contained in:
Florian Stinglmayr 2019-07-17 19:48:58 +02:00
parent eebc9343b0
commit d43d008cb8

View File

@ -203,7 +203,7 @@ ncdc_textview_render_msgs(ncdc_textview_t v, WINDOW *win, int lines, int cols)
for (i = msgs-1; i >= 0; i--) { for (i = msgs-1; i >= 0; i--) {
dc_message_t m = dc_channel_nth_message(v->channel, i); dc_message_t m = dc_channel_nth_message(v->channel, i);
wchar_t *s = ncdc_textview_format(m); wchar_t *s = ncdc_textview_format(m);
wchar_t const *end = s, *last = NULL; wchar_t const *end = s, *last = s;
size_t len = 0; size_t len = 0;
size_t needed_lines = 0; size_t needed_lines = 0;
@ -211,16 +211,13 @@ ncdc_textview_render_msgs(ncdc_textview_t v, WINDOW *win, int lines, int cols)
*/ */
while ((end = wcschr(end, '\n')) != NULL) { while ((end = wcschr(end, '\n')) != NULL) {
++needed_lines; ++needed_lines;
++end;
len = wcswidth(last, (end - last)); len = wcswidth(last, (end - last - 1));
needed_lines += (len % cols); needed_lines += (len / cols);
last = end; last = end;
} }
if (last == NULL) {
last = s;
}
len = wcswidth(last, wcslen(last)); len = wcswidth(last, wcslen(last));
needed_lines += (len / cols) + 1; needed_lines += (len / cols) + 1;