progress 1.1.3 → 1.2.0
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.
- data/VERSION +1 -1
- data/lib/progress.rb +46 -27
- data/progress.gemspec +6 -10
- metadata +8 -11
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/lib/progress.rb
CHANGED
@@ -66,6 +66,13 @@ class Progress
|
|
66
66
|
if levels.empty?
|
67
67
|
@started_at = Time.now
|
68
68
|
@eta = nil
|
69
|
+
@semaphore = Mutex.new
|
70
|
+
@beeper = Thread.new do
|
71
|
+
loop do
|
72
|
+
sleep 3
|
73
|
+
print_message
|
74
|
+
end
|
75
|
+
end
|
69
76
|
end
|
70
77
|
levels << new(title, total)
|
71
78
|
print_message true
|
@@ -190,39 +197,51 @@ class Progress
|
|
190
197
|
end
|
191
198
|
end
|
192
199
|
|
200
|
+
def lock(force)
|
201
|
+
if force ? @semaphore.lock : @semaphore.try_lock
|
202
|
+
begin
|
203
|
+
yield
|
204
|
+
ensure
|
205
|
+
@semaphore.unlock
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
193
210
|
def print_message(force = false)
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
211
|
+
lock force do
|
212
|
+
if force || time_to_print?
|
213
|
+
inner = 0
|
214
|
+
parts, parts_cl = [], []
|
215
|
+
levels.reverse.each do |level|
|
216
|
+
inner = current = level.to_f(inner)
|
217
|
+
value = current.zero? ? '......' : "#{'%5.1f' % (current * 100.0)}%"
|
218
|
+
|
219
|
+
title = level.title ? "#{level.title}: " : nil
|
220
|
+
if !highlight? || value == '100.0%'
|
221
|
+
parts << "#{title}#{value}"
|
222
|
+
else
|
223
|
+
parts << "#{title}\e[1m#{value}\e[0m"
|
224
|
+
end
|
225
|
+
parts_cl << "#{title}#{value}"
|
206
226
|
end
|
207
|
-
parts_cl << "#{title}#{value}"
|
208
|
-
end
|
209
227
|
|
210
|
-
|
211
|
-
|
212
|
-
|
228
|
+
eta_string = eta(inner)
|
229
|
+
message = "#{parts.reverse * ' > '}#{eta_string}"
|
230
|
+
message_cl = "#{parts_cl.reverse * ' > '}#{eta_string}"
|
213
231
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
232
|
+
if note = levels.last && levels.last.note
|
233
|
+
message << " - #{note}"
|
234
|
+
message_cl << " - #{note}"
|
235
|
+
end
|
218
236
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
237
|
+
if lines?
|
238
|
+
io.puts message
|
239
|
+
else
|
240
|
+
io << message << "\e[K\r"
|
241
|
+
end
|
224
242
|
|
225
|
-
|
243
|
+
set_title message_cl
|
244
|
+
end
|
226
245
|
end
|
227
246
|
end
|
228
247
|
end
|
data/progress.gemspec
CHANGED
@@ -4,12 +4,12 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "1.
|
7
|
+
s.name = "progress"
|
8
|
+
s.version = "1.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ivan Kuchin"]
|
12
|
-
s.date =
|
12
|
+
s.date = "2011-10-17"
|
13
13
|
s.extra_rdoc_files = [
|
14
14
|
"LICENSE.txt",
|
15
15
|
"README.markdown"
|
@@ -30,15 +30,11 @@ Gem::Specification.new do |s|
|
|
30
30
|
"spec/progress_spec.rb",
|
31
31
|
"spec/spec_helper.rb"
|
32
32
|
]
|
33
|
-
s.homepage =
|
33
|
+
s.homepage = "http://github.com/toy/progress"
|
34
34
|
s.licenses = ["MIT"]
|
35
35
|
s.require_paths = ["lib"]
|
36
|
-
s.rubygems_version =
|
37
|
-
s.summary =
|
38
|
-
s.test_files = [
|
39
|
-
"spec/progress_spec.rb",
|
40
|
-
"spec/spec_helper.rb"
|
41
|
-
]
|
36
|
+
s.rubygems_version = "1.8.11"
|
37
|
+
s.summary = "Show progress of long running tasks"
|
42
38
|
|
43
39
|
if s.respond_to? :specification_version then
|
44
40
|
s.specification_version = 3
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: progress
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 1.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ivan Kuchin
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-10-17 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: jeweler
|
@@ -86,7 +85,6 @@ files:
|
|
86
85
|
- progress.gemspec
|
87
86
|
- spec/progress_spec.rb
|
88
87
|
- spec/spec_helper.rb
|
89
|
-
has_rdoc: true
|
90
88
|
homepage: http://github.com/toy/progress
|
91
89
|
licenses:
|
92
90
|
- MIT
|
@@ -116,10 +114,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
114
|
requirements: []
|
117
115
|
|
118
116
|
rubyforge_project:
|
119
|
-
rubygems_version: 1.
|
117
|
+
rubygems_version: 1.8.11
|
120
118
|
signing_key:
|
121
119
|
specification_version: 3
|
122
120
|
summary: Show progress of long running tasks
|
123
|
-
test_files:
|
124
|
-
|
125
|
-
- spec/spec_helper.rb
|
121
|
+
test_files: []
|
122
|
+
|