diff options
author | June McEnroe <june@causal.agency> | 2020-02-01 22:40:55 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-02-01 22:41:30 -0500 |
commit | 05256b68fef9d9b64b01afb60de31f9c47b60ca1 (patch) | |
tree | 97a6b3e5fbcdf22f01f5616c7c9f01d437eaa0ba /ui.c | |
parent | Parse IRC styling in UI (diff) | |
download | test-05256b68fef9d9b64b01afb60de31f9c47b60ca1.tar.gz test-05256b68fef9d9b64b01afb60de31f9c47b60ca1.zip |
Implement word wrap
This actually wasn't that bad?
Diffstat (limited to 'ui.c')
-rw-r--r-- | ui.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/ui.c b/ui.c index 83c4bc7..7ce0257 100644 --- a/ui.c +++ b/ui.c @@ -209,11 +209,33 @@ static void styleParse(struct Style *style, const char **str, size_t *len) { *len = strcspn(*str, "\2\3\17\26\35\37"); } +static int wordWidth(const char *str) { + size_t len = strcspn(str, " "); + // TODO: wcswidth. + return len; +} + static void styleAdd(WINDOW *win, const char *str) { + int _, x, width; + getmaxyx(win, _, width); + size_t len; struct Style style = Reset; while (*str) { + if (*str == ' ') { + const char *word = &str[strspn(str, " ")]; + getyx(win, _, x); + if (width - x - 1 < wordWidth(word)) { + waddch(win, '\n'); + str = word; + } + } + styleParse(&style, &str, &len); + size_t sp = strspn(str, " "); + sp += strcspn(&str[sp], " "); + if (sp < len) len = sp; + wattr_set( win, style.attr | colorAttr(mapColor(style.fg)), |