summary refs log tree commit diff
path: root/chat.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--chat.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/chat.c b/chat.c
index 3402621..3aa4ad2 100644
--- a/chat.c
+++ b/chat.c
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <locale.h>
 #include <poll.h>
+#include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -34,7 +35,7 @@ char *idNames[IDCap] = {
 
 enum Color idColors[IDCap] = {
 	[None] = Black,
-	[Debug] = Red,
+	[Debug] = Green,
 	[Network] = Gray,
 };
 
@@ -42,6 +43,11 @@ size_t idNext = Network + 1;
 
 struct Self self;
 
+static volatile sig_atomic_t signals[NSIG];
+static void signalHandler(int signal) {
+	signals[signal] = 1;
+}
+
 int main(int argc, char *argv[]) {
 	setlocale(LC_CTYPE, "");
 
@@ -100,6 +106,11 @@ int main(int argc, char *argv[]) {
 	ircFormat("NICK :%s\r\n", nick);
 	ircFormat("USER %s 0 * :%s\r\n", user, real);
 
+	signal(SIGHUP, signalHandler);
+	signal(SIGINT, signalHandler);
+	signal(SIGTERM, signalHandler);
+	sig_t cursesWinch = signal(SIGWINCH, signalHandler);
+
 	struct pollfd fds[2] = {
 		{ .events = POLLIN, .fd = STDIN_FILENO },
 		{ .events = POLLIN, .fd = irc },
@@ -108,8 +119,20 @@ int main(int argc, char *argv[]) {
 		int nfds = poll(fds, 2, -1);
 		if (nfds < 0 && errno != EINTR) err(EX_IOERR, "poll");
 
+		if (signals[SIGHUP] || signals[SIGINT] || signals[SIGTERM]) {
+			break;
+		}
+		if (signals[SIGWINCH]) {
+			signals[SIGWINCH] = 0;
+			cursesWinch(SIGWINCH);
+			fds[0].revents = POLLIN;
+		}
+
 		if (fds[0].revents) uiRead();
 		if (fds[1].revents) ircRecv();
 		uiDraw();
 	}
+
+	ircFormat("QUIT\r\n");
+	uiHide();
 }
e54b84aaf38685c717186a&follow=1'>Add photos from June 25-30June McEnroe 2024-06-30Add photos from June 22 (and the few days after that)June McEnroe 2024-06-30Accommodate lower-case .jpg filesJune McEnroe 2024-06-23Add another BACKXWASH showJune McEnroe It was good! 2024-06-16Update bioJune McEnroe 2024-06-15Add photo descriptions from June 12June McEnroe 2024-06-10Add first roll of film from June 8June McEnroe 2024-06-10Cope with not having an EXIF infoJune McEnroe 2024-06-10Resize using target pixel counts for consistencyJune McEnroe This will resize film scans to about the same size as for the digital photos. 2024-06-10Add The Girl Who Was Convinced...June McEnroe Not much there. The illustrations are very nice though. 2024-06-09Add photos from May 31June McEnroe 2024-06-09Use monospace on photo pagesJune McEnroe 2024-06-09Put lens and (future) film at the tops of photo pagesJune McEnroe 2024-05-22Remove use of sysexits.hJune McEnroe 2024-05-22Add photo descriptions from 05-03 and 05-06June McEnroe 2024-05-21Fix = precedence in whenJune McEnroe