aboutsummaryrefslogtreecommitdiffstats
path: root/mongotimer.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-02-07 08:53:39 +0100
committerMattias Andrée <maandree@kth.se>2021-02-07 08:53:39 +0100
commit67d88f832cf8445f462f8cbf76fe6575210b6c2a (patch)
treeadc364f6019112cfea5e048e8d11050bbc48ecfe /mongotimer.c
parentAdd pause on enter (diff)
downloadmongotimer-67d88f832cf8445f462f8cbf76fe6575210b6c2a.tar.gz
mongotimer-67d88f832cf8445f462f8cbf76fe6575210b6c2a.tar.bz2
mongotimer-67d88f832cf8445f462f8cbf76fe6575210b6c2a.tar.xz
Pause on space
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'mongotimer.c')
-rw-r--r--mongotimer.c16
1 files 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <termios.h>
#include <time.h>
#include <unistd.h>
@@ -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();
}