summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2020-11-07 01:02:04 +0100
committerJohn Ankarström <john@ankarstrom.se>2020-11-07 01:15:08 +0100
commita91c2b7552139cdd7caba9089162f4bb15edf96c (patch)
tree4eca86d3174a392b0a74b64bb2e82a009d395d90
parenteb29f84831150d80fcf7ed65e14ae67ec47e12c2 (diff)
downloadlst-a91c2b7552139cdd7caba9089162f4bb15edf96c.tar.gz
write key used to choose item to stdout
-rw-r--r--lst.c22
1 files changed, 15 insertions, 7 deletions
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;