thyme 0.0.13 → 0.0.14
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.
- checksums.yaml +4 -4
- data/README.md +31 -0
- data/lib/thyme.rb +59 -15
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a34024e5c3c57ea62c834ea83adf0c118b3fad2
|
4
|
+
data.tar.gz: b0e6459d5fb05917846384d5296c7b4da76d0ce1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfd282a9ff8df019c9c58b4add8c98bdc7e08e37a71cf4ea980bdacd366cbc9142450fcd9b062e783a4d4e5c0735c3a3ceb35a2c6b6a0c05c0f1d913a2d8b5b9
|
7
|
+
data.tar.gz: 82391d021bf3735a7e34be5a354de37cd62e104664886ead5e03af649a5b2849cac58c16226f9ab6d6472a1aea4ecd458a45929c29dc2d790717abe58f23d53c
|
data/README.md
CHANGED
@@ -90,6 +90,37 @@ works if you have tmux integration setup for the countdown:
|
|
90
90
|
|
91
91
|
nmap <leader>t :!thyme -d<cr>
|
92
92
|
|
93
|
+
Plugins
|
94
|
+
=======
|
95
|
+
|
96
|
+
Thyme's functionality can also be extended with plugins. They'll usually follow this
|
97
|
+
format:
|
98
|
+
|
99
|
+
require "thyme_growl"
|
100
|
+
use ThymeGrowl, text: "Go take a break!"
|
101
|
+
|
102
|
+
You can create your own plugins. They implement these methods:
|
103
|
+
|
104
|
+
class MyThymePlugin
|
105
|
+
def initialize(thyme, options={})
|
106
|
+
# `thyme` is an instance of Thyme (see lib/thyme.rb)
|
107
|
+
end
|
108
|
+
|
109
|
+
def before
|
110
|
+
# code to run when timer starts
|
111
|
+
end
|
112
|
+
|
113
|
+
def tick(seconds_left)
|
114
|
+
# code to run each tick
|
115
|
+
end
|
116
|
+
|
117
|
+
def after(seconds_left)
|
118
|
+
# code to run when timer stops
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
The `before`, `tick`, and `after` methods are all optional.
|
123
|
+
|
93
124
|
License
|
94
125
|
=======
|
95
126
|
|
data/lib/thyme.rb
CHANGED
@@ -2,7 +2,7 @@ require 'ruby-progressbar'
|
|
2
2
|
require 'date'
|
3
3
|
|
4
4
|
class Thyme
|
5
|
-
VERSION = '0.0.
|
5
|
+
VERSION = '0.0.14'
|
6
6
|
CONFIG_FILE = "#{ENV['HOME']}/.thymerc"
|
7
7
|
PID_FILE = "#{ENV['HOME']}/.thyme-pid"
|
8
8
|
TMUX_FILE = "#{ENV['HOME']}/.thyme-tmux"
|
@@ -17,6 +17,11 @@ class Thyme
|
|
17
17
|
@tmux_theme = "#[default]#[fg=%s]%s#[default]"
|
18
18
|
@warning = 5 * 60
|
19
19
|
@warning_color = "red,bold"
|
20
|
+
@plugins = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def use(plugin_class, *args, &block)
|
24
|
+
@plugins << plugin_class.new(self, *args, &block)
|
20
25
|
end
|
21
26
|
|
22
27
|
def run(force=false)
|
@@ -46,15 +51,15 @@ class Thyme
|
|
46
51
|
end
|
47
52
|
|
48
53
|
def before(&block)
|
49
|
-
|
54
|
+
hooks_plugin.add(:before, &block)
|
50
55
|
end
|
51
56
|
|
52
57
|
def after(&block)
|
53
|
-
|
58
|
+
hooks_plugin.add(:after, &block)
|
54
59
|
end
|
55
60
|
|
56
61
|
def tick(&block)
|
57
|
-
|
62
|
+
hooks_plugin.add(:tick, &block)
|
58
63
|
end
|
59
64
|
|
60
65
|
def option(optparse, short, long, desc, &block)
|
@@ -67,14 +72,15 @@ class Thyme
|
|
67
72
|
def load_config(optparse)
|
68
73
|
return if !File.exists?(CONFIG_FILE)
|
69
74
|
app = self
|
70
|
-
|
75
|
+
environment = Class.new do
|
71
76
|
define_method(:set) { |opt,val| app.set(opt,val) }
|
77
|
+
define_method(:use) { |plugin,*args,&b| app.use(plugin,*args,&b) }
|
72
78
|
define_method(:before) { |&block| app.before(&block) }
|
73
79
|
define_method(:after) { |&block| app.after(&block) }
|
74
80
|
define_method(:tick) { |&block| app.tick(&block) }
|
75
81
|
define_method(:option) { |sh,lo,desc,&b| app.option(optparse,sh,lo,desc,&b) }
|
76
|
-
end
|
77
|
-
|
82
|
+
end.new
|
83
|
+
environment.instance_eval(File.read(CONFIG_FILE), CONFIG_FILE)
|
78
84
|
end
|
79
85
|
|
80
86
|
def running?
|
@@ -85,12 +91,12 @@ class Thyme
|
|
85
91
|
|
86
92
|
def start_timer
|
87
93
|
File.open(PID_FILE, "w") { |f| f.print(Process.pid) }
|
88
|
-
before_hook = @before
|
89
94
|
seconds_start = @break ? @timer_break : @timer
|
90
95
|
seconds_left = seconds_start + 1
|
91
96
|
start_time = DateTime.now
|
92
97
|
min_length = (seconds_left / 60).floor.to_s.length
|
93
98
|
tmux_file = File.open(TMUX_FILE, "w") if @tmux
|
99
|
+
started = false
|
94
100
|
bar = ENV['THYME_TEST'].nil? && !daemon? ?
|
95
101
|
ProgressBar.create(
|
96
102
|
title: format(seconds_left-1, min_length),
|
@@ -112,13 +118,11 @@ class Thyme
|
|
112
118
|
tmux_file.write(@tmux_theme % [fg, title])
|
113
119
|
tmux_file.flush
|
114
120
|
end
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
119
|
-
if @tick
|
120
|
-
self.instance_exec(seconds_left, &@tick)
|
121
|
+
unless started
|
122
|
+
started = true
|
123
|
+
send_to_plugin :before
|
121
124
|
end
|
125
|
+
send_to_plugin :tick, seconds_left
|
122
126
|
sleep(@interval)
|
123
127
|
end
|
124
128
|
rescue SignalException => e
|
@@ -128,7 +132,7 @@ class Thyme
|
|
128
132
|
File.delete(TMUX_FILE) if File.exists?(TMUX_FILE)
|
129
133
|
File.delete(PID_FILE) if File.exists?(PID_FILE)
|
130
134
|
seconds_left = [seconds_start - seconds_since(start_time), 0].max
|
131
|
-
|
135
|
+
send_to_plugin :after, seconds_left
|
132
136
|
end
|
133
137
|
|
134
138
|
def stop_timer
|
@@ -139,6 +143,23 @@ class Thyme
|
|
139
143
|
File.delete(PID_FILE) if File.exists?(PID_FILE)
|
140
144
|
end
|
141
145
|
|
146
|
+
def send_to_plugin(message, *args)
|
147
|
+
@plugins.each do |plugin|
|
148
|
+
begin
|
149
|
+
plugin.public_send(message, *args) if plugin.respond_to?(message)
|
150
|
+
rescue
|
151
|
+
$stderr.puts "Exception raised from #{plugin.class}:", $!, $@
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def hooks_plugin
|
157
|
+
@hooks_plugin ||= begin
|
158
|
+
use ThymeHooksPlugin
|
159
|
+
@plugins.last
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
142
163
|
def seconds_since(time)
|
143
164
|
((DateTime.now - time) * 24 * 60 * 60).to_i
|
144
165
|
end
|
@@ -159,3 +180,26 @@ class Thyme
|
|
159
180
|
end
|
160
181
|
|
161
182
|
class ThymeError < StandardError; end;
|
183
|
+
|
184
|
+
class ThymeHooksPlugin
|
185
|
+
def initialize(app)
|
186
|
+
@app = app
|
187
|
+
@hooks = {before: [], tick: [], after: []}
|
188
|
+
end
|
189
|
+
|
190
|
+
def add(type, &block)
|
191
|
+
@hooks[type] << block
|
192
|
+
end
|
193
|
+
|
194
|
+
def before
|
195
|
+
@hooks[:before].each { |b| @app.instance_exec(&b) }
|
196
|
+
end
|
197
|
+
|
198
|
+
def tick(seconds_left)
|
199
|
+
@hooks[:tick].each { |t| @app.instance_exec(seconds_left, &t) }
|
200
|
+
end
|
201
|
+
|
202
|
+
def after(seconds_left)
|
203
|
+
@hooks[:after].each { |a| @app.instance_exec(seconds_left, &a) }
|
204
|
+
end
|
205
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thyme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hugh Bien
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-progressbar
|
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
55
|
version: 1.3.6
|
56
56
|
requirements: []
|
57
57
|
rubyforge_project:
|
58
|
-
rubygems_version: 2.2.
|
58
|
+
rubygems_version: 2.2.2
|
59
59
|
signing_key:
|
60
60
|
specification_version: 4
|
61
61
|
summary: Timer for Pomodoro Technique
|