From 39390b673ceda291e73df207dcf3c987b5a8e7e1 Mon Sep 17 00:00:00 2001 From: Brian Barto Date: Tue, 19 Apr 2016 13:46:58 -0400 Subject: [PATCH] Had to reopen stdin to get keyboard input back when piped data is used modified: src/nms.c --- src/nms.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/nms.c b/src/nms.c index cffb44f..0421887 100644 --- a/src/nms.c +++ b/src/nms.c @@ -125,9 +125,13 @@ void nmsexec(char *src) { usleep(ms * 1000); } - // TODO: pause with getchar() - something about the input stream being redirected - // to a file is causing getchar() to immediately return here. - sleep(1); + // Reopen stdin for interactive input (keyboard), then require user + // to press a key to continue. + if (!isatty(STDIN_FILENO)) + if (!freopen ("/dev/tty", "r", stdin)) + sleep(1); + else + getch(); // Jumble loop ms = 35; // miliseconds, used for usleep() @@ -206,6 +210,12 @@ void nmsexec(char *src) { attroff(COLOR_PAIR(1)); } + // If stdin is set to the keyboard, user must press a key to continue + if (isatty(STDIN_FILENO)) + getch(); + else + sleep(2); + // End curses mode endwin();