summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAriadna Vigo <arivigodr@gmail.com>2020-06-28 23:15:36 +0200
committerAriadna Vigo <arivigodr@gmail.com>2020-06-28 23:39:51 +0200
commit06204aa816eb266f64da5045b19d8a10ed7cec0f (patch)
treeceddd630427aa2967ee542298bb1bb5b643ec95b
parentc64e53deffa1be3169d1e31e24031451e74ed420 (diff)
New stopwatch function
-rw-r--r--README.md15
-rw-r--r--minitimer.127
-rw-r--r--minitimer.c38
3 files changed, 46 insertions, 34 deletions
diff --git a/README.md b/README.md
index 592e2a6..c007c52 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,8 @@
# Mini Timer - A timer in your terminal
-Mini Timer is a very simple countdown timer that lives in the terminal of your
-Linux system. It supports pausing and resuming the countdown. It also provides
-a named pipe which you can pass commands to to control a running instance of
-Mini Timer.
+Mini Timer is a very simple timer that lives in the terminal of your system. It
+ also provides a named pipe which you can pass commands to to control a running
+ instance of Mini Timer.
## Build
Mini Timer doesn't require any external dependencies.
@@ -39,6 +38,14 @@ HH:MM:SS format. For example, for 10 minutes 34 seconds:
$ minitimer 00:10:34
```
+Mini Timer also provides a stopwatch mode (i.e. counting time up). You may pass
+ an initial time code from which to start counting up or leave blank to start
+from 00:00:00.
+
+```
+$ minitimer -s # Mini Timer will start counting from 00:00:00 up
+```
+
For further information on the usage of Mini Timer, please refer to the manual
page minitimer(1).
diff --git a/minitimer.1 b/minitimer.1
index 439000d..2ca310c 100644
--- a/minitimer.1
+++ b/minitimer.1
@@ -3,26 +3,27 @@
Mini Timer \- A timer in your terminal
.SH SYNOPSIS
.B minitimer
-.RB HH:MM:SS
-.br
-.B minitimer
-.RB \-v
+.RB [ \-sv ]
+.RB [ HH:MM:SS ]
.SH DESCRIPTION
-Mini Timer is a very simple countdown timer that lives in the terminal of your
-Linux system. It supports pausing and resuming the countdown. It also provides
-a named pipe which you can pass commands to to control a running instance of
-Mini Timer.
+Mini Timer is a very simple timer that lives in the terminal of your system. It
+supports pausing and resuming the countdown. It also provides a named pipe
+which you can pass commands to to control a running instance of Mini Timer.
.SH OPTIONS
.TP
+.B \-s
+Switch to stopwatch mode (i.e. counting time up), from the time provided at the
+command line (00:00:00 by default).
+.TP
.B \-v
-Show version information.
+Show version information and exit.
.SH USAGE
-Mini Timer is started by passing the amount of time to count down in an
-HH:MM:SS format (e.g. 01:10:10 for 1 hour, 10 mins., 10 secs.). During
-execution, pressing these keys will perform an action:
+Mini Timer is started by passing the initial time in HH:MM:SS format (e.g.
+01:10:10 for 1 hour, 10 mins., 10 secs.). During execution, pressing these keys
+will perform an action:
.TP
.B p
-Pause/resume the countdown.
+Pause/resume.
.TP
.B +
Increment the countdown by 10 secs. (amount configurable in config.h).
diff --git a/minitimer.c b/minitimer.c
index 8c03568..2c11b11 100644
--- a/minitimer.c
+++ b/minitimer.c
@@ -57,8 +57,7 @@ die(const char *fmt, ...)
static void
usage(void)
{
- die("usage:\tminitimer HH:MM:SS\n"
- "\tminitimer -v");
+ die("usage: minitimer [-sv] [HH:MM:SS]");
}
static int
@@ -205,27 +204,32 @@ int
main(int argc, char *argv[])
{
struct time the_time;
- int parse_status, fifofd, timer_runs;
+ int delta, parse_status, fifofd, timer_runs;
char fifoname[FIFONAME_SIZE];
struct termios oldterm;
- ARGBEGIN {
- case 'v':
- die("Mini Timer %s. See LICENSE file for copyright "
- "and license details.", VERSION);
- break;
- default:
- usage();
- break;
- } ARGEND;
+ delta = -1; /* Default is counting time down. */
- if (argc <= 0)
+ ARGBEGIN {
+ case 's':
+ delta = 1;
+ break;
+ case 'v':
+ die("Mini Timer %s. See LICENSE file for copyright and license"
+ " details.", VERSION);
+ break;
+ default:
usage();
+ break;
+ } ARGEND;
memset(&the_time, 0, sizeof(struct time));
- parse_status = parse_time(argv[0], &the_time);
- if (parse_status < 0)
- die("Invalid or ill-formed time (must be HH:MM:SS)");
+
+ if (argc > 0) {
+ parse_status = parse_time(argv[0], &the_time);
+ if (parse_status < 0)
+ die("Invalid or ill-formed time (must be HH:MM:SS)");
+ }
ui_setup(&oldterm);
@@ -262,7 +266,7 @@ main(int argc, char *argv[])
if (timer_runs > 0) {
ui_update(the_time);
- time_inc(&the_time, -1);
+ time_inc(&the_time, delta);
sleep(1);
}
}