diff options
author | John Ankarström <john@ankarstrom.se> | 2020-11-07 01:02:04 +0100 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2020-11-07 01:15:08 +0100 |
commit | a91c2b7552139cdd7caba9089162f4bb15edf96c (patch) | |
tree | 4eca86d3174a392b0a74b64bb2e82a009d395d90 | |
parent | eb29f84831150d80fcf7ed65e14ae67ec47e12c2 (diff) | |
download | lst-a91c2b7552139cdd7caba9089162f4bb15edf96c.tar.gz |
write key used to choose item to stdout
-rw-r--r-- | lst.c | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -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; |