about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-05 21:57:23 -0500
committerJune McEnroe <june@causal.agency>2020-02-05 21:57:23 -0500
commit7c0e9cf3d2e83814fab3bb4bb09f7b955c2afaca (patch)
tree70adbed2adff0b4639f2a6647c6aa19121aa2f1a
parentAdd /me, /notice, /quote commands (diff)
downloadcatgirl-7c0e9cf3d2e83814fab3bb4bb09f7b955c2afaca.tar.gz
catgirl-7c0e9cf3d2e83814fab3bb4bb09f7b955c2afaca.zip
Add /quit
Diffstat (limited to '')
-rw-r--r--chat.c13
-rw-r--r--chat.h1
-rw-r--r--command.c5
3 files changed, 14 insertions, 5 deletions
diff --git a/chat.c b/chat.c
index 2d58b1e..1ad2833 100644
--- a/chat.c
+++ b/chat.c
@@ -115,13 +115,12 @@ int main(int argc, char *argv[]) {
 		{ .events = POLLIN, .fd = STDIN_FILENO },
 		{ .events = POLLIN, .fd = irc },
 	};
-	for (;;) {
+	while (!self.quit) {
 		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[SIGHUP]) self.quit = "zzz";
+		if (signals[SIGINT] || signals[SIGTERM]) break;
 		if (signals[SIGWINCH]) {
 			signals[SIGWINCH] = 0;
 			cursesWinch(SIGWINCH);
@@ -136,6 +135,10 @@ int main(int argc, char *argv[]) {
 		uiDraw();
 	}
 
-	ircFormat("QUIT\r\n");
+	if (self.quit) {
+		ircFormat("QUIT :%s\r\n", self.quit);
+	} else {
+		ircFormat("QUIT\r\n");
+	}
 	uiHide();
 }
diff --git a/chat.h b/chat.h
index b73cf40..5b3c01c 100644
--- a/chat.h
+++ b/chat.h
@@ -75,6 +75,7 @@ extern struct Self {
 	char *nick;
 	char *user;
 	enum Color color;
+	char *quit;
 } self;
 
 static inline void set(char **field, const char *value) {
diff --git a/command.c b/command.c
index 0843bd3..7fb98af 100644
--- a/command.c
+++ b/command.c
@@ -56,12 +56,17 @@ static void commandMe(size_t id, char *params) {
 	commandPrivmsg(id, buf);
 }
 
+static void commandQuit(size_t id, char *params) {
+	set(&self.quit, (params ? params : "Goodbye"));
+}
+
 static const struct Handler {
 	const char *cmd;
 	Command *fn;
 } Commands[] = {
 	{ "/me", commandMe },
 	{ "/notice", commandNotice },
+	{ "/quit", commandQuit },
 	{ "/quote", commandQuote },
 };
 
s new implementation works on an instance of a struct and does not interact with the rest of catgirl, making it possible to copy into another project. Unlike existing line editing libraries, this one is entirely abstract and can be rendered externally. My goal with this library is to be able to implement vi mode. Since it operates on struct instances rather than globals, it might also be possible to give catgirl separate line editing buffers for each window, which would be a nice UX improvement. 2022-02-18Simplify cursor positioning in inputJune McEnroe Do some extra work by adding the portion before the cursor to the input window twice, but simplify the interaction with the split point. This fixes the awkward behaviour when moving the cursor across colour codes where the code would be partially interpreted up to the cursor. 2022-02-18Fix M-f orderingJune McEnroe 2022-02-12Move sandman build to scripts/MakefileJune McEnroe 2022-02-12Use compat_readpassphrase.c on LinuxJune McEnroe 2022-02-12Copy RPP defines from oconfigureJune McEnroe