thyme 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/thyme.rb +14 -12
  2. metadata +2 -2
data/thyme.rb CHANGED
@@ -2,7 +2,7 @@ require 'ruby-progressbar'
2
2
  require 'date'
3
3
 
4
4
  class Thyme
5
- VERSION = '0.0.3'
5
+ VERSION = '0.0.4'
6
6
  CONFIG_FILE = "#{ENV['HOME']}/.thymerc"
7
7
  PID_FILE = "#{ENV['HOME']}/.thyme-pid"
8
8
  TMUX_FILE = "#{ENV['HOME']}/.thyme-tmux"
@@ -16,23 +16,24 @@ class Thyme
16
16
 
17
17
  def run
18
18
  @before.call if @before
19
- start = @timer * 60
19
+ seconds_start = @timer * 60
20
+ seconds_left = seconds_start + 1
20
21
  start_time = DateTime.now
21
- seconds = start + 1
22
22
  delta = @seconds ? 1 : 60
23
- min_length = (seconds / 60).floor.to_s.length
23
+ min_length = (seconds_left / 60).floor.to_s.length
24
24
  tmux_file = File.open(TMUX_FILE, "w")
25
25
  bar = ProgressBar.create(
26
- title: format(seconds-1, min_length),
27
- total: seconds,
26
+ title: format(seconds_left-1, min_length),
27
+ total: seconds_start,
28
28
  length: 50,
29
29
  format: '[%B] %t')
30
- while !bar.finished? && seconds > 0
31
- seconds = start - seconds_since(start_time)
32
- title = format(seconds, min_length)
33
- fg = color(seconds)
30
+ while seconds_left > 0
31
+ seconds_passed = seconds_since(start_time)
32
+ seconds_left = seconds_start - seconds_passed
33
+ title = format(seconds_left, min_length)
34
+ fg = color(seconds_left)
34
35
  bar.title = title
35
- bar.increment
36
+ bar.progress = seconds_passed
36
37
  if @tmux
37
38
  tmux_file.truncate(0)
38
39
  tmux_file.rewind
@@ -45,7 +46,7 @@ class Thyme
45
46
  puts ""
46
47
  ensure
47
48
  tmux_file.close
48
- @after.call if @after && seconds <= 0
49
+ @after.call if @after && seconds_left <= 0
49
50
  stop
50
51
  end
51
52
 
@@ -98,6 +99,7 @@ class Thyme
98
99
  end
99
100
 
100
101
  def format(seconds, min_length)
102
+ seconds = [0, seconds].max
101
103
  min = (seconds / 60).floor
102
104
  lead = ' ' * (min_length - min.to_s.length)
103
105
  sec = (seconds % 60).floor
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.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: .
11
11
  cert_chain: []
12
- date: 2013-06-20 00:00:00.000000000 Z
12
+ date: 2013-06-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-progressbar