summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-01-16 12:58:16 -0500
committerJune McEnroe <june@causal.agency>2021-01-16 12:58:16 -0500
commitd05872303e2313d28f45569851ddeb238fc4d5ea (patch)
treea746980ed4377ab1625affdd75ebb817aec898b2
parentSave and load the URL ring in the save file (diff)
downloadcatgirl-d05872303e2313d28f45569851ddeb238fc4d5ea.tar.gz
catgirl-d05872303e2313d28f45569851ddeb238fc4d5ea.zip
Generalize ignore toggling to visibility threshold
-rw-r--r--buffer.c9
-rw-r--r--catgirl.110
-rw-r--r--chat.h6
-rw-r--r--ui.c33
4 files changed, 36 insertions, 22 deletions
diff --git a/buffer.c b/buffer.c
index bdf9e3a..ef175b8 100644
--- a/buffer.c
+++ b/buffer.c
@@ -199,7 +199,7 @@ static int flow(struct Lines *hard, int cols, const struct Line *soft) {
 }
 
 int bufferPush(
-	struct Buffer *buffer, int cols, bool ignore,
+	struct Buffer *buffer, int cols, enum Heat thresh,
 	enum Heat heat, time_t time, const char *str
 ) {
 	struct Line *soft = linesNext(&buffer->soft);
@@ -207,11 +207,12 @@ int bufferPush(
 	soft->time = time;
 	soft->str = strdup(str);
 	if (!soft->str) err(EX_OSERR, "strdup");
-	if (heat < Cold && ignore) return 0;
+	if (heat < thresh) return 0;
 	return flow(&buffer->hard, cols, soft);
 }
 
-int bufferReflow(struct Buffer *buffer, int cols, bool ignore, size_t tail) {
+int
+bufferReflow(struct Buffer *buffer, int cols, enum Heat thresh, size_t tail) {
 	buffer->hard.len = 0;
 	for (size_t i = 0; i < BufferCap; ++i) {
 		free(buffer->hard.lines[i].str);
@@ -221,7 +222,7 @@ int bufferReflow(struct Buffer *buffer, int cols, bool ignore, size_t tail) {
 	for (size_t i = 0; i < BufferCap; ++i) {
 		const struct Line *soft = bufferSoft(buffer, i);
 		if (!soft) continue;
-		if (soft->heat < Cold && ignore) continue;
+		if (soft->heat < thresh) continue;
 		int n = flow(&buffer->hard, cols, soft);
 		if (i >= BufferCap - tail) flowed += n;
 	}
diff --git a/catgirl.1 b/catgirl.1
index 35e984d..e6f50c1 100644
--- a/catgirl.1
+++ b/catgirl.1
@@ -1,4 +1,4 @@
-.Dd January 10, 2021
+.Dd January 16, 2021
 .Dt CATGIRL 1
 .Os
 .
@@ -545,8 +545,14 @@ Scroll to previous line matching input.
 Scroll to next line matching input.
 .It Ic C-v
 Scroll down a page.
+.It Ic M-+
+Raise message visibility threshold,
+hiding ignored messages,
+general events,
+or non-highlighted messages.
 .It Ic M--
-Toggle visibility of filtered messages.
+Lower message visibility threshold,
+showing ignored messages.
 .It Ic M-=
 Toggle mute.
 Muted windows do not appear in the status line
diff --git a/chat.h b/chat.h
index b5e546a..e027fa5 100644
--- a/chat.h
+++ b/chat.h
@@ -309,10 +309,12 @@ void bufferFree(struct Buffer *buffer);
 const struct Line *bufferSoft(const struct Buffer *buffer, size_t i);
 const struct Line *bufferHard(const struct Buffer *buffer, size_t i);
 int bufferPush(
-	struct Buffer *buffer, int cols, bool ignore,
+	struct Buffer *buffer, int cols, enum Heat thresh,
 	enum Heat heat, time_t time, const char *str
 );
-int bufferReflow(struct Buffer *buffer, int cols, bool ignore, size_t tail);
+int bufferReflow(
+	struct Buffer *buffer, int cols, enum Heat thresh, size_t tail
+);
 
 enum Edit {
 	EditHead,
diff --git a/ui.c b/ui.c
index 0a0342e..0d234a7 100644
--- a/ui.c
+++ b/ui.c
@@ -78,7 +78,7 @@ struct Window {
 	int scroll;
 	bool mark;
 	bool mute;
-	bool ignore;
+	enum Heat thresh;
 	enum Heat heat;
 	uint unreadSoft;
 	uint unreadHard;
@@ -135,7 +135,7 @@ static uint windowFor(uint id) {
 
 	window->id = id;
 	window->mark = true;
-	window->ignore = true;
+	window->thresh = Cold;
 	window->buffer = bufferAlloc();
 
 	return windowPush(window);
@@ -204,8 +204,9 @@ static short colorPair(short fg, short bg) {
 	X(KeyMetaEnter, "\33\r", "\33\n") \
 	X(KeyMetaGt, "\33>", "\33.") \
 	X(KeyMetaLt, "\33<", "\33,") \
-	X(KeyMetaEqual, "\33=", "\33+") \
+	X(KeyMetaEqual, "\33=", NULL) \
 	X(KeyMetaMinus, "\33-", "\33_") \
+	X(KeyMetaPlus, "\33+", NULL) \
 	X(KeyMetaSlash, "\33/", "\33?") \
 	X(KeyFocusIn, "\33[I", NULL) \
 	X(KeyFocusOut, "\33[O", NULL) \
@@ -388,8 +389,9 @@ static void statusUpdate(void) {
 			&cat, "\3%d%s %u ",
 			idColors[window->id], (num == windows.show ? "\26" : ""), num
 		);
-		if (!window->ignore || window->mute) {
-			catf(&cat, "%s%s ", &"-"[window->ignore], &"="[!window->mute]);
+		if (window->thresh != Cold || window->mute) {
+			const char *thresh[] = { "-", "", "+", "++" };
+			catf(&cat, "%s%s ", thresh[window->thresh], &"="[!window->mute]);
 		}
 		catf(&cat, "%s ", idNames[window->id]);
 		if (window->mark && window->unreadWarm) {
@@ -560,7 +562,7 @@ void uiWrite(uint id, enum Heat heat, const time_t *src, const char *str) {
 	struct Window *window = windows.ptrs[windowFor(id)];
 	time_t ts = (src ? *src : time(NULL));
 
-	if (heat > Ice || !window->ignore) {
+	if (heat >= window->thresh) {
 		if (!window->unreadSoft++) window->unreadHard = 0;
 	}
 	if (window->mark && heat > Cold) {
@@ -575,7 +577,7 @@ void uiWrite(uint id, enum Heat heat, const time_t *src, const char *str) {
 		if (heat > window->heat) window->heat = heat;
 		statusUpdate();
 	}
-	int lines = bufferPush(window->buffer, COLS, window->ignore, heat, ts, str);
+	int lines = bufferPush(window->buffer, COLS, window->thresh, heat, ts, str);
 	window->unreadHard += lines;
 	if (window->scroll) windowScroll(window, lines);
 	if (window == windows.ptrs[windows.show]) windowUpdate();
@@ -605,7 +607,7 @@ static void resize(void) {
 	for (uint num = 0; num < windows.len; ++num) {
 		struct Window *window = windows.ptrs[num];
 		window->unreadHard = bufferReflow(
-			window->buffer, COLS, window->ignore, window->unreadSoft
+			window->buffer, COLS, window->thresh, window->unreadSoft
 		);
 	}
 	windowUpdate();
@@ -781,10 +783,12 @@ void uiCloseNum(uint num) {
 	if (num < windows.len) windowClose(num);
 }
 
-static void toggleIgnore(struct Window *window) {
-	window->ignore ^= true;
+static void incThresh(struct Window *window, int n) {
+	if (n < 0 && window->thresh == Ice) return;
+	if (n > 0 && window->thresh == Hot) return;
+	window->thresh += n;
 	window->unreadHard = bufferReflow(
-		window->buffer, COLS, window->ignore, window->unreadSoft
+		window->buffer, COLS, window->thresh, window->unreadSoft
 	);
 	windowUpdate();
 	statusUpdate();
@@ -828,7 +832,8 @@ static void keyCode(int code) {
 
 		break; case KeyMetaEnter: edit(id, EditInsert, L'\n');
 		break; case KeyMetaEqual: window->mute ^= true; statusUpdate();
-		break; case KeyMetaMinus: toggleIgnore(window);
+		break; case KeyMetaMinus: incThresh(window, -1);
+		break; case KeyMetaPlus:  incThresh(window, +1);
 		break; case KeyMetaSlash: windowShow(windows.swap);
 
 		break; case KeyMetaGt: windowScroll(window, -BufferCap);
@@ -1050,10 +1055,10 @@ void uiLoad(const char *name) {
 			if (!time) break;
 			enum Heat heat = (version > 2 ? readTime(file) : Cold);
 			readString(file, &buf, &cap);
-			bufferPush(window->buffer, COLS, window->ignore, heat, time, buf);
+			bufferPush(window->buffer, COLS, window->thresh, heat, time, buf);
 		}
 		window->unreadHard = bufferReflow(
-			window->buffer, COLS, window->ignore, window->unreadSoft
+			window->buffer, COLS, window->thresh, window->unreadSoft
 		);
 	}
 	urlLoad(file, version);