diff options
author | John Ankarström <john@ankarstrom.se> | 2020-11-07 00:04:19 +0100 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2020-11-07 00:04:19 +0100 |
commit | 0566a340f5065c7c575cd8f35a9587e778ff70f8 (patch) | |
tree | 3dd283e20e7724d59b1a4fde5d1a33047e83ef5a | |
parent | 545fcfb1ee7b4004707da7183399ad822365c7a8 (diff) | |
download | lst-0566a340f5065c7c575cd8f35a9587e778ff70f8.tar.gz |
fix bugs
-rw-r--r-- | l.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -13,6 +13,7 @@ #define CSI ESC "[" #define prn(...) dprintf(ttyfd, __VA_ARGS__) +#define rerr(...) do { raw(false); err(__VA_ARGS__); } while (0) char *lines[3] = { "line 1", @@ -112,7 +113,7 @@ int main() { phrase = NULL; ttyfd = open("/dev/tty", O_RDWR); - if (ttyfd == -1) err(1, "open"); + if (ttyfd == -1) rerr(1, "open"); raw(true); @@ -136,7 +137,7 @@ int main() { /* get height of terminal */ r = ioctl(ttyfd, TIOCGWINSZ, &w); - if (r == -1) err(1, "ioctl"); + if (r == -1) rerr(1, "ioctl"); /* correct cursor position if original cursor was near bottom */ r = y + height - w.ws_row; @@ -149,15 +150,15 @@ int main() { /* select first item */ item(1); - while (read(0, &c, 1) != 0) { + while (read(ttyfd, &c, 1) != 0) { switch (c) { case 'q': goto quit; break; case '\033': - read(0, &c, 1); + read(ttyfd, &c, 1); if (c != '[') break; - read(0, &c, 1); + read(ttyfd, &c, 1); if (c == 'A') up(); if (c == 'B') down(); if (c == 'C') right(); |