about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-08-06 15:12:13 -0400
committerJune McEnroe <june@causal.agency>2018-08-06 15:12:13 -0400
commit3f3fa34d8aa914e6d65e524d4ab3cd944082cde7 (patch)
tree484215d19fac54af7c77b6b48a7afca7581e943e
parentUse wchar_t strings for all of UI (diff)
downloadcatgirl-3f3fa34d8aa914e6d65e524d4ab3cd944082cde7.tar.gz
catgirl-3f3fa34d8aa914e6d65e524d4ab3cd944082cde7.zip
Implement word wrapping
Diffstat (limited to '')
-rw-r--r--pls.c2
-rw-r--r--ui.c21
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;
05 12:39:40 -0500'>2018-03-05Undef COLOR_ constants in torus.hJune McEnroe 2018-03-05Generate tagsJune McEnroe 2017-10-03Simplify Makefile with pattern ruleJune McEnroe 2017-09-27Remove leading blank linesJune McEnroe 2017-09-27Add merge.c to READMEJune McEnroe 2017-09-03Assert client coords are valid after movementJune McEnroe 2017-09-03Relicense AGPLJune McEnroe 2017-09-01Revert "Add client readOnly mode"June McEnroe 2017-09-01Remove clientRemove call from clientCastJune McEnroe 2017-09-01Add client readOnly modeJune McEnroe 2017-08-31Clean up merge toolJune McEnroe 2017-08-31Choose B for tiles with equal modify timesJune McEnroe 2017-08-31Add quick data file merge toolJune McEnroe 2017-08-30Use only foreground color for selecting spawnJune McEnroe 2017-08-29Add four additional spawnsJune McEnroe 2017-08-28Add respawningJune McEnroe 2017-08-26Move license above includesJune McEnroe 2017-08-26Snapshot metadataJune McEnroe 2017-08-26Add meta.c to READMEJune McEnroe 2017-08-26Use MakefileJune McEnroe roughly a second on a big PNG screenshot. Almost all the remaining time is spent in deflate. 2021-09-21Rewrite pngo, add explicit optionsJune McEnroe Interesting to see how my code habits have changed. 2021-09-16Fix /* **/ comment matchingJune McEnroe 2021-09-15Remove typer, add downgrade to READMEJune McEnroe 2021-09-15Set bot mode on downgradeJune McEnroe 2021-09-15Enter capsicum in downgradeJune McEnroe 2021-09-15Factor out common parts of downgrade messagesJune McEnroe Also bump the message cap to 1024 because that is ostensibly useful for replying to older messages. 2021-09-14Add downgrade IRC botJune McEnroe 2021-09-14Sort by title if authors matchJune McEnroe There are probably better things to sort by but title definitely always exists. 2021-09-13Swap-remove tags as they're foundJune McEnroe This makes it even faster. From ~1s on a sqlite3.c amalgamation to ~0.85s. 2021-09-12Replace htagml regex with strncmpJune McEnroe Since ctags only ever produces regular expressions of the form /^re$/ or /^re/ with no other special characters, instead unescape the pattern and simply use strncmp. Running on a sqlite3.c amalgamation, the regex version takes ~37s while the strncmp version takes ~1s, producing identical output. Big win! 2021-09-11Also defer printing comment for lone close-parensJune McEnroe 2021-09-10Publish "git-comment"June McEnroe 2021-09-10Add git comment --pretty optionJune McEnroe 2021-09-08Defer printing comment if line is blank or closing braceJune McEnroe This fixes badly indented comments. 2021-09-08Up default min-repeat to 30 linesJune McEnroe 2021-09-08Handle dirty lines in git-commentJune McEnroe 2021-09-08Document and install git-commentJune McEnroe 2021-09-08Add repeat and all options to git-commentJune McEnroe 2021-09-08Add group threshold to git-commentJune McEnroe