diff options
author | James Booth <boothj5@gmail.com> | 2015-07-30 01:31:11 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-07-30 01:31:11 +0100 |
commit | 41c93c33502e92583100010b2ca6cb61d1323cff (patch) | |
tree | d8f26826bdaf90b29c6edf9be158809c960fc001 /src/ui | |
parent | 8ec931eb84896ae261b39cd884d4463338b7f2b2 (diff) | |
download | profani-tty-41c93c33502e92583100010b2ca6cb61d1323cff.tar.gz |
Handle larger than line words in wrapping
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/window.c | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/src/ui/window.c b/src/ui/window.c index daf701bb..95e89849 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1085,6 +1085,7 @@ _win_print_wrapped(WINDOW *win, const char * const message, size_t indent, int p // handle word } else { wordi = 0; + int wordlen = 0; while (*curr_ch != ' ' && *curr_ch != '\n' && *curr_ch != '\0') { size_t ch_len = mbrlen(curr_ch, 4, NULL); int offset = 0; @@ -1094,21 +1095,44 @@ _win_print_wrapped(WINDOW *win, const char * const message, size_t indent, int p curr_ch = g_utf8_next_char(curr_ch); } word[wordi] = '\0'; + wordlen = utf8_display_len(word); int curx = getcurx(win); int cury = getcury(win); int maxx = getmaxx(win); - gboolean firstline = (cury == starty); - // word larger than line - if ((firstline && (utf8_display_len(word) > (maxx - indent))) || - (!firstline && (utf8_display_len(word) > (maxx - (indent + pad_indent))))) { + // wrap required + if (curx + wordlen > maxx) { + int linelen = maxx - (indent + pad_indent); + + // word larger than line + if (wordlen > linelen) { + gchar *word_ch = g_utf8_offset_to_pointer(word, 0); + while(*word_ch != '\0') { + curx = getcurx(win); + cury = getcury(win); + gboolean firstline = cury == starty; + + if (firstline && curx < indent) { + _win_indent(win, indent); + } + if (!firstline && curx < (indent + pad_indent)) { + _win_indent(win, indent + pad_indent); + } + + gchar copy[wordi+1]; + g_utf8_strncpy(copy, word_ch, 1); + waddstr(win, copy); + + word_ch = g_utf8_next_char(word_ch); + } - gchar *word_ch = g_utf8_offset_to_pointer(word, 0); - while(*word_ch != '\0') { + // newline and print word + } else { + waddch(win, '\n'); curx = getcurx(win); cury = getcury(win); - firstline = cury == starty; + gboolean firstline = cury == starty; if (firstline && curx < indent) { _win_indent(win, indent); @@ -1116,30 +1140,22 @@ _win_print_wrapped(WINDOW *win, const char * const message, size_t indent, int p if (!firstline && curx < (indent + pad_indent)) { _win_indent(win, indent + pad_indent); } - - gchar copy[wordi++]; - g_utf8_strncpy(copy, word_ch, 1); - - if (curx + utf8_display_len(copy) > maxx) { - waddch(win, '\n'); - _win_indent(win, indent + pad_indent); - } - waddstr(win, copy); - - word_ch = g_utf8_next_char(word_ch); + waddstr(win, word); } + + // no wrap required } else { - if (curx + utf8_display_len(word) > maxx) { - waddch(win, '\n'); - _win_indent(win, indent + pad_indent); - } + curx = getcurx(win); + cury = getcury(win); + gboolean firstline = cury == starty; + if (firstline && curx < indent) { _win_indent(win, indent); } if (!firstline && curx < (indent + pad_indent)) { _win_indent(win, indent + pad_indent); } - wprintw(win, "%s", word); + waddstr(win, word); } } |