progressbar 0.21.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/LICENSE.txt +19 -0
- data/README.md +38 -0
- data/Rakefile +2 -14
- data/lib/progressbar.rb +14 -284
- data/lib/ruby-progressbar/base.rb +161 -0
- data/lib/ruby-progressbar/calculators/length.rb +88 -0
- data/lib/ruby-progressbar/calculators/length_spec.rb +9 -0
- data/lib/ruby-progressbar/calculators/running_average.rb +9 -0
- data/lib/ruby-progressbar/components.rb +5 -0
- data/lib/ruby-progressbar/components/bar.rb +96 -0
- data/lib/ruby-progressbar/components/percentage.rb +29 -0
- data/lib/ruby-progressbar/components/rate.rb +43 -0
- data/lib/ruby-progressbar/components/time.rb +103 -0
- data/lib/ruby-progressbar/components/title.rb +13 -0
- data/lib/ruby-progressbar/errors/invalid_progress_error.rb +4 -0
- data/lib/ruby-progressbar/format.rb +3 -0
- data/lib/ruby-progressbar/format/formatter.rb +27 -0
- data/lib/ruby-progressbar/format/molecule.rb +58 -0
- data/lib/ruby-progressbar/format/string.rb +36 -0
- data/lib/ruby-progressbar/output.rb +61 -0
- data/lib/ruby-progressbar/outputs/non_tty.rb +47 -0
- data/lib/ruby-progressbar/outputs/tty.rb +32 -0
- data/lib/ruby-progressbar/progress.rb +114 -0
- data/lib/ruby-progressbar/throttle.rb +25 -0
- data/lib/ruby-progressbar/time.rb +30 -0
- data/lib/ruby-progressbar/timer.rb +72 -0
- data/lib/ruby-progressbar/version.rb +3 -0
- data/spec/fixtures/benchmark.rb +28 -0
- data/spec/ruby-progressbar/base_spec.rb +949 -0
- data/spec/ruby-progressbar/calculators/length_calculator_spec.rb +17 -0
- data/spec/ruby-progressbar/calculators/running_average_spec.rb +19 -0
- data/spec/ruby-progressbar/components/bar_spec.rb +234 -0
- data/spec/ruby-progressbar/components/percentage_spec.rb +9 -0
- data/spec/ruby-progressbar/components/rate_spec.rb +9 -0
- data/spec/ruby-progressbar/components/throttle_spec.rb +157 -0
- data/spec/ruby-progressbar/components/time_spec.rb +307 -0
- data/spec/ruby-progressbar/components/title_spec.rb +12 -0
- data/spec/ruby-progressbar/format/formatter_spec.rb +9 -0
- data/spec/ruby-progressbar/format/molecule_spec.rb +30 -0
- data/spec/ruby-progressbar/format/string_spec.rb +9 -0
- data/spec/ruby-progressbar/output_spec.rb +7 -0
- data/spec/ruby-progressbar/outputs/non_tty_spec.rb +9 -0
- data/spec/ruby-progressbar/outputs/tty_spec.rb +9 -0
- data/spec/ruby-progressbar/progress_spec.rb +156 -0
- data/spec/ruby-progressbar/time_spec.rb +45 -0
- data/spec/ruby-progressbar/timer_spec.rb +7 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/time.rb +17 -0
- metadata +134 -69
- metadata.gz.sig +3 -0
- data/.gitignore +0 -23
- data/.ruby-version +0 -1
- data/.travis.yml +0 -6
- data/ChangeLog +0 -113
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -27
- data/LICENSE +0 -1
- data/README.rdoc +0 -116
- data/progressbar.gemspec +0 -29
- data/test/test.rb +0 -125
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 961db6323b945f7b6373152fb44363bfd8a6ac51
|
4
|
+
data.tar.gz: 379bef4d424ce616f2f7b98e0de4881474d3c636
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45799ecf9e67670603bb0cbeb959508fbe148a30681d07c5dff599b8fb3ee9aefa06d1ac24f42552977b463760340d83724b0d4193297ffa60dcf49654d10084
|
7
|
+
data.tar.gz: 60430265e9174a0fe0a1484986d956683b8dea789683fb78c7956852bf9c5759b569d6e476ad0c6871084f32ee27ff43fd274a598985722e0d1d870870c6c90d
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2010-2016 The Kompanee, Ltd
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
Ruby/ProgressBar
|
2
|
+
================================
|
3
|
+
[![Gem Version](https://img.shields.io/gem/v/ruby-progressbar.svg)](https://rubygems.org/gems/ruby-progressbar) ![Rubygems Rank Overall](https://img.shields.io/gem/rt/ruby-progressbar.svg) ![Rubygems Rank Daily](https://img.shields.io/gem/rd/ruby-progressbar.svg) ![Rubygems Downloads](https://img.shields.io/gem/dv/ruby-progressbar/stable.svg) [![Build Status](https://img.shields.io/travis/jfelchner/ruby-progressbar/master.svg)](http://travis-ci.org/jfelchner/ruby-progressbar) [![Code Climate](https://codeclimate.com/github/jfelchner/ruby-progressbar.svg)](https://codeclimate.com/github/jfelchner/ruby-progressbar) [![Code Climate](https://codeclimate.com/github/jfelchner/ruby-progressbar/coverage.svg)](https://codeclimate.com/github/jfelchner/ruby-progressbar)
|
4
|
+
|
5
|
+
<img src="https://www.dropbox.com/s/pe9o1yobxtubof8/ruby-progressbar-cage.png?dl=1" align="right" />
|
6
|
+
|
7
|
+
The **ultimate** text progress bar library for Ruby! It'll **SMASH YOU OVER THE HEAD** with a **PURE RUSH** of progress bar excitement!
|
8
|
+
|
9
|
+
Don't miss out on what all the kids are talking about! If you want everyone to know that your gem or app can survive _in the cage_ then YOU WANT **RUBY-PROGRESSBAR**!
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
Full Reference
|
14
|
+
--------------------------------
|
15
|
+
|
16
|
+
There's gotten to be too much awesome to pack into one page. Visit the [wiki](https://github.com/jfelchner/ruby-progressbar/wiki) for the full documentation.
|
17
|
+
|
18
|
+
Here's a [quick link](https://github.com/jfelchner/ruby-progressbar/wiki/Basic-Usage) to the 'Basic Usage' section.
|
19
|
+
|
20
|
+
Issues
|
21
|
+
--------------------------------
|
22
|
+
|
23
|
+
If you have problems, please create a [Github issue](https://github.com/jfelchner/ruby-progressbar/issues).
|
24
|
+
|
25
|
+
Credits
|
26
|
+
--------------------------------
|
27
|
+
|
28
|
+
![The Kompanee](https://www.dropbox.com/s/86jfka1d6bhv8as/kompanee-text-black.png?dl=1)
|
29
|
+
|
30
|
+
ruby-progressbar is maintained by [The Kompanee, Ltd.](http://www.thekompanee.com)
|
31
|
+
|
32
|
+
The names and logos for The Kompanee are trademarks of The Kompanee, Ltd.
|
33
|
+
|
34
|
+
License
|
35
|
+
--------------------------------
|
36
|
+
|
37
|
+
ruby-progressbar 1.0 is Copyright © 2011-2016 The Kompanee. It is free software, and may be redistributed under the terms specified in the LICENSE file.
|
38
|
+
ruby-progressbar 0.9.0 is Copyright © 2008 [Satoru Takabayashi](http://namazu.org/~satoru/)
|
data/Rakefile
CHANGED
@@ -1,14 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
task :default => :test
|
5
|
-
|
6
|
-
require 'rake/testtask'
|
7
|
-
Rake::TestTask.new(:test) do |test|
|
8
|
-
test.libs << 'lib' << 'test'
|
9
|
-
test.pattern = 'test/test.rb'
|
10
|
-
test.verbose = true
|
11
|
-
end
|
12
|
-
|
13
|
-
require 'yard'
|
14
|
-
YARD::Rake::YardocTask.new
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'bundler/gem_tasks'
|
data/lib/progressbar.rb
CHANGED
@@ -1,288 +1,18 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'ruby-progressbar/output'
|
3
|
+
require 'ruby-progressbar/outputs/tty'
|
4
|
+
require 'ruby-progressbar/outputs/non_tty'
|
5
|
+
require 'ruby-progressbar/timer'
|
6
|
+
require 'ruby-progressbar/progress'
|
7
|
+
require 'ruby-progressbar/throttle'
|
8
|
+
require 'ruby-progressbar/calculators/length'
|
9
|
+
require 'ruby-progressbar/calculators/running_average'
|
10
|
+
require 'ruby-progressbar/components'
|
11
|
+
require 'ruby-progressbar/format'
|
12
|
+
require 'ruby-progressbar/base'
|
11
13
|
|
12
14
|
class ProgressBar
|
13
|
-
|
14
|
-
|
15
|
-
def initialize (title, total, out = STDERR)
|
16
|
-
@title = title
|
17
|
-
@total = total
|
18
|
-
@out = out
|
19
|
-
@terminal_width = 80
|
20
|
-
@bar_mark = "o"
|
21
|
-
@current = 0
|
22
|
-
@previous = 0
|
23
|
-
@finished_p = false
|
24
|
-
@start_time = Time.now
|
25
|
-
@previous_time = @start_time
|
26
|
-
@title_width = 14
|
27
|
-
@format = "%-#{@title_width}s %3d%% %s %s"
|
28
|
-
@format_arguments = [:title, :percentage, :bar, :stat]
|
29
|
-
clear
|
30
|
-
show
|
31
|
-
if block_given?
|
32
|
-
yield(self)
|
33
|
-
finish
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
attr_reader :title
|
38
|
-
attr_reader :current
|
39
|
-
attr_reader :total
|
40
|
-
attr_accessor :start_time
|
41
|
-
attr_writer :bar_mark
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def fmt_bar
|
46
|
-
bar_width = do_percentage * @terminal_width / 100
|
47
|
-
sprintf("|%s%s|",
|
48
|
-
@bar_mark * bar_width,
|
49
|
-
" " * (@terminal_width - bar_width))
|
50
|
-
end
|
51
|
-
|
52
|
-
def fmt_percentage
|
53
|
-
do_percentage
|
54
|
-
end
|
55
|
-
|
56
|
-
def fmt_stat
|
57
|
-
if @finished_p then elapsed else eta end
|
58
|
-
end
|
59
|
-
|
60
|
-
def fmt_stat_for_long_run
|
61
|
-
if @finished_p then elapsed else eta_running_average end
|
62
|
-
end
|
63
|
-
|
64
|
-
def fmt_stat_for_file_transfer
|
65
|
-
if @finished_p then
|
66
|
-
sprintf("%s %s %s", bytes, transfer_rate, elapsed)
|
67
|
-
else
|
68
|
-
sprintf("%s %s %s", bytes, transfer_rate, eta)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def fmt_title
|
73
|
-
@title[0,(@title_width - 1)] + ":"
|
74
|
-
end
|
75
|
-
|
76
|
-
def convert_bytes (bytes)
|
77
|
-
if bytes < 1024
|
78
|
-
sprintf("%6dB", bytes)
|
79
|
-
elsif bytes < 1024 * 1000 # 1000kb
|
80
|
-
sprintf("%5.1fKB", bytes.to_f / 1024)
|
81
|
-
elsif bytes < 1024 * 1024 * 1000 # 1000mb
|
82
|
-
sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
|
83
|
-
else
|
84
|
-
sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def transfer_rate
|
89
|
-
bytes_per_second = @current.to_f / (Time.now - @start_time)
|
90
|
-
sprintf("%s/s", convert_bytes(bytes_per_second))
|
91
|
-
end
|
92
|
-
|
93
|
-
def bytes
|
94
|
-
convert_bytes(@current)
|
95
|
-
end
|
96
|
-
|
97
|
-
def format_time (t)
|
98
|
-
t = t.to_i
|
99
|
-
sec = t % 60
|
100
|
-
min = (t / 60) % 60
|
101
|
-
hour = t / 3600
|
102
|
-
sprintf("% 3d:%02d:%02d", hour, min, sec);
|
103
|
-
end
|
104
|
-
|
105
|
-
# ETA stands for Estimated Time of Arrival.
|
106
|
-
def eta
|
107
|
-
if @current == 0
|
108
|
-
"ETA: --:--:--"
|
109
|
-
else
|
110
|
-
elapsed = Time.now - @start_time
|
111
|
-
eta = elapsed * @total / @current - elapsed;
|
112
|
-
sprintf("ETA: %s", format_time(eta))
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
# Compute ETA with running average (better suited to long running tasks)
|
117
|
-
def eta_running_average
|
118
|
-
now = Time.now
|
119
|
-
|
120
|
-
# update throughput running average
|
121
|
-
if @total > 0 && @eta_previous && @eta_previous_time
|
122
|
-
current_elapsed = @current - @eta_previous
|
123
|
-
alpha = 0.9 ** current_elapsed
|
124
|
-
current_progress = 1.0 * current_elapsed
|
125
|
-
current_throughput = current_progress / (now - @eta_previous_time)
|
126
|
-
if @eta_throughput
|
127
|
-
@eta_throughput = @eta_throughput * alpha + current_throughput * (1-alpha)
|
128
|
-
else
|
129
|
-
@eta_throughput = current_throughput
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
@eta_previous = @current
|
134
|
-
@eta_previous_time = now
|
135
|
-
|
136
|
-
if @eta_throughput && @eta_throughput > 0
|
137
|
-
eta = (@total - @current) / @eta_throughput;
|
138
|
-
sprintf("ETA: %s", format_time(eta))
|
139
|
-
else
|
140
|
-
"ETA: --:--:--"
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
def elapsed
|
145
|
-
elapsed = Time.now - @start_time
|
146
|
-
sprintf("Time: %s", format_time(elapsed))
|
147
|
-
end
|
148
|
-
|
149
|
-
def eol
|
150
|
-
if @finished_p then "\n" else "\r" end
|
151
|
-
end
|
152
|
-
|
153
|
-
def do_percentage
|
154
|
-
if @total.zero?
|
155
|
-
100
|
156
|
-
else
|
157
|
-
@current * 100 / @total
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
DEFAULT_WIDTH = 80
|
162
|
-
def get_term_width
|
163
|
-
term_width = if ENV['COLUMNS'] =~ /^\d+$/
|
164
|
-
ENV['COLUMNS'].to_i
|
165
|
-
elsif (RUBY_PLATFORM =~ /java/ || (!STDIN.tty? && ENV['TERM'])) && shell_command_exists?('tput')
|
166
|
-
`tput cols`.to_i
|
167
|
-
elsif STDIN.tty? && shell_command_exists?('stty')
|
168
|
-
`stty size`.scan(/\d+/).map { |s| s.to_i }[1]
|
169
|
-
else
|
170
|
-
DEFAULT_WIDTH
|
171
|
-
end
|
172
|
-
|
173
|
-
if term_width > 0
|
174
|
-
term_width
|
175
|
-
else
|
176
|
-
DEFAULT_WIDTH
|
177
|
-
end
|
178
|
-
rescue
|
179
|
-
DEFAULT_WIDTH
|
180
|
-
end
|
181
|
-
|
182
|
-
def shell_command_exists?(command)
|
183
|
-
ENV['PATH'].split(File::PATH_SEPARATOR).any?{|d| File.exists? File.join(d, command) }
|
184
|
-
end
|
185
|
-
|
186
|
-
def show
|
187
|
-
arguments = @format_arguments.map {|method|
|
188
|
-
method = sprintf("fmt_%s", method)
|
189
|
-
send(method)
|
190
|
-
}
|
191
|
-
line = sprintf(@format, *arguments)
|
192
|
-
|
193
|
-
width = get_term_width
|
194
|
-
if line.length == width - 1
|
195
|
-
@out.print(line + eol)
|
196
|
-
@out.flush
|
197
|
-
elsif line.length >= width
|
198
|
-
@terminal_width = [@terminal_width - (line.length - width + 1), 0].max
|
199
|
-
if @terminal_width == 0 then @out.print(line + eol) else show end
|
200
|
-
else # line.length < width - 1
|
201
|
-
@terminal_width += width - line.length + 1
|
202
|
-
show
|
203
|
-
end
|
204
|
-
@previous_time = Time.now
|
205
|
-
end
|
206
|
-
|
207
|
-
def show_if_needed
|
208
|
-
if @total.zero?
|
209
|
-
cur_percentage = 100
|
210
|
-
prev_percentage = 0
|
211
|
-
else
|
212
|
-
cur_percentage = (@current * 100 / @total).to_i
|
213
|
-
prev_percentage = (@previous * 100 / @total).to_i
|
214
|
-
end
|
215
|
-
|
216
|
-
# Use "!=" instead of ">" to support negative changes
|
217
|
-
if cur_percentage != prev_percentage ||
|
218
|
-
Time.now - @previous_time >= 1 || @finished_p
|
219
|
-
show
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
public
|
224
|
-
|
225
|
-
def clear
|
226
|
-
@out.print "\r"
|
227
|
-
@out.print(" " * (get_term_width - 1))
|
228
|
-
@out.print "\r"
|
229
|
-
end
|
230
|
-
|
231
|
-
def finish
|
232
|
-
@current = @total
|
233
|
-
@finished_p = true
|
234
|
-
show
|
235
|
-
end
|
236
|
-
|
237
|
-
def finished?
|
238
|
-
@finished_p
|
239
|
-
end
|
240
|
-
|
241
|
-
def file_transfer_mode
|
242
|
-
@format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
|
243
|
-
end
|
244
|
-
|
245
|
-
def long_running
|
246
|
-
@format_arguments = [:title, :percentage, :bar, :stat_for_long_run]
|
247
|
-
end
|
248
|
-
|
249
|
-
def format= (format)
|
250
|
-
@format = format
|
251
|
-
end
|
252
|
-
|
253
|
-
def format_arguments= (arguments)
|
254
|
-
@format_arguments = arguments
|
255
|
-
end
|
256
|
-
|
257
|
-
def halt
|
258
|
-
@finished_p = true
|
259
|
-
show
|
260
|
-
end
|
261
|
-
|
262
|
-
def inc (step = 1)
|
263
|
-
@current += step
|
264
|
-
@current = @total if @current > @total
|
265
|
-
show_if_needed
|
266
|
-
@previous = @current
|
267
|
-
end
|
268
|
-
|
269
|
-
def set (count)
|
270
|
-
if count < 0 || count > @total
|
271
|
-
raise "invalid count: #{count} (total: #{@total})"
|
272
|
-
end
|
273
|
-
@current = count
|
274
|
-
show_if_needed
|
275
|
-
@previous = @current
|
276
|
-
end
|
277
|
-
|
278
|
-
def inspect
|
279
|
-
"#<ProgressBar:#{@current}/#{@total}>"
|
280
|
-
end
|
281
|
-
|
282
|
-
end
|
283
|
-
|
284
|
-
class ReversedProgressBar < ProgressBar
|
285
|
-
def do_percentage
|
286
|
-
100 - super
|
15
|
+
def self.create(*args)
|
16
|
+
ProgressBar::Base.new(*args)
|
287
17
|
end
|
288
18
|
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
class ProgressBar
|
4
|
+
class Base
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
def_delegators :output,
|
8
|
+
:clear,
|
9
|
+
:log,
|
10
|
+
:refresh
|
11
|
+
|
12
|
+
def_delegators :progressable,
|
13
|
+
:progress,
|
14
|
+
:total
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
self.autostart = options.fetch(:autostart, true)
|
18
|
+
self.autofinish = options.fetch(:autofinish, true)
|
19
|
+
self.finished = false
|
20
|
+
|
21
|
+
self.timer = Timer.new(options)
|
22
|
+
self.progressable = Progress.new(options)
|
23
|
+
|
24
|
+
options = options.merge(:timer => timer,
|
25
|
+
:progress => progressable)
|
26
|
+
|
27
|
+
self.title_comp = Components::Title.new(options)
|
28
|
+
self.bar = Components::Bar.new(options)
|
29
|
+
self.percentage = Components::Percentage.new(options)
|
30
|
+
self.rate = Components::Rate.new(options)
|
31
|
+
self.time = Components::Time.new(options)
|
32
|
+
|
33
|
+
self.output = Output.detect(options.merge(:bar => self))
|
34
|
+
@format = Format::String.new(output.resolve_format(options[:format]))
|
35
|
+
|
36
|
+
start :at => options[:starting_at] if autostart
|
37
|
+
end
|
38
|
+
|
39
|
+
def start(options = {})
|
40
|
+
clear
|
41
|
+
|
42
|
+
timer.start
|
43
|
+
update_progress(:start, options)
|
44
|
+
end
|
45
|
+
|
46
|
+
def finish
|
47
|
+
return if finished?
|
48
|
+
|
49
|
+
output.with_refresh do
|
50
|
+
self.finished = true
|
51
|
+
progressable.finish
|
52
|
+
timer.stop
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def pause
|
57
|
+
output.with_refresh { timer.pause } unless paused?
|
58
|
+
end
|
59
|
+
|
60
|
+
def stop
|
61
|
+
output.with_refresh { timer.stop } unless stopped?
|
62
|
+
end
|
63
|
+
|
64
|
+
def resume
|
65
|
+
output.with_refresh { timer.resume } if stopped?
|
66
|
+
end
|
67
|
+
|
68
|
+
def reset
|
69
|
+
output.with_refresh do
|
70
|
+
self.finished = false
|
71
|
+
progressable.reset
|
72
|
+
timer.reset
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def stopped?
|
77
|
+
timer.stopped? || finished?
|
78
|
+
end
|
79
|
+
|
80
|
+
alias paused? stopped?
|
81
|
+
|
82
|
+
def finished?
|
83
|
+
finished || (autofinish && progressable.finished?)
|
84
|
+
end
|
85
|
+
|
86
|
+
def started?
|
87
|
+
timer.started?
|
88
|
+
end
|
89
|
+
|
90
|
+
def decrement
|
91
|
+
update_progress(:decrement)
|
92
|
+
end
|
93
|
+
|
94
|
+
def increment
|
95
|
+
update_progress(:increment)
|
96
|
+
end
|
97
|
+
|
98
|
+
def progress=(new_progress)
|
99
|
+
update_progress(:progress=, new_progress)
|
100
|
+
end
|
101
|
+
|
102
|
+
def total=(new_total)
|
103
|
+
update_progress(:total=, new_total)
|
104
|
+
end
|
105
|
+
|
106
|
+
def progress_mark=(mark)
|
107
|
+
output.refresh_with_format_change { bar.progress_mark = mark }
|
108
|
+
end
|
109
|
+
|
110
|
+
def remainder_mark=(mark)
|
111
|
+
output.refresh_with_format_change { bar.remainder_mark = mark }
|
112
|
+
end
|
113
|
+
|
114
|
+
def title
|
115
|
+
title_comp.title
|
116
|
+
end
|
117
|
+
|
118
|
+
def title=(title)
|
119
|
+
output.refresh_with_format_change { title_comp.title = title }
|
120
|
+
end
|
121
|
+
|
122
|
+
def to_s(new_format = nil)
|
123
|
+
self.format = new_format if new_format
|
124
|
+
|
125
|
+
Format::Formatter.process(@format, output.length, self)
|
126
|
+
end
|
127
|
+
|
128
|
+
def inspect
|
129
|
+
"#<ProgressBar:#{progress}/#{total || 'unknown'}>"
|
130
|
+
end
|
131
|
+
|
132
|
+
def format=(other)
|
133
|
+
output.refresh_with_format_change do
|
134
|
+
@format = Format::String.new(other || output.default_format)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
alias format format=
|
139
|
+
|
140
|
+
protected
|
141
|
+
|
142
|
+
attr_accessor :output,
|
143
|
+
:timer,
|
144
|
+
:progressable,
|
145
|
+
:title_comp,
|
146
|
+
:bar,
|
147
|
+
:percentage,
|
148
|
+
:rate,
|
149
|
+
:time,
|
150
|
+
:autostart,
|
151
|
+
:autofinish,
|
152
|
+
:finished
|
153
|
+
|
154
|
+
def update_progress(*args)
|
155
|
+
output.with_refresh do
|
156
|
+
progressable.__send__(*args)
|
157
|
+
timer.stop if finished?
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|