diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-10-19 01:34:12 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-10-19 01:34:12 (EDT) |
commit | 0c8ff1106651c5bc2ef024364404f08163cdab43 (patch) | |
tree | 64d430fa1b2e8b911528264e39d4d98a2c25a562 | |
parent | 57a6ec252862726621c573c5e57fdbc2ab483068 (diff) | |
download | timeteller-0c8ff1106651c5bc2ef024364404f08163cdab43.zip timeteller-0c8ff1106651c5bc2ef024364404f08163cdab43.tar.gz timeteller-0c8ff1106651c5bc2ef024364404f08163cdab43.tar.bz2 |
screen_main(): Poll input
-rw-r--r-- | src/screen.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/screen.c b/src/screen.c index 7259fab..c72b9de 100644 --- a/src/screen.c +++ b/src/screen.c @@ -23,6 +23,8 @@ #include <assert.h> #include <curses.h> +#include <errno.h> +#include <poll.h> #include <stdbool.h> #include <stdlib.h> #include <unistd.h> @@ -69,7 +71,10 @@ screen_new(void) bool screen_main(struct screen *screen, struct speech *speech) { - bool play; + struct pollfd fds[] = { + { .fd = STDIN_FILENO, .events = POLLIN|POLLERR, .revents = 0 }, + }; + bool play; assert(screen); assert(speech); @@ -107,7 +112,10 @@ screen_main(struct screen *screen, struct speech *speech) speech_play_time(speech); play = false; } else { - sleep(1); + while (poll(fds, 1, 1000) < 0 && (errno == EINTR || + errno == EAGAIN)) { + continue; + } } } |