-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtimer
More file actions
executable file
·38 lines (33 loc) · 733 Bytes
/
timer
File metadata and controls
executable file
·38 lines (33 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env ruby
/^(?<mins>\d{1,2}):?(?<secs>\d{2})?$/ =~ ARGV.first
module Timer
def self.tick(mins, secs)
if mins
printf "#{mins} minutes"
printf ", #{secs} seconds" if secs
printf "\n"
s = 0
max_secs = mins.to_i * 60 + secs.to_i
num_digits = Math.log10(max_secs).ceil
# curses stuff
lines = 1
cols = num_digits
while s < max_secs
puts s
sleep 1
print "\x1B[1A\x1B[2K" # move up and clear
s += 1
end
else
puts "input must be minutes with optional seconds: (e.g. 2:30)"
exit 1
end
end
end
Timer.tick(mins, secs)
SIGS = ["KILL", "TERM"]
SIGS.each do |sig|
Signal.trap(sig) do
exit
end
end