diff options
author | ulwlu <ooulwluoo@gmail.com> | 2022-02-07 19:06:56 +0900 |
---|---|---|
committer | Thomas Koutcher <thomas.koutcher@online.fr> | 2023-09-04 21:23:47 +0200 |
commit | 16694489460d0aceb39914c3e625a808fe6dc358 (patch) | |
tree | 4fb9fa54a489f385ab1e214efc7521693e418460 | |
parent | 69e40ce74ea4cb7bc648f78f6c62d8bc5dbb2778 (diff) |
Handle oversized string out of maxwidth while string contains ansi codes
-rw-r--r-- | src/ansi.c | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -190,7 +190,20 @@ draw_ansi_line(struct view *view, char *ansi_end_ptr, int after_ansi_len, size_t *skip -= 1; *widths_of_display -= 1; } - waddnstr(view->win, ansi_end_ptr, after_ansi_len); + + if (*cur_width + *widths_of_display > view->width) { + int left_widths = view->width - *cur_width; + while (left_widths > 0) { + utf8proc_int32_t unicode; + int bytes_to_display = utf8proc_iterate((const utf8proc_uint8_t *) ansi_end_ptr, strlen(ansi_end_ptr), &unicode); + waddnstr(view->win, ansi_end_ptr, bytes_to_display); + ansi_end_ptr += bytes_to_display; + after_ansi_len -= bytes_to_display; + left_widths -= 1; + } + } else { + waddnstr(view->win, ansi_end_ptr, after_ansi_len); + } } void |