summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;