about summary refs log tree commit diff
path: root/ui.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 /ui.c
parentUse time_t rather than struct tm (diff)
downloadcatgirl-43845c61156bf27955891d68c2e1a2504786b587.tar.gz
catgirl-43845c61156bf27955891d68c2e1a2504786b587.zip
Add beginnings of input handling
Diffstat (limited to 'ui.c')
-rw-r--r--ui.c45
1 files changed, 44 insertions, 1 deletions
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;
+	}
+}