diff options
-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(); |