about summary refs log tree commit diff
path: root/main.c
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@librem.one>2022-01-21 23:27:37 -0500
committerZach DeCook <zachdecook@librem.one>2022-01-21 23:27:37 -0500
commitda3ce831fdeed71dd2a0e3deb977d6bc770ef2f9 (patch)
tree0a587e0c708444c869ba15ff3853105896927be8 /main.c
parent24f516a5870662b09992ace0ad1dcfeb49149aaa (diff)
downloadsuggpicker-da3ce831fdeed71dd2a0e3deb977d6bc770ef2f9.tar.gz
suggestion: take from stdin
Diffstat (limited to 'main.c')
-rw-r--r--main.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/main.c b/main.c
index 62b80e9..5ffb772 100644
--- a/main.c
+++ b/main.c
@@ -380,13 +380,29 @@ show(int sigint) {
 }
 
 void
-handle_input(FILE *fd) {
+handle_input(FILE *fd, struct key *sugg) {
 	char *line;
 	line = malloc(1024);
 
 	if (fgets(line, 1024, fd) != NULL) {
 		fprintf(stderr, "Retrieved line: %s", line);
-		
+		int i;
+		struct key *key = sugg;
+		char *l = line;
+		for (i = 0; l[i+1]; i++) {
+			if (l[i] == '\t') {
+				// free label?
+				key->label = strndup(l,i);
+				l += i + 1;
+				i = 0;
+				key++;
+			} else if (l[i] == '\n') {
+				break;
+			}
+		}		
+		key->label = strndup(l,i);
+		key+=sizeof(struct key*);
+		key->label = NULL;
 	}
 
 	free(line);
@@ -506,7 +522,7 @@ main(int argc, char **argv) {
 	while (run_display) {
 		while(layer_surface && poll(fds, 2, -1) != -1) {
 			if (fds[0].revents & POLLIN) {
-				handle_input(stdin);
+				handle_input(stdin, keyboard.suggs);
 			}
 			if (wl_display_dispatch(display) == -1) {
 				break;