From a91c2b7552139cdd7caba9089162f4bb15edf96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 7 Nov 2020 01:02:04 +0100 Subject: write key used to choose item to stdout --- lst.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'lst.c') diff --git a/lst.c b/lst.c index bbc5081..2385e59 100644 --- a/lst.c +++ b/lst.c @@ -105,8 +105,10 @@ int left() {} int main() { char c, *line, *p, *phrase, *tmp; - int i, line_s, r; + int i, key, line_s, r; struct winsize w; + + key = -1; phrase = NULL; ttyfd = open("/dev/tty", O_RDWR); @@ -173,10 +175,7 @@ int main() { while (read(ttyfd, &c, 1) != 0) { switch (c) { - case 'q': - goto quit; - break; - case '\033': + case '\033': /* escape */ read(ttyfd, &c, 1); if (c != '[') break; read(ttyfd, &c, 1); @@ -185,15 +184,24 @@ int main() { if (c == 'C') right(); if (c == 'D') left(); break; - case 13: /* enter */ - phrase = lines[current - 1]; + case 3: /* ctrl-c */ goto quit; + break; + default: + phrase = lines[current - 1]; + key = c; + goto choose; } } quit: + key = -1; + phrase = NULL; +choose: prn("%s%d;%dH", CSI, y, x); prn(CSI "J"); /* delete from cursor to end of display (ED) */ raw(false); + if (key != -1) + printf("%d\n", key); if (phrase != NULL) printf("%s\n", phrase); return 0; -- cgit v1.2.3