summary refs log tree commit diff
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
parentUse time_t rather than struct tm (diff)
downloadcatgirl-43845c61156bf27955891d68c2e1a2504786b587.tar.gz
catgirl-43845c61156bf27955891d68c2e1a2504786b587.zip
Add beginnings of input handling
-rw-r--r--chat.c12
-rw-r--r--chat.h1
-rw-r--r--ui.c45
3 files changed, 56 insertions, 2 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();
 	}
 }
diff --git a/chat.h b/chat.h
index 9165c13..8de5df1 100644
--- a/chat.h
+++ b/chat.h
@@ -115,6 +115,7 @@ void uiShow(void);
 void uiHide(void);
 void uiDraw(void);
 void uiShowID(size_t id);
+void uiRead(void);
 void uiWrite(size_t id, enum Heat heat, const time_t *time, const char *str);
 void uiFormat(
 	size_t id, enum Heat heat, const time_t *time, const char *format, ...
diff --git a/ui.c b/ui.c
index e2746f1..d69e706 100644
--- a/ui.c
+++ b/ui.c
@@ -14,6 +14,8 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+#define _XOPEN_SOURCE_EXTENDED
+
 #include <assert.h>
 #include <ctype.h>
 #include <curses.h>
@@ -192,7 +194,7 @@ void uiInit(void) {
 	keypad(input, true);
 	nodelay(input, true);
 	windows.active = windowFor(Network);
-	//uiShow();
+	uiShow();
 }
 
 void uiDraw(void) {
@@ -397,3 +399,44 @@ void uiFormat(
 	assert((size_t)len < sizeof(buf));
 	uiWrite(id, heat, time, buf);
 }
+
+static void keyCode(int code) {
+	switch (code) {
+		break; case KEY_RESIZE:; // TODO
+		break; case KeyFocusIn:; // TODO
+		break; case KeyFocusOut: windows.active->mark = true;
+		break; case KeyPasteOn:; // TODO
+		break; case KeyPasteOff:; // TODO
+	}
+}
+
+static void keyMeta(wchar_t ch) {
+	switch (ch) {
+		break; case L'm': uiWrite(windows.active->id, Cold, NULL, "");
+	}
+}
+
+static void keyChar(wchar_t ch) {
+	switch (ch) {
+		break; case CTRL(L'L'): clearok(curscr, true);
+	}
+}
+
+void uiRead(void) {
+	int ret;
+	wint_t ch;
+	static bool meta;
+	while (ERR != (ret = wget_wch(input, &ch))) {
+		if (ret == KEY_CODE_YES) {
+			keyCode(ch);
+		} else if (ch == '\33') {
+			meta = true;
+			continue;
+		} else if (meta) {
+			keyMeta(ch);
+		} else {
+			keyChar(ch);
+		}
+		meta = false;
+	}
+}
6964f6b255dccddcd93&follow=1'>Assert return values in edit testsJune McEnroe 2022-02-20Move mbs out of struct Edit, use a global bufferJune McEnroe This saves 4K in the edit buffers, not to mention all the heap allocations for the separate mbs buffers! There might be a way to be more clever about capacities, but I don't think it's worth it. 2022-02-20Clear edit buffer before running commandJune McEnroe Otherwise a command that switches windows will update the status line while the edit buffer still has input "pending", showing an indicator. 2022-02-20Show indicator in status when window has pending inputJune McEnroe 2022-02-20Use separate edit buffers for each IDJune McEnroe 2022-02-20Make sure new cap is actually larger than new lengthJune McEnroe 2022-02-20Remove unused mbs.len field from struct EditJune McEnroe 2022-02-19Remove unneeded includes in ui.cJune McEnroe 2022-02-19Reimplement tab completeJune McEnroe 2022-02-19Handle errors from editFn, etc.June McEnroe 2022-02-19Reimplement text macrosJune McEnroe 2022-02-19Factor out input handling to input.cJune McEnroe 2022-02-19Factor out window management to window.cJune McEnroe 2022-02-19Enable -Wmissing-prototypesJune McEnroe In other words, warn when a function is missing static. I don't see why this isn't in -Wextra. 2022-02-19Fix edit.[ch] license notice additional permissionsJune McEnroe 2022-02-19Run line editing testsJune McEnroe I know, it feels wrong. 2022-02-18Implement new line editing "library"June McEnroe Losing tab complete and text macros, for now. This 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