thyme 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +6 -6
  2. data/thyme.rb +11 -7
  3. data/thyme_test.rb +3 -3
  4. metadata +1 -1
data/README.md CHANGED
@@ -31,9 +31,9 @@ Configure
31
31
  Thyme is configurable and extensible. All configurations live in the
32
32
  `~/.thymerc` file:
33
33
 
34
- set :timer, 25
35
- set :tmux, true
34
+ set :timer, 25*60
36
35
  set :interval, 1
36
+ set :tmux, true
37
37
 
38
38
  option :o, :open, 'open sheets' do
39
39
  `vim -O ~/.thyme-today.md ~/.thyme-records.md < \`tty\` > \`tty\``
@@ -43,15 +43,15 @@ Thyme is configurable and extensible. All configurations live in the
43
43
  `mplayer ~/music/flight-of-the-bumble-bee.mp3 &`
44
44
  end
45
45
 
46
- after do
47
- `notify-send -u critical "0:00 Thymes Up!"`
46
+ after do |seconds_left|
47
+ `notify-send -u critical "Thymes Up!"` if seconds_left == 0
48
48
  end
49
49
 
50
50
  The `set` method sets different configurations. There are only two:
51
51
 
52
- * `:timer` is the number of minutes to countdown from
53
- * `:tmux` is whether or not you want tmux integration on (off by default)
52
+ * `:timer` is the number of seconds to countdown from
54
53
  * `:interval` is the refresh rate of the progress bar and tmux status in seconds
54
+ * `:tmux` is whether or not you want tmux integration on (off by default)
55
55
 
56
56
  The `option` method adds new options to the `thyme` command. In the above
57
57
  example, we can now execute `thyme -o`. Use `thyme -h` to see available
data/thyme.rb CHANGED
@@ -2,21 +2,21 @@ require 'ruby-progressbar'
2
2
  require 'date'
3
3
 
4
4
  class Thyme
5
- VERSION = '0.0.5'
5
+ VERSION = '0.0.6'
6
6
  CONFIG_FILE = "#{ENV['HOME']}/.thymerc"
7
7
  PID_FILE = "#{ENV['HOME']}/.thyme-pid"
8
8
  TMUX_FILE = "#{ENV['HOME']}/.thyme-tmux"
9
9
  OPTIONS = [:timer, :tmux, :interval]
10
10
 
11
11
  def initialize
12
- @timer = 25
12
+ @timer = 25 * 60
13
13
  @tmux = false
14
14
  @interval = 1
15
15
  end
16
16
 
17
17
  def run
18
- @before.call if @before
19
- seconds_start = @timer * 60
18
+ before_hook = @before
19
+ seconds_start = @timer
20
20
  seconds_left = seconds_start + 1
21
21
  start_time = DateTime.now
22
22
  min_length = (seconds_left / 60).floor.to_s.length
@@ -28,7 +28,7 @@ class Thyme
28
28
  format: '[%B] %t')
29
29
  while seconds_left > 0
30
30
  seconds_passed = seconds_since(start_time)
31
- seconds_left = seconds_start - seconds_passed
31
+ seconds_left = [seconds_start - seconds_passed, 0].max
32
32
  title = format(seconds_left, min_length)
33
33
  fg = color(seconds_left)
34
34
  bar.title = title
@@ -39,14 +39,19 @@ class Thyme
39
39
  tmux_file.write("#[default]#[fg=#{fg}]#{title}#[default]")
40
40
  tmux_file.flush
41
41
  end
42
+ if before_hook
43
+ before_hook.call
44
+ before_hook = nil
45
+ end
42
46
  sleep(@interval)
43
47
  end
44
48
  rescue SignalException => e
45
49
  puts ""
46
50
  ensure
47
51
  tmux_file.close
48
- @after.call if @after && seconds_left <= 0
49
52
  stop
53
+ seconds_left = [seconds_start - seconds_since(start_time), 0].max
54
+ @after.call(seconds_left) if @after
50
55
  end
51
56
 
52
57
  def stop
@@ -98,7 +103,6 @@ class Thyme
98
103
  end
99
104
 
100
105
  def format(seconds, min_length)
101
- seconds = [0, seconds].max
102
106
  min = (seconds / 60).floor
103
107
  lead = ' ' * (min_length - min.to_s.length)
104
108
  sec = (seconds % 60).floor
data/thyme_test.rb CHANGED
@@ -22,9 +22,9 @@ class ThymeTest < Minitest::Test
22
22
  end
23
23
 
24
24
  def test_set
25
- assert_equal(25, @thyme.instance_variable_get('@timer'))
26
- @thyme.set(:timer, 20)
27
- assert_equal(20, @thyme.instance_variable_get('@timer'))
25
+ assert_equal(25*60, @thyme.instance_variable_get('@timer'))
26
+ @thyme.set(:timer, 20*60)
27
+ assert_equal(20*60, @thyme.instance_variable_get('@timer'))
28
28
  assert_raises(ThymeError) { @thyme.set(:invalid, nil) }
29
29
  end
30
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thyme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: