From 67d88f832cf8445f462f8cbf76fe6575210b6c2a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 7 Feb 2021 08:53:39 +0100 Subject: Pause on space MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- mongotimer.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/mongotimer.c b/mongotimer.c index f65238f..40ed234 100644 --- a/mongotimer.c +++ b/mongotimer.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -347,6 +348,7 @@ main(int argc, char *argv[]) size_t colons = 0; char *s; struct f_owner_ex old_owner, new_owner; + struct termios stty, saved_stty; ARGBEGIN { case 'e': @@ -399,7 +401,10 @@ main(int argc, char *argv[]) if (old_sig) fcntl(STDIN_FILENO, F_SETSIG, 0); - /* TODO set ICANON and ECHO and reset on exit */ + tcgetattr(STDIN_FILENO, &stty); + saved_stty = stty; + stty.c_lflag &= (tcflag_t)~(ECHO | ICANON); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &stty); if (argc) { for (s = argv[0]; *s; s++) { @@ -429,6 +434,7 @@ main(int argc, char *argv[]) fcntl(STDIN_FILENO, F_SETOWN_EX, &old_owner); fcntl(STDIN_FILENO, F_SETFL, old_flags); fcntl(STDIN_FILENO, F_SETSIG, old_sig); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_stty); close(timerfd); return 0; @@ -440,8 +446,10 @@ fail: fcntl(STDIN_FILENO, F_SETOWN_EX, &old_owner); if (old_flags != -1) fcntl(STDIN_FILENO, F_SETFL, old_flags); - if (old_sig) + if (old_sig) { fcntl(STDIN_FILENO, F_SETSIG, old_sig); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_stty); + } if (timerfd >= 0) close(timerfd); return 1; @@ -453,7 +461,9 @@ fail_usage: fcntl(STDIN_FILENO, F_SETOWN_EX, &old_owner); if (old_flags != -1) fcntl(STDIN_FILENO, F_SETFL, old_flags); - if (old_sig) + if (old_sig) { fcntl(STDIN_FILENO, F_SETSIG, old_sig); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_stty); + } usage(); } -- cgit v1.2.3-70-g09d2