From 0566a340f5065c7c575cd8f35a9587e778ff70f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 7 Nov 2020 00:04:19 +0100 Subject: fix bugs --- l.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/l.c b/l.c index 46fac3e..53a1dbe 100644 --- a/l.c +++ b/l.c @@ -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(); -- cgit v1.2.3