summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-10 01:59:08 -0500
committerJune McEnroe <june@causal.agency>2020-02-10 01:59:08 -0500
commit05fc01b2483dfa203a4f905f294b04325e4111eb (patch)
tree02ab9ea7c3dd31d27fa554d3322ecf2f55e8c194
parentUpdate prompt when own nick changes (diff)
downloadcatgirl-05fc01b2483dfa203a4f905f294b04325e4111eb.tar.gz
catgirl-05fc01b2483dfa203a4f905f294b04325e4111eb.zip
Simplify mark, heat, unread tracking
-rw-r--r--ui.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/ui.c b/ui.c
index d94351a..c331a7c 100644
--- a/ui.c
+++ b/ui.c
@@ -71,11 +71,11 @@ struct Window {
 	size_t id;
 	struct Buffer buffer;
 	WINDOW *pad;
+	int scroll;
 	bool mark;
 	enum Heat heat;
 	int unreadCount;
 	int unreadLines;
-	int scroll;
 	struct Window *prev;
 	struct Window *next;
 };
@@ -114,7 +114,7 @@ static struct Window *windowFor(size_t id) {
 	window->pad = newpad(WindowLines, COLS);
 	if (!window->pad) err(EX_OSERR, "newpad");
 	scrollok(window->pad, true);
-	wmove(window->pad, BufferCap - 1, 0);
+	wmove(window->pad, WindowLines - 1, 0);
 	window->mark = true;
 
 	windowAdd(window);
@@ -356,7 +356,7 @@ static void statusUpdate(void) {
 	int num;
 	const struct Window *window;
 	for (num = 0, window = windows.head; window; ++num, window = window->next) {
-		if (!window->unreadCount && window != windows.active) continue;
+		if (!window->heat && window != windows.active) continue;
 		int unread;
 		char buf[256];
 		snprintf(
@@ -367,7 +367,7 @@ static void statusUpdate(void) {
 			window->unreadCount,
 			idColors[window->id]
 		);
-		if (!window->unreadCount) buf[unread] = '\0';
+		if (!window->mark || !window->unreadCount) buf[unread] = '\0';
 		statusAdd(buf);
 	}
 	wclrtoeol(status);
@@ -379,30 +379,38 @@ static void statusUpdate(void) {
 		self.network, idNames[windows.active->id],
 		&unread, windows.active->unreadCount
 	);
-	if (!windows.active->unreadCount) buf[unread] = '\0';
+	if (!windows.active->mark || !windows.active->unreadCount) {
+		buf[unread] = '\0';
+	}
 	putp(to_status_line);
 	putp(buf);
 	putp(from_status_line);
 	fflush(stdout);
 }
 
+static void mark(struct Window *window) {
+	if (window->scroll) return;
+	window->mark = true;
+	window->unreadCount = 0;
+	window->unreadLines = 0;
+}
+
 static void unmark(struct Window *window) {
 	if (!window->scroll) {
-		window->heat = Cold;
-		window->unreadCount = 0;
 		window->mark = false;
+		window->heat = Cold;
 	}
 	statusUpdate();
 }
 
 static void windowScroll(struct Window *window, int n) {
-	if (!window->scroll) window->mark = true;
+	mark(window);
 	window->scroll += n;
 	if (window->scroll > WindowLines - PAGE_LINES) {
 		window->scroll = WindowLines - PAGE_LINES;
 	}
 	if (window->scroll < 0) window->scroll = 0;
-	if (!window->scroll) unmark(window);
+	unmark(window);
 }
 
 static void windowScrollUnread(struct Window *window) {
@@ -480,7 +488,6 @@ void uiWrite(size_t id, enum Heat heat, const time_t *src, const char *str) {
 
 	int lines = 1;
 	waddch(window->pad, '\n');
-	if (window->mark && !window->unreadCount) window->unreadLines = 0;
 	if (window->mark && heat > Cold) {
 		if (!window->unreadCount++) {
 			lines++;
@@ -646,9 +653,9 @@ static void windowShow(struct Window *window) {
 	touchwin(window->pad);
 	windows.other = windows.active;
 	windows.active = window;
-	windows.other->mark = true;
-	inputUpdate();
+	mark(windows.other);
 	unmark(windows.active);
+	inputUpdate();
 }
 
 void uiShowID(size_t id) {
@@ -722,7 +729,7 @@ static void keyCode(int code) {
 	switch (code) {
 		break; case KEY_RESIZE:  resize();
 		break; case KeyFocusIn:  unmark(window);
-		break; case KeyFocusOut: window->mark = true;
+		break; case KeyFocusOut: mark(window);
 		break; case KeyPasteOn:; // TODO
 		break; case KeyPasteOff:; // TODO
 
/ui.c?h=1.3&id=a6ede6f91f41ca20d02454de3bd33329d35fbbd1&follow=1'>Factor out allocating conversion between wcs and mbsJune McEnroe 2018-08-07Match commands case-insensitivelyJune McEnroe Also include the slash in their names so that they can be added to tab-complete later. 2018-08-07Convert input to multibyte before handlingJune McEnroe 2018-08-07Populate tab-complete listJune McEnroe 2018-08-07Fix /me formatting side-effectsJune McEnroe NEVER pass side-effects to a macro. 2018-08-07Define ui.c BUF_LEN with enumJune McEnroe 2018-08-07Hack clang into checking uiFmt format stringsJune McEnroe 2018-08-07Handle PART and QUIT without messagesJune McEnroe 2018-08-07Make safe filling the who bufferJune McEnroe 2018-08-07Add reverse and reset IRC formatting codesJune McEnroe 2018-08-06Rewrite line editing again, add formattingJune McEnroe 2018-08-06Fix allocation size in vaswprintfJune McEnroe This is so embarrassing. It only started crashing once it had strings that were long enough, and then it took me so long to notice this mistake. I was worried I was still doing va_list wrong somehow. 2018-08-06Implement word wrappingJune McEnroe 2018-08-06Use wchar_t strings for all of UIJune McEnroe vaswprintf is a nightmare. 2018-08-06Rename line editing functionsJune McEnroe 2018-08-05Initialize all possible color pairsJune McEnroe This is actually possible with use_default_colors! 2018-08-05Refactor color initializationJune McEnroe 2018-08-05Add ^L redrawJune McEnroe 2018-08-05Use 16 colors if availableJune McEnroe Fall back to using bold if there are only 8 colors. This also allowed bright background colors in 16-color terminals. I must port this system to torus. I'll be able to remove the awful termcap patch hack. 2018-08-05Limit parsed colors to number of mIRC colorsJune McEnroe Oh boy that's embarrassing. 2018-08-04Show source link on exitJune McEnroe 2018-08-04Implement line editing, scrollingJune McEnroe Don't really have a way to implement the M-* keys, and currently missing C-w. 2018-08-04Handle /topicJune McEnroe