diff options
Diffstat (limited to '')
| -rw-r--r-- | README | 2 | ||||
| -rw-r--r-- | mongotimer.1 | 4 | ||||
| -rw-r--r-- | mongotimer.c | 32 | 
3 files changed, 31 insertions, 7 deletions
| @@ -14,6 +14,8 @@ DESCRIPTION  	paused. Pressing space again will unpause the  	timer/stopwatch. +	Pressing r will restart the timer/stopwatch. +  	mongotimer is designed to be fit on most screens  	and be readable from all practical distances, so  	that it can be used in place of a standard wall- diff --git a/mongotimer.1 b/mongotimer.1 index 060866f..fa5be0e 100644 --- a/mongotimer.1 +++ b/mongotimer.1 @@ -16,6 +16,10 @@ and the time be displayed in yellow will paused.  Pressing space again will unpause the  timer/stopwatch.  .PP +Pressing +.B r +will restart the timer/stopwatch. +.PP  .B mongotimer  is designed to be fit on most screens and be  readable from all practical distances, so that diff --git a/mongotimer.c b/mongotimer.c index 7fe6e05..7fefb51 100644 --- a/mongotimer.c +++ b/mongotimer.c @@ -42,6 +42,8 @@ static volatile sig_atomic_t caught_sigterm = 0;  static volatile sig_atomic_t caught_sigwinch = 1;  static volatile sig_atomic_t caught_sigio = 0; +static struct itimerspec each_second; +  char *argv0;  static void @@ -152,6 +154,14 @@ display_stopwatch(int timerfd)  						if (timerfd_settime(timerfd, 0, &old_time, NULL))  							goto fail;  					} +				} else if (c == 'r') { +					total_overrun = 0; +					if (paused) { +						old_time.it_value = each_second.it_value; +					} else { +						if (timerfd_settime(timerfd, 0, &each_second, NULL)) +							goto fail; +					}  				} else if (c == 'q') {  					goto out;  				} @@ -213,8 +223,9 @@ fail:  }  static int -display_timer(int timerfd, int64_t time, int exit_on_zero) +display_timer(int timerfd, int64_t starttime, int exit_on_zero)  { +	int64_t time = starttime;  	uint64_t overrun, abstime;  	struct winsize winsize;  	size_t x = 0, y = 0, width; @@ -259,6 +270,14 @@ display_timer(int timerfd, int64_t time, int exit_on_zero)  						if (timerfd_settime(timerfd, 0, &old_time, NULL))  							goto fail;  					} +				} else if (c == 'r') { +					time = starttime; +					if (paused) { +						old_time.it_value = each_second.it_value; +					} else { +						if (timerfd_settime(timerfd, 0, &each_second, NULL)) +							goto fail; +					}  				} else if (c == 'q') {  					caught_sigterm = 1;  					goto out; @@ -348,7 +367,6 @@ main(int argc, char *argv[])  {  	int timerfd = -1, old_flags = -1, tcset = 0;  	int exit_on_zero = 0, old_sig = 0; -	struct itimerspec itimerspec;  	struct sigaction sigact;  	int64_t time = 0, t = 0, owner_set = 0;  	size_t colons = 0; @@ -369,14 +387,14 @@ main(int argc, char *argv[])  	fprintf(stdout, "\033[?1049h\033[?25l"); -	itimerspec.it_interval.tv_sec = 1; -	itimerspec.it_interval.tv_nsec = 0; -	itimerspec.it_value.tv_sec = 1; -	itimerspec.it_value.tv_nsec = 0; +	each_second.it_interval.tv_sec = 1; +	each_second.it_interval.tv_nsec = 0; +	each_second.it_value.tv_sec = 1; +	each_second.it_value.tv_nsec = 0;  	timerfd = timerfd_create(CLOCK_BOOTTIME, 0);  	if (timerfd < 0)  		goto fail; -	if (timerfd_settime(timerfd, 0, &itimerspec, NULL)) +	if (timerfd_settime(timerfd, 0, &each_second, NULL))  		goto fail;  	memset(&sigact, 0, sizeof(sigact)); | 
