Implement a simple digital Stopwatch, which will display the time elapsed in seconds and minutes, as described below.
Important
Please read both Display and Controls sections !
Display
Time elapsed, should be displayed in the MM:SS
format,
by replacing the previously displayed time string "in-place"
(clearing the whole or a part of the screen is also allowed).
The stopwatch must be updated at least every second.
Examples:
0 minutes, 0 seconds
00:00
0 minutes, 33 seconds
00:33
1 minute, 50 seconds
01:50
Initially, you can start with '00:00' or with any other value in range [00:00-59:59].
Once your Stopwatch reaches 59:59
, it should reset to 00:00
and continue afresh.
You can use a different base (instead of decimal) or even a different numeral system if you wish, as long as you follow the general pattern.
For example 13:03
can be displayed as:
13:03
0D:03
N:D
10101:3
XIII:III
Beware that if you use a non-decimal numeral system/base, it must be encoded using printable ASCII (or Unicode) characters, e.g. using two binary (unprintable) bytes for minutes and seconds is not allowed.
You must also left-pad your output with zeroes as appropriate, if your numerical system allows for that.
Replacing the separator character :
with any other printable character (including digits) is also acceptable.
Controls
The stopwatch should start paused, and stay in this state, until user explicitly starts it, by pressing the 'control' key (see below).
If, while stopwatch is counting, user presses the 'control' key again, the stopwatch should pause (keeping the current time), until the 'control' key is pressed a one more time.
The 'control' key can be a single keystroke, e.g. s
,
or any combination of keys, e.g. Ctrl+Shift+X
, but it must be 'atomic', pressing multiple keys in sequence, e.g. s
then Enter
, is not allowed.
The same 'control' key (or combination) must be used to pause and resume the stopwatch.
You must use a specific 'control' key, i.e. 'any key' is not allowed.
Alternatively, you can use a single or double mouse-click, instead of a keypress for 'control'.
Rules
- This is code-golf, the shortest answer in bytes wins;
- Standard code-golf loopholes apply;
- Your program must (theoretically) be capable of running forever.
00:05
is printed, and then at some point resumes again, must the00:06
appear 3000 milliseconds after the resume key was pressed, or is it okay to print it a full second after the resume key was pressed? \$\endgroup\$