thyme 0.0.10 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +18 -13
  3. data/bin/thyme +3 -3
  4. data/lib/thyme.rb +78 -49
  5. metadata +9 -13
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 01f04a390342ec220db3518e9c4495a615526d9c
4
+ data.tar.gz: 9486f89eee4c8770a10c7d1b529e25d00a2a2b82
5
+ SHA512:
6
+ metadata.gz: d206ec0493005d94414a7e8b46de5e3f739f0c4fa24ee897e0545c99a77c60675659c61a9126d66b1d3bde7b8ca7b6ff471c6618fe0e015324e1d07e8644f4b6
7
+ data.tar.gz: 55552b2da07a13917a2225aeba7840bbcd381ca441a3c46440018b547e79a67d0914c7053172a0fe40903fd84a2c8fa792a26a909866f4f7a3b811e039a30f2a
data/README.md CHANGED
@@ -22,8 +22,8 @@ you of the timer:
22
22
 
23
23
  $ thyme -d
24
24
 
25
- To interrupt the timer in daemon mode, simply run `thyme --stop`. Or wait 25
26
- minutes for it to kill itself.
25
+ To interrupt the timer in daemon mode, run `thyme` again. Or wait 25 minutes
26
+ for it to kill itself.
27
27
 
28
28
  Configure
29
29
  =========
@@ -32,32 +32,38 @@ Thyme is configurable and extensible. All configurations live in the
32
32
  `~/.thymerc` file:
33
33
 
34
34
  set :timer, 25*60
35
+ set :timer_break, 5*60
36
+ set :warning, 5*60
37
+ set :warning_color, "red,bold"
35
38
  set :interval, 1
36
39
  set :tmux, true
37
40
  set :tmux_theme, "#[fg=mycolor,bg=mycolor]#[fg=%s]%s#[fg=mycolor,bg=mycolor]"
38
41
 
39
- option :b, :break, 'start a break' do
40
- set :timer, 5*60
41
- run
42
- end
43
-
44
42
  option :t, :today, 'open today sheet' do
45
43
  `vim -O ~/.thyme-today.md ~/.thyme-records.md < \`tty\` > \`tty\``
46
44
  end
47
45
 
46
+ option :s, 'seconds num', 'run with custom seconds' do |num|
47
+ @timer = num.to_i
48
+ run
49
+ end
50
+
48
51
  before do
49
52
  `mplayer ~/music/flight-of-the-bumble-bee.mp3 &`
50
53
  end
51
54
 
52
55
  after do |seconds_left|
53
- `notify-send -u critical "Thymes Up!"` if seconds_left == 0
56
+ `notify-send -u critical "Thyme's Up!"` if seconds_left == 0
54
57
  end
55
58
 
56
- The `set` method sets different configurations. There are only two:
59
+ The `set` method sets different configurations.
57
60
 
58
- * `:timer` is the number of seconds to countdown from
59
- * `:interval` is the refresh rate of the progress bar and tmux status in seconds
60
- * `:tmux` is whether or not you want tmux integration on (off by default)
61
+ * `:timer` seconds to countdown from
62
+ * `:timer_break` seconds to countdown from in break mode
63
+ * `:warning` seconds threshold before tmux timer turns red (use 0 to disable)
64
+ * `:warning_color` color of the tmux timer during the warning period
65
+ * `:interval` refresh rate of the progress bar and tmux status in seconds
66
+ * `:tmux` whether or not you want tmux integration on (false by default)
61
67
  * `:tmux_theme` optionally lets you format the tmux status
62
68
 
63
69
  The `option` method adds new options to the `thyme` command. In the above
@@ -83,7 +89,6 @@ For vim integration, I like to execute `thyme -d` to toggle the timer. This onl
83
89
  works if you have tmux integration setup for the countdown:
84
90
 
85
91
  nmap <leader>t :!thyme -d<cr>
86
- nmap <leader>T :!thyme -s<cr>
87
92
 
88
93
  License
89
94
  =======
data/bin/thyme CHANGED
@@ -5,13 +5,13 @@ require File.expand_path('thyme', File.join(File.dirname(__FILE__), '..', 'lib')
5
5
  $0 = 'thyme'
6
6
  ARGV.options do |o|
7
7
  thyme = Thyme.new
8
- thyme.load_config(o)
9
8
  o.set_summary_indent(' ')
10
9
  o.banner = "Usage: #{File.basename($0)} [OPTION]"
11
10
  o.define_head "Timer for Pomodoro Technique"
11
+ o.on('-b', '--break', 'run break timer') { thyme.break! }
12
12
  o.on('-d', '--daemon', 'run in background') { thyme.daemonize! }
13
13
  o.on('-h', '--help', 'show this help message') { puts o; exit }
14
- o.on('-s', '--stop', 'stops timer') { thyme.stop; exit }
14
+ thyme.load_config(o)
15
15
  o.parse!
16
- thyme.run
16
+ thyme.run(true)
17
17
  end
data/lib/thyme.rb CHANGED
@@ -2,70 +2,38 @@ require 'ruby-progressbar'
2
2
  require 'date'
3
3
 
4
4
  class Thyme
5
- VERSION = '0.0.10'
5
+ VERSION = '0.0.12'
6
6
  CONFIG_FILE = "#{ENV['HOME']}/.thymerc"
7
7
  PID_FILE = "#{ENV['HOME']}/.thyme-pid"
8
8
  TMUX_FILE = "#{ENV['HOME']}/.thyme-tmux"
9
- OPTIONS = [:timer, :tmux, :interval, :tmux_theme]
9
+ OPTIONS = [:interval, :timer, :timer_break, :tmux, :tmux_theme, :warning, :warning_color]
10
10
 
11
11
  def initialize
12
+ @break = false
13
+ @interval = 1
12
14
  @timer = 25 * 60
15
+ @timer_break = 5 * 60
13
16
  @tmux = false
14
- @interval = 1
15
17
  @tmux_theme = "#[default]#[fg=%s]%s#[default]"
18
+ @warning = 5 * 60
19
+ @warning_color = "red,bold"
16
20
  end
17
21
 
18
- def run
19
- before_hook = @before
20
- seconds_start = @timer
21
- seconds_left = seconds_start + 1
22
- start_time = DateTime.now
23
- min_length = (seconds_left / 60).floor.to_s.length
24
- tmux_file = File.open(TMUX_FILE, "w")
25
- bar = ProgressBar.create(
26
- title: format(seconds_left-1, min_length),
27
- total: seconds_start,
28
- length: 50,
29
- format: '[%B] %t')
30
- while seconds_left > 0
31
- seconds_passed = seconds_since(start_time)
32
- seconds_left = [seconds_start - seconds_passed, 0].max
33
- title = format(seconds_left, min_length)
34
- fg = color(seconds_left)
35
- bar.title = title
36
- bar.progress = seconds_passed
37
- if @tmux
38
- tmux_file.truncate(0)
39
- tmux_file.rewind
40
- tmux_file.write(@tmux_theme % [fg, title])
41
- tmux_file.flush
42
- end
43
- if before_hook
44
- self.instance_exec(&before_hook)
45
- before_hook = nil
46
- end
47
- sleep(@interval)
22
+ def run(force=false)
23
+ if force
24
+ running? ? stop_timer : start_timer
25
+ else
26
+ @run = true
48
27
  end
49
- rescue SignalException => e
50
- puts ""
51
- ensure
52
- tmux_file.close
53
- File.delete(TMUX_FILE) if File.exists?(TMUX_FILE)
54
- File.delete(PID_FILE) if File.exists?(PID_FILE)
55
- seconds_left = [seconds_start - seconds_since(start_time), 0].max
56
- self.instance_exec(seconds_left, &@after) if @after
57
28
  end
58
29
 
59
- def stop
60
- return if !File.exists?(PID_FILE)
61
- pid = File.read(PID_FILE).to_i
62
- File.delete(PID_FILE)
63
- Process.kill('TERM', pid) if pid > 1
30
+ def break!
31
+ @break = true
64
32
  end
65
33
 
66
34
  def daemonize!
35
+ @daemon = true
67
36
  Process.daemon
68
- File.open(PID_FILE, "w") { |f| f.print(Process.pid) }
69
37
  end
70
38
 
71
39
  def set(opt, val)
@@ -82,7 +50,10 @@ class Thyme
82
50
  end
83
51
 
84
52
  def option(optparse, short, long, desc, &block)
85
- optparse.on("-#{short}", "--#{long}", desc) { self.instance_exec(&block); exit }
53
+ optparse.on("-#{short}", "--#{long}", desc) do |*args|
54
+ self.instance_exec(*args, &block)
55
+ exit if !@run
56
+ end
86
57
  end
87
58
 
88
59
  def load_config(optparse)
@@ -97,7 +68,65 @@ class Thyme
97
68
  load(CONFIG_FILE, true)
98
69
  end
99
70
 
71
+ def running?
72
+ File.exists?(PID_FILE)
73
+ end
74
+
100
75
  private
76
+
77
+ def start_timer
78
+ File.open(PID_FILE, "w") { |f| f.print(Process.pid) }
79
+ before_hook = @before
80
+ seconds_start = @break ? @timer_break : @timer
81
+ seconds_left = seconds_start + 1
82
+ start_time = DateTime.now
83
+ min_length = (seconds_left / 60).floor.to_s.length
84
+ tmux_file = File.open(TMUX_FILE, "w") if @tmux
85
+ bar = ENV['THYME_TEST'].nil? && !@daemon ?
86
+ ProgressBar.create(
87
+ title: format(seconds_left-1, min_length),
88
+ total: seconds_start,
89
+ length: 50,
90
+ format: '[%B] %t') : nil
91
+ while seconds_left > 0
92
+ seconds_passed = seconds_since(start_time)
93
+ seconds_left = [seconds_start - seconds_passed, 0].max
94
+ title = format(seconds_left, min_length)
95
+ fg = color(seconds_left)
96
+ if bar
97
+ bar.title = title
98
+ bar.progress = seconds_passed
99
+ end
100
+ if @tmux
101
+ tmux_file.truncate(0)
102
+ tmux_file.rewind
103
+ tmux_file.write(@tmux_theme % [fg, title])
104
+ tmux_file.flush
105
+ end
106
+ if before_hook
107
+ self.instance_exec(&before_hook)
108
+ before_hook = nil
109
+ end
110
+ sleep(@interval)
111
+ end
112
+ rescue SignalException => e
113
+ puts ""
114
+ ensure
115
+ tmux_file.close if tmux_file
116
+ File.delete(TMUX_FILE) if File.exists?(TMUX_FILE)
117
+ File.delete(PID_FILE) if File.exists?(PID_FILE)
118
+ seconds_left = [seconds_start - seconds_since(start_time), 0].max
119
+ self.instance_exec(seconds_left, &@after) if @after
120
+ end
121
+
122
+ def stop_timer
123
+ pid = File.read(PID_FILE).to_i
124
+ Process.kill('TERM', pid) if pid > 1
125
+ rescue Errno::ESRCH # process is already dead, cleanup files and restart
126
+ File.delete(TMUX_FILE) if File.exists?(TMUX_FILE)
127
+ File.delete(PID_FILE) if File.exists?(PID_FILE)
128
+ end
129
+
101
130
  def seconds_since(time)
102
131
  ((DateTime.now - time) * 24 * 60 * 60).to_i
103
132
  end
@@ -113,7 +142,7 @@ class Thyme
113
142
  end
114
143
 
115
144
  def color(seconds)
116
- seconds < (5*60) ? 'red,bold' : 'default'
145
+ !@break && seconds < @warning ? @warning_color : 'default'
117
146
  end
118
147
  end
119
148
 
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thyme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
5
- prerelease:
4
+ version: 0.0.12
6
5
  platform: ruby
7
6
  authors:
8
7
  - Hugh Bien
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-07 00:00:00.000000000 Z
11
+ date: 2014-08-25 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: ruby-progressbar
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  description: Extensible and configurable timer for Pomodoro Technique.
@@ -41,26 +38,25 @@ files:
41
38
  - lib/thyme.rb
42
39
  homepage: http://thymerb.com
43
40
  licenses: []
41
+ metadata: {}
44
42
  post_install_message:
45
43
  rdoc_options: []
46
44
  require_paths:
47
45
  - lib
48
46
  required_ruby_version: !ruby/object:Gem::Requirement
49
- none: false
50
47
  requirements:
51
- - - ! '>='
48
+ - - ">="
52
49
  - !ruby/object:Gem::Version
53
50
  version: '0'
54
51
  required_rubygems_version: !ruby/object:Gem::Requirement
55
- none: false
56
52
  requirements:
57
- - - ! '>='
53
+ - - ">="
58
54
  - !ruby/object:Gem::Version
59
55
  version: 1.3.6
60
56
  requirements: []
61
57
  rubyforge_project:
62
- rubygems_version: 1.8.23
58
+ rubygems_version: 2.2.0
63
59
  signing_key:
64
- specification_version: 3
60
+ specification_version: 4
65
61
  summary: Timer for Pomodoro Technique
66
62
  test_files: []