summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-09-14 18:54:18 -0400
committerJune McEnroe <june@causal.agency>2018-09-14 18:54:18 -0400
commit714a703935ceff4c676706584ef612e2ca6e105f (patch)
treebd64fe854c1781d29396410c174428fbf92599e4
parentRemove word handling from formatParse (diff)
downloadcatgirl-714a703935ceff4c676706584ef612e2ca6e105f.tar.gz
catgirl-714a703935ceff4c676706584ef612e2ca6e105f.zip
Check width of entire next word including codes
This results in a tiny bit of premature wrapping for color codes, but
that isn't a problem.
-rw-r--r--ui.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/ui.c b/ui.c
index b1e56c7..0e22fd8 100644
--- a/ui.c
+++ b/ui.c
@@ -193,6 +193,14 @@ static void addFormat(WINDOW *win, const struct Format *format) {
 	waddnwstr(win, format->str, format->len);
 }
 
+static int printWidth(const wchar_t *str, size_t len) {
+	int width = 0;
+	for (size_t i = 0; i < len; ++i) {
+		if (iswprint(str[i])) width += wcwidth(str[i]);
+	}
+	return width;
+}
+
 static int addWrap(WINDOW *win, const wchar_t *str) {
 	int lines = 0;
 
@@ -205,7 +213,7 @@ static int addWrap(WINDOW *win, const wchar_t *str) {
 		int _, x, xMax;
 		getyx(win, _, x);
 		getmaxyx(win, _, xMax);
-		if (xMax - x - 1 < wcswidth(format.str, format.len)) {
+		if (xMax - x - 1 < printWidth(format.str, word)) {
 			if (format.str[0] == L' ') {
 				format.str++;
 				format.len--;