about summary refs log tree commit diff
path: root/chat.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-04 03:58:56 -0500
committerJune McEnroe <june@causal.agency>2020-02-04 03:58:56 -0500
commit43845c61156bf27955891d68c2e1a2504786b587 (patch)
treee8cb5c9c104c23f5d60b920d24c21b1677bda5cc /chat.c
parentUse time_t rather than struct tm (diff)
downloadcatgirl-43845c61156bf27955891d68c2e1a2504786b587.tar.gz
catgirl-43845c61156bf27955891d68c2e1a2504786b587.zip
Add beginnings of input handling
Diffstat (limited to 'chat.c')
-rw-r--r--chat.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/chat.c b/chat.c
index 162f68f..3402621 100644
--- a/chat.c
+++ b/chat.c
@@ -15,7 +15,9 @@
  */
 
 #include <err.h>
+#include <errno.h>
 #include <locale.h>
+#include <poll.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -98,8 +100,16 @@ int main(int argc, char *argv[]) {
 	ircFormat("NICK :%s\r\n", nick);
 	ircFormat("USER %s 0 * :%s\r\n", user, real);
 
+	struct pollfd fds[2] = {
+		{ .events = POLLIN, .fd = STDIN_FILENO },
+		{ .events = POLLIN, .fd = irc },
+	};
 	for (;;) {
+		int nfds = poll(fds, 2, -1);
+		if (nfds < 0 && errno != EINTR) err(EX_IOERR, "poll");
+
+		if (fds[0].revents) uiRead();
+		if (fds[1].revents) ircRecv();
 		uiDraw();
-		ircRecv();
 	}
 }