progress 0.1.2 → 0.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/Rakefile +7 -0
- data/VERSION +1 -1
- data/lib/progress.rb +42 -24
- data/progress.gemspec +1 -1
- data/spec/progress_spec.rb +2 -1
- metadata +1 -1
data/Rakefile
CHANGED
@@ -26,3 +26,10 @@ begin
|
|
26
26
|
rescue LoadError
|
27
27
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
28
28
|
end
|
29
|
+
|
30
|
+
require 'spec/rake/spectask'
|
31
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
32
|
+
spec.libs << 'lib' << 'spec'
|
33
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
34
|
+
end
|
35
|
+
task :default => :spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/progress.rb
CHANGED
@@ -64,7 +64,7 @@ class Progress
|
|
64
64
|
# Progress.highlight = true
|
65
65
|
def start(title, total = 1)
|
66
66
|
levels << new(title, total)
|
67
|
-
print_message
|
67
|
+
print_message(true)
|
68
68
|
if block_given?
|
69
69
|
begin
|
70
70
|
yield
|
@@ -97,13 +97,13 @@ class Progress
|
|
97
97
|
|
98
98
|
def stop
|
99
99
|
if levels.last
|
100
|
-
print_message if levels.last.step_if_blank
|
100
|
+
print_message(true) if levels.last.step_if_blank
|
101
101
|
levels.pop
|
102
102
|
io.puts if levels.empty?
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
attr_writer :
|
106
|
+
attr_writer :lines, :highlight # :nodoc:
|
107
107
|
|
108
108
|
private
|
109
109
|
|
@@ -112,8 +112,10 @@ class Progress
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def io
|
115
|
-
@io
|
116
|
-
|
115
|
+
unless @io
|
116
|
+
@io = $stderr
|
117
|
+
@io.sync = true
|
118
|
+
end
|
117
119
|
@io
|
118
120
|
end
|
119
121
|
|
@@ -129,29 +131,45 @@ class Progress
|
|
129
131
|
@highlight.nil? ? io_tty? : @highlight
|
130
132
|
end
|
131
133
|
|
132
|
-
def
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
value = current == 0 ? '......' : '%5.1f%%' % (current * 100.0)
|
138
|
-
messages << "#{l.title}: #{!highlight? || value == '100.0%' ? value : "\e[1m#{value}\e[0m"}"
|
139
|
-
inner = current
|
140
|
-
end
|
141
|
-
message = messages.reverse * ' > '
|
142
|
-
|
143
|
-
unless lines?
|
144
|
-
previous_length = @previous_length || 0
|
145
|
-
message_cl = if highlight?
|
146
|
-
message.gsub(/\033\[(0|1)m/, '')
|
134
|
+
def time_to_print?
|
135
|
+
if @previous
|
136
|
+
if @previous < Time.now - 0.3
|
137
|
+
@previous = Time.now
|
138
|
+
true
|
147
139
|
else
|
148
|
-
|
140
|
+
false
|
149
141
|
end
|
150
|
-
|
151
|
-
|
142
|
+
else
|
143
|
+
@previous = Time.now
|
144
|
+
true
|
152
145
|
end
|
146
|
+
end
|
153
147
|
|
154
|
-
|
148
|
+
def print_message(force = false)
|
149
|
+
if force || time_to_print?
|
150
|
+
messages = []
|
151
|
+
inner = 0
|
152
|
+
levels.reverse.each do |l|
|
153
|
+
current = l.to_f(inner)
|
154
|
+
value = current == 0 ? '......' : '%5.1f%%' % (current * 100.0)
|
155
|
+
messages << "#{l.title}: #{!highlight? || value == '100.0%' ? value : "\e[1m#{value}\e[0m"}"
|
156
|
+
inner = current
|
157
|
+
end
|
158
|
+
message = messages.reverse * ' > '
|
159
|
+
|
160
|
+
unless lines?
|
161
|
+
previous_length = @previous_length || 0
|
162
|
+
message_cl = if highlight?
|
163
|
+
message.gsub(/\033\[(0|1)m/, '')
|
164
|
+
else
|
165
|
+
message
|
166
|
+
end
|
167
|
+
@previous_length = message_cl.length
|
168
|
+
message = "#{message}#{' ' * [previous_length - message_cl.length, 0].max}\r"
|
169
|
+
end
|
170
|
+
|
171
|
+
lines? ? io.puts(message) : io.print(message)
|
172
|
+
end
|
155
173
|
end
|
156
174
|
end
|
157
175
|
end
|
data/progress.gemspec
CHANGED
data/spec/progress_spec.rb
CHANGED