summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-14 05:00:26 -0500
committerJune McEnroe <june@causal.agency>2020-02-14 05:19:33 -0500
commitfbdfb360851d9926a739f7d02d0f4a3cd9cfc217 (patch)
tree1078eec7e53d86bcf5fc1cf3b745d60aaef2628c
parentDon't copy into cut buffer during tab complete (diff)
downloadcatgirl-fbdfb360851d9926a739f7d02d0f4a3cd9cfc217.tar.gz
catgirl-fbdfb360851d9926a739f7d02d0f4a3cd9cfc217.zip
Track unreadTotal and unreadWarm separately
Otherwise reflow's calculation of unreadLines is always going to be
wrong if there were Cold lines interspersed.
-rw-r--r--ui.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/ui.c b/ui.c
index f44a78b..f5c4936 100644
--- a/ui.c
+++ b/ui.c
@@ -84,7 +84,8 @@ struct Window {
 	int scroll;
 	bool mark;
 	enum Heat heat;
-	int unreadCount;
+	int unreadTotal;
+	int unreadWarm;
 	int unreadLines;
 };
 
@@ -406,7 +407,7 @@ static void statusUpdate(void) {
 		const struct Window *window = windows.ptrs[num];
 		if (!window->heat && num != windows.show) continue;
 		if (num != windows.show) {
-			otherUnread += window->unreadCount;
+			otherUnread += window->unreadWarm;
 			if (window->heat > otherHeat) otherHeat = window->heat;
 		}
 		int trunc;
@@ -416,20 +417,20 @@ static void statusUpdate(void) {
 			idColors[window->id], (num == windows.show ? "\26" : ""),
 			num, idNames[window->id],
 			&trunc, (window->heat > Warm ? White : idColors[window->id]),
-			window->unreadCount,
+			window->unreadWarm,
 			idColors[window->id]
 		);
-		if (!window->mark || !window->unreadCount) buf[trunc] = '\0';
+		if (!window->mark || !window->unreadWarm) buf[trunc] = '\0';
 		statusAdd(buf);
 	}
 	wclrtoeol(status);
 
 	const struct Window *window = windows.ptrs[windows.show];
 	snprintf(title, sizeof(title), "%s %s", self.network, idNames[window->id]);
-	if (window->mark && window->unreadCount) {
+	if (window->mark && window->unreadWarm) {
 		snprintf(
 			&title[strlen(title)], sizeof(title) - strlen(title),
-			" (%d%s)", window->unreadCount, (window->heat > Warm ? "!" : "")
+			" (%d%s)", window->unreadWarm, (window->heat > Warm ? "!" : "")
 		);
 	}
 	if (otherUnread) {
@@ -443,7 +444,8 @@ static void statusUpdate(void) {
 static void mark(struct Window *window) {
 	if (window->scroll) return;
 	window->mark = true;
-	window->unreadCount = 0;
+	window->unreadTotal = 0;
+	window->unreadWarm = 0;
 	window->unreadLines = 0;
 }
 
@@ -588,12 +590,13 @@ void uiWrite(size_t id, enum Heat heat, const time_t *src, const char *str) {
 
 	int lines = 1;
 	waddch(window->pad, '\n');
+	window->unreadTotal++;
 	if (window->mark && heat > Cold) {
-		if (!window->unreadCount++) {
-			lines++;
+		if (window->heat < heat) window->heat = heat;
+		if (!window->unreadWarm++) {
 			waddch(window->pad, '\n');
+			lines++;
 		}
-		if (window->heat < heat) window->heat = heat;
 		statusUpdate();
 	}
 	lines += wordWrap(window->pad, str);
@@ -625,7 +628,7 @@ static void reflow(struct Window *window) {
 		const char *line = bufferLine(&window->buffer, i);
 		if (!line) continue;
 		waddch(window->pad, '\n');
-		if (i >= (size_t)(BufferCap - window->unreadCount)) {
+		if (i >= (size_t)(BufferCap - window->unreadTotal)) {
 			window->unreadLines += 1 + wordWrap(window->pad, line);
 		} else {
 			wordWrap(window->pad, line);