From 3f3fa34d8aa914e6d65e524d4ab3cd944082cde7 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Mon, 6 Aug 2018 15:12:13 -0400 Subject: Implement word wrapping --- pls.c | 2 +- ui.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pls.c b/pls.c index bd40dbd..c6071c7 100644 --- a/pls.c +++ b/pls.c @@ -26,7 +26,7 @@ wchar_t *wcssep(wchar_t **stringp, const wchar_t *delim) { size_t i = wcscspn(orig, delim); *stringp = NULL; if (orig[i]) { - orig[i] = '\0'; + orig[i] = L'\0'; *stringp = &orig[i + 1]; } return orig; diff --git a/ui.c b/ui.c index 5f5efc3..9c77668 100644 --- a/ui.c +++ b/ui.c @@ -198,17 +198,36 @@ static const wchar_t *parseColor(short *pair, const wchar_t *str) { return str; } +static void wordWrap(WINDOW *win, const wchar_t *str) { + size_t len = wcscspn(str, L" "); + size_t width = 1; + for (size_t i = 0; i < len; ++i) { + if (iswprint(str[i])) width += wcwidth(str[i]); + } + + int _, x, xMax; + getyx(win, _, x); + getmaxyx(win, _, xMax); + + if (width >= (size_t)(xMax - x)) { + waddch(win, '\n'); + } else { + waddch(win, ' '); + } +} + static void addIRC(WINDOW *win, const wchar_t *str) { attr_t attr = A_NORMAL; short pair = -1; for (;;) { - size_t cc = wcscspn(str, L"\2\3\35\37"); + size_t cc = wcscspn(str, L" \2\3\35\37"); wattr_set(win, attr | attr8(pair), 1 + pair8(pair), NULL); waddnwstr(win, str, cc); if (!str[cc]) break; str = &str[cc]; switch (*str++) { + break; case L' ': wordWrap(win, str); break; case L'\2': attr ^= A_BOLD; break; case L'\3': str = parseColor(&pair, str); break; case L'\35': attr ^= A_ITALIC; -- cgit 1.4.1 e9d8346c8b352aea5f2096a459d'/>
path: root/www/photo.causal.agency/.gitignore (unfollow)
Commit message (Expand)Author
6 hoursAdd The Girl Who Was Convinced...June McEnroe
25 hoursAdd photos from May 31June McEnroe
25 hoursUse monospace on photo pagesJune McEnroe
25 hoursPut lens and (future) film at the tops of photo pagesJune McEnroe
2024-05-22Remove use of sysexits.hJune McEnroe
2024-05-22Add photo descriptions from 05-03 and 05-06June McEnroe
2024-05-21Fix = precedence in whenJune McEnroe