progressbar_zobar 0.9.1.1
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/.gitignore +23 -0
- data/.rvmrc +1 -0
- data/ChangeLog +113 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +27 -0
- data/LICENSE +1 -0
- data/README.rd +106 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/lib/progressbar.rb +251 -0
- data/progressbar.gemspec +27 -0
- data/test/test.rb +137 -0
- metadata +129 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.2@progressbar
|
data/ChangeLog
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
2005-05-21 Satoru Takabayashi <satoru@namazu.org>
|
2
|
+
|
3
|
+
* progressbar.rb (ProgressBar::show): Call IO#flush. Suggestted by
|
4
|
+
"Geert Fannes" <Geert.Fannes at ikanconsulting.com>
|
5
|
+
|
6
|
+
2005-01-07 Satoru Takabayashi <satoru@namazu.org>
|
7
|
+
|
8
|
+
* progressbar.rb (ProgressBar::VERSION): Bumped version number to 0.9.
|
9
|
+
(ProgressBar::finished?): New method.
|
10
|
+
(ProgressBar::current): New attribute.
|
11
|
+
(ProgressBar::total): New attribute.
|
12
|
+
(ProgressBar::title): New attribute.
|
13
|
+
(ProgressBar::start_time): New attribute.
|
14
|
+
(ProgressBar::inspect): Change the format.
|
15
|
+
(ProgressBar::show_if_needed): Renamed from show_progress.
|
16
|
+
(ProgressBar::clear): New method.
|
17
|
+
(ProgressBar::initialize): Renamed a field: bar_width ->
|
18
|
+
terminal_width.
|
19
|
+
(ProgressBar::do_percentage): New method.
|
20
|
+
(ProgressBar::percentage): Use it.
|
21
|
+
(ReversedProgressBar): New class.
|
22
|
+
(ProgressBar::initialize): Use #clear.
|
23
|
+
(ProgressBar::fmt_bar): Ditto.
|
24
|
+
(ProgressBar::fmt_percentage): Renamed from percentage.
|
25
|
+
(ProgressBar::fmt_stat): Ditto.
|
26
|
+
(ProgressBar::fmt_stat_for_file_transfer): Ditto.
|
27
|
+
(ProgressBar::fmt_title): Ditto.
|
28
|
+
|
29
|
+
* test.rb: Use Test::Unit.
|
30
|
+
|
31
|
+
* Makefile (docs): Removed.
|
32
|
+
(progressbar.ja.html): Ditto.
|
33
|
+
(progressbar.en.html): Ditto.
|
34
|
+
(dist): New rule.
|
35
|
+
(check): New rule.
|
36
|
+
|
37
|
+
2004-02-05 Satoru Takabayashi <satoru@namazu.org>
|
38
|
+
|
39
|
+
* Ruby/ProgressBar: Version 0.8 released!
|
40
|
+
|
41
|
+
* progressbar.rb (ProgressBar::set): Fixed the bug when caused by
|
42
|
+
the invalid count. <http://bugs.debian.org/231009>
|
43
|
+
(ProgressBar::VERSION): Bumped version number to 0.8.
|
44
|
+
|
45
|
+
2004-01-19 Satoru Takabayashi <satoru@namazu.org>
|
46
|
+
|
47
|
+
* Ruby/ProgressBar: Version 0.7 released!
|
48
|
+
|
49
|
+
* progressbar.rb (ProgressBar::initialize): Rename a field:
|
50
|
+
@bar_length -> @bar_width.
|
51
|
+
(ProgressBar::initialize): New field: @title_width.
|
52
|
+
(ProgressBar::title): use it.
|
53
|
+
(ProgressBar::initialize): New field: @previous_time.
|
54
|
+
(ProgressBar::show_progress): Use it and update the progress bar
|
55
|
+
if one sec. elapsed.
|
56
|
+
(ProgressBar::initialize): Call show instead of show_progress.
|
57
|
+
|
58
|
+
2004-01-16 Satoru Takabayashi <satoru@namazu.org>
|
59
|
+
|
60
|
+
* Ruby/ProgressBar: Version 0.6 released!
|
61
|
+
|
62
|
+
* progressbar.rb (ProgressBar::show): Remove the useless condition
|
63
|
+
after "else". Thanks to Neil Spring <nspring@cs.washington.edu>
|
64
|
+
for the report.
|
65
|
+
<http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=227966>
|
66
|
+
(ProgressBar):
|
67
|
+
|
68
|
+
2003-07-24 Satoru Takabayashi <satoru@namazu.org>
|
69
|
+
|
70
|
+
* Ruby/ProgressBar: Version 0.5 released!
|
71
|
+
|
72
|
+
* progressbar.rb (ProgressBar::initialize): New parameter: config.
|
73
|
+
(ProgressBar::convert_prefix_multiplier): New method.
|
74
|
+
(ProgressBar::transfer_rate): New method.
|
75
|
+
(ProgressBar::percentage): New method.
|
76
|
+
(ProgressBar::title): New method.
|
77
|
+
(ProgressBar::initialize): New fields: @bar_mark, @format,
|
78
|
+
@arguments.
|
79
|
+
(ProgressBar::get_width): New method.
|
80
|
+
(ProgressBar::stat_for_file_transfer): New method.
|
81
|
+
(ProgressBar::stat): Renamed from time.
|
82
|
+
(ProgressBar::format=): New method.
|
83
|
+
(ProgressBar::format_arguments=): New method.
|
84
|
+
(ProgressBar::convert_bytes): New method.
|
85
|
+
(ProgressBar::file_transfer_mode): New method.
|
86
|
+
|
87
|
+
2002-10-21 Satoru Takabayashi <satoru@namazu.org>
|
88
|
+
|
89
|
+
* Ruby/ProgressBar: Version 0.4 released!
|
90
|
+
|
91
|
+
* progressbar.rb (ProgressBar::halt): New method. allowing a
|
92
|
+
"broken" ProgressBar in the event of error.
|
93
|
+
- Suggestted by Austin Ziegler <austin@halostatue.ca>
|
94
|
+
|
95
|
+
2002-01-05 Satoru Takabayashi <satoru@namazu.org>
|
96
|
+
|
97
|
+
* Ruby/ProgressBar: Version 0.3 released!
|
98
|
+
|
99
|
+
* progressbar.rb (ProgressBar::show): Shorten @title to fall into
|
100
|
+
the format well.
|
101
|
+
|
102
|
+
2001-11-03 Satoru Takabayashi <satoru@namazu.org>
|
103
|
+
|
104
|
+
* Ruby/ProgressBar: Version 0.2 released!
|
105
|
+
|
106
|
+
* progressbar.rb (ProgressBar::eta): Remove an unnecessary condition.
|
107
|
+
|
108
|
+
* progressbar.rb (ProgressBar::eta): Fix the return value bug.
|
109
|
+
|
110
|
+
* progressbar.rb (ProgressBar::inc): Add an optional parameter `step'.
|
111
|
+
|
112
|
+
* Ruby/ProgressBar: Version 0.1 released!
|
113
|
+
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
progressbar (0.9.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
bluecloth (2.1.0)
|
10
|
+
minitest (2.2.2)
|
11
|
+
rake (0.9.2)
|
12
|
+
simplecov (0.4.2)
|
13
|
+
simplecov-html (~> 0.4.4)
|
14
|
+
simplecov-html (0.4.5)
|
15
|
+
yard (0.7.1)
|
16
|
+
|
17
|
+
PLATFORMS
|
18
|
+
ruby
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
bluecloth (>= 0.3.5)
|
22
|
+
bundler (>= 1.0.0)
|
23
|
+
minitest
|
24
|
+
progressbar!
|
25
|
+
rake
|
26
|
+
simplecov (>= 0.3.5)
|
27
|
+
yard
|
data/LICENSE
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Ruby/ProgressBar is a free software with ABSOLUTELY NO WARRANTY under the terms of Ruby's license.
|
data/README.rd
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
=begin
|
2
|
+
index:Ej
|
3
|
+
|
4
|
+
= Ruby/ProgressBar: A Text Progress Bar Library for Ruby
|
5
|
+
|
6
|
+
Last Modified: 2005-05-22 00:28:04
|
7
|
+
|
8
|
+
--
|
9
|
+
|
10
|
+
Ruby/ProgressBar is a text progress bar library for Ruby.
|
11
|
+
It can indicate progress with percentage, a progress bar,
|
12
|
+
and estimated remaining time.
|
13
|
+
|
14
|
+
The latest version of Ruby/ProgressBar is available at
|
15
|
+
((<URL:http://namazu.org/~satoru/ruby-progressbar/>))
|
16
|
+
.
|
17
|
+
|
18
|
+
== Examples
|
19
|
+
|
20
|
+
% irb --simple-prompt -r progressbar
|
21
|
+
>> pbar = ProgressBar.new("test", 100)
|
22
|
+
=> (ProgressBar: 0/100)
|
23
|
+
>> 100.times {sleep(0.1); pbar.inc}; pbar.finish
|
24
|
+
test: 100% |oooooooooooooooooooooooooooooooooooooooo| Time: 00:00:10
|
25
|
+
=> nil
|
26
|
+
|
27
|
+
>> pbar = ProgressBar.new("test", 100)
|
28
|
+
=> (ProgressBar: 0/100)
|
29
|
+
>> (1..100).each{|x| sleep(0.1); pbar.set(x)}; pbar.finish
|
30
|
+
test: 67% |oooooooooooooooooooooooooo | ETA: 00:00:03
|
31
|
+
|
32
|
+
== API
|
33
|
+
|
34
|
+
--- ProgressBar#new (title, total, out = STDERR)
|
35
|
+
Display the initial progress bar and return a
|
36
|
+
ProgressBar object. ((|title|)) specifies the title,
|
37
|
+
and ((|total|)) specifies the total cost of processing.
|
38
|
+
Optional parameter ((|out|)) specifies the output IO.
|
39
|
+
|
40
|
+
The display of the progress bar is updated when one or
|
41
|
+
more percent is proceeded or one or more seconds are
|
42
|
+
elapsed from the previous display.
|
43
|
+
|
44
|
+
--- ProgressBar#inc (step = 1)
|
45
|
+
Increase the internal counter by ((|step|)) and update
|
46
|
+
the display of the progress bar. Display the estimated
|
47
|
+
remaining time on the right side of the bar. The counter
|
48
|
+
does not go beyond the ((|total|)).
|
49
|
+
|
50
|
+
--- ProgressBar#set (count)
|
51
|
+
Set the internal counter to ((|count|)) and update the
|
52
|
+
display of the progress bar. Display the estimated
|
53
|
+
remaining time on the right side of the bar. Raise if
|
54
|
+
((|count|)) is a negative number or a number more than
|
55
|
+
the ((|total|)).
|
56
|
+
|
57
|
+
--- ProgressBar#finish
|
58
|
+
Stop the progress bar and update the display of progress
|
59
|
+
bar. Display the elapsed time on the right side of the bar.
|
60
|
+
The progress bar always stops at 100 % by the method.
|
61
|
+
|
62
|
+
--- ProgressBar#halt
|
63
|
+
Stop the progress bar and update the display of progress
|
64
|
+
bar. Display the elapsed time on the right side of the bar.
|
65
|
+
The progress bar stops at the current percentage by the method.
|
66
|
+
|
67
|
+
--- ProgressBar#format=
|
68
|
+
Set the format for displaying a progress bar.
|
69
|
+
Default: "%-14s %3d%% %s %s".
|
70
|
+
|
71
|
+
--- ProgressBar#format_arguments=
|
72
|
+
Set the methods for displaying a progress bar.
|
73
|
+
Default: [:title, :percentage, :bar, :stat].
|
74
|
+
|
75
|
+
--- ProgressBar#file_transfer_mode
|
76
|
+
Use :stat_for_file_transfer instead of :stat to display
|
77
|
+
transfered bytes and transfer rate.
|
78
|
+
|
79
|
+
--- ProgressBar#total=
|
80
|
+
Change the progress bar's maximum value.
|
81
|
+
|
82
|
+
|
83
|
+
ReverseProgressBar class is also available. The
|
84
|
+
functionality is identical to ProgressBar but the direction
|
85
|
+
of the progress bar is just opposite.
|
86
|
+
|
87
|
+
== Limitations
|
88
|
+
|
89
|
+
Since the progress is calculated by the proportion to the
|
90
|
+
total cost of processing, Ruby/ProgressBar cannot be used if
|
91
|
+
the total cost of processing is unknown in advance.
|
92
|
+
Moreover, the estimation of remaining time cannot be
|
93
|
+
accurately performed if the progress does not flow uniformly.
|
94
|
+
|
95
|
+
== Download
|
96
|
+
|
97
|
+
Ruby/ProgressBar is a free software with ABSOLUTELY NO WARRANTY
|
98
|
+
under the terms of Ruby's license.
|
99
|
+
|
100
|
+
* ((<URL:http://namazu.org/~satoru/ruby-progressbar/ruby-progressbar-0.9.tar.gz>))
|
101
|
+
* ((<URL:http://cvs.namazu.org/ruby-progressbar/>))
|
102
|
+
|
103
|
+
--
|
104
|
+
|
105
|
+
- ((<Satoru Takabayashi|URL:http://namazu.org/~satoru/>)) -
|
106
|
+
=end
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
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
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.9.0
|
data/lib/progressbar.rb
ADDED
@@ -0,0 +1,251 @@
|
|
1
|
+
#
|
2
|
+
# Ruby/ProgressBar - a text progress bar library
|
3
|
+
#
|
4
|
+
# Copyright (C) 2001-2005 Satoru Takabayashi <satoru@namazu.org>
|
5
|
+
# All rights reserved.
|
6
|
+
# This is free software with ABSOLUTELY NO WARRANTY.
|
7
|
+
#
|
8
|
+
# You can redistribute it and/or modify it under the terms
|
9
|
+
# of Ruby's license.
|
10
|
+
#
|
11
|
+
|
12
|
+
class ProgressBar
|
13
|
+
VERSION = "0.9"
|
14
|
+
|
15
|
+
def initialize (title, total, out = STDERR)
|
16
|
+
@title = title
|
17
|
+
@prev_total = @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
|
+
end
|
32
|
+
attr_reader :title
|
33
|
+
attr_reader :current
|
34
|
+
attr_reader :total
|
35
|
+
attr_accessor :start_time
|
36
|
+
attr_writer :bar_mark
|
37
|
+
|
38
|
+
private
|
39
|
+
def fmt_bar
|
40
|
+
bar_width = do_percentage * @terminal_width / 100
|
41
|
+
sprintf("|%s%s|",
|
42
|
+
@bar_mark * bar_width,
|
43
|
+
" " * (@terminal_width - bar_width))
|
44
|
+
end
|
45
|
+
|
46
|
+
def fmt_percentage
|
47
|
+
do_percentage
|
48
|
+
end
|
49
|
+
|
50
|
+
def fmt_stat
|
51
|
+
if @finished_p then elapsed else eta end
|
52
|
+
end
|
53
|
+
|
54
|
+
def fmt_stat_for_file_transfer
|
55
|
+
if @finished_p then
|
56
|
+
sprintf("%s %s %s", bytes, transfer_rate, elapsed)
|
57
|
+
else
|
58
|
+
sprintf("%s %s %s", bytes, transfer_rate, eta)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def fmt_title
|
63
|
+
@title[0,(@title_width - 1)] + ":"
|
64
|
+
end
|
65
|
+
|
66
|
+
def convert_bytes (bytes)
|
67
|
+
if bytes < 1024
|
68
|
+
sprintf("%6dB", bytes)
|
69
|
+
elsif bytes < 1024 * 1000 # 1000kb
|
70
|
+
sprintf("%5.1fKB", bytes.to_f / 1024)
|
71
|
+
elsif bytes < 1024 * 1024 * 1000 # 1000mb
|
72
|
+
sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
|
73
|
+
else
|
74
|
+
sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def transfer_rate
|
79
|
+
bytes_per_second = @current.to_f / (Time.now - @start_time)
|
80
|
+
sprintf("%s/s", convert_bytes(bytes_per_second))
|
81
|
+
end
|
82
|
+
|
83
|
+
def bytes
|
84
|
+
convert_bytes(@current)
|
85
|
+
end
|
86
|
+
|
87
|
+
def format_time (t)
|
88
|
+
t = t.to_i
|
89
|
+
sec = t % 60
|
90
|
+
min = (t / 60) % 60
|
91
|
+
hour = t / 3600
|
92
|
+
sprintf("%02d:%02d:%02d", hour, min, sec);
|
93
|
+
end
|
94
|
+
|
95
|
+
# ETA stands for Estimated Time of Arrival.
|
96
|
+
def eta
|
97
|
+
if @current == 0
|
98
|
+
"ETA: --:--:--"
|
99
|
+
else
|
100
|
+
elapsed = Time.now - @start_time
|
101
|
+
eta = elapsed * @total / @current - elapsed;
|
102
|
+
sprintf("ETA: %s", format_time(eta))
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def elapsed
|
107
|
+
elapsed = Time.now - @start_time
|
108
|
+
sprintf("Time: %s", format_time(elapsed))
|
109
|
+
end
|
110
|
+
|
111
|
+
def eol
|
112
|
+
if @finished_p then "\n" else "\r" end
|
113
|
+
end
|
114
|
+
|
115
|
+
def do_percentage
|
116
|
+
if @total.zero?
|
117
|
+
100
|
118
|
+
else
|
119
|
+
@current * 100 / @total
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def get_width
|
124
|
+
# FIXME: I don't know how portable it is.
|
125
|
+
default_width = 80
|
126
|
+
begin
|
127
|
+
tiocgwinsz = 0x5413
|
128
|
+
data = [0, 0, 0, 0].pack("SSSS")
|
129
|
+
if @out.ioctl(tiocgwinsz, data) >= 0 then
|
130
|
+
rows, cols, xpixels, ypixels = data.unpack("SSSS")
|
131
|
+
if cols >= 0 then cols else default_width end
|
132
|
+
else
|
133
|
+
default_width
|
134
|
+
end
|
135
|
+
rescue Exception
|
136
|
+
default_width
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def show
|
141
|
+
arguments = @format_arguments.map {|method|
|
142
|
+
method = sprintf("fmt_%s", method)
|
143
|
+
send(method)
|
144
|
+
}
|
145
|
+
line = sprintf(@format, *arguments)
|
146
|
+
|
147
|
+
width = get_width
|
148
|
+
if line.length == width - 1
|
149
|
+
@out.print(line + eol)
|
150
|
+
@out.flush
|
151
|
+
elsif line.length >= width
|
152
|
+
@terminal_width = [@terminal_width - (line.length - width + 1), 0].max
|
153
|
+
if @terminal_width == 0 then @out.print(line + eol) else show end
|
154
|
+
else # line.length < width - 1
|
155
|
+
@terminal_width += width - line.length + 1
|
156
|
+
show
|
157
|
+
end
|
158
|
+
@previous_time = Time.now
|
159
|
+
end
|
160
|
+
|
161
|
+
def show_if_needed
|
162
|
+
prev_percentage = if @prev_total.zero?
|
163
|
+
0
|
164
|
+
else
|
165
|
+
(@previous * 100 / @prev_total).to_i
|
166
|
+
end
|
167
|
+
cur_percentage = if @total.zero?
|
168
|
+
100
|
169
|
+
else
|
170
|
+
(@current * 100 / @total).to_i
|
171
|
+
end
|
172
|
+
|
173
|
+
# Use "!=" instead of ">" to support negative changes
|
174
|
+
if cur_percentage != prev_percentage ||
|
175
|
+
Time.now - @previous_time >= 1 || @finished_p
|
176
|
+
show
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
public
|
181
|
+
def clear
|
182
|
+
@out.print "\r"
|
183
|
+
@out.print(" " * (get_width - 1))
|
184
|
+
@out.print "\r"
|
185
|
+
end
|
186
|
+
|
187
|
+
def finish
|
188
|
+
@current = @total
|
189
|
+
@finished_p = true
|
190
|
+
show
|
191
|
+
end
|
192
|
+
|
193
|
+
def finished?
|
194
|
+
@finished_p
|
195
|
+
end
|
196
|
+
|
197
|
+
def file_transfer_mode
|
198
|
+
@format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
|
199
|
+
end
|
200
|
+
|
201
|
+
def format= (format)
|
202
|
+
@format = format
|
203
|
+
end
|
204
|
+
|
205
|
+
def format_arguments= (arguments)
|
206
|
+
@format_arguments = arguments
|
207
|
+
end
|
208
|
+
|
209
|
+
def halt
|
210
|
+
@finished_p = true
|
211
|
+
show
|
212
|
+
end
|
213
|
+
|
214
|
+
def inc (step = 1)
|
215
|
+
@current += step
|
216
|
+
@current = @total if @current > @total
|
217
|
+
show_if_needed
|
218
|
+
@previous = @current
|
219
|
+
end
|
220
|
+
|
221
|
+
def set (count)
|
222
|
+
if count < 0 || count > @total
|
223
|
+
raise "invalid count: #{count} (total: #{@total})"
|
224
|
+
end
|
225
|
+
@current = count
|
226
|
+
show_if_needed
|
227
|
+
@previous = @current
|
228
|
+
end
|
229
|
+
|
230
|
+
def title= (value)
|
231
|
+
@title = value
|
232
|
+
show
|
233
|
+
end
|
234
|
+
|
235
|
+
def total= (value)
|
236
|
+
@prev_total = total
|
237
|
+
@total = value
|
238
|
+
show_if_needed
|
239
|
+
@prev_total = value
|
240
|
+
end
|
241
|
+
|
242
|
+
def inspect
|
243
|
+
"#<ProgressBar:#{@current}/#{@total}>"
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
class ReversedProgressBar < ProgressBar
|
248
|
+
def do_percentage
|
249
|
+
100 - super
|
250
|
+
end
|
251
|
+
end
|
data/progressbar.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "progressbar_zobar"
|
5
|
+
s.version = "0.9.1.1"
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.authors = ["Satoru Takabayashi", "Jose Peleteiro", 'David P Kleinschmidt']
|
8
|
+
s.email = ["satoru@0xcc.net", "jose@peleteiro.net", 'david@kleinschmidt.name']
|
9
|
+
s.homepage = "http://github.com/zobar/progressbar"
|
10
|
+
s.summary = "Ruby/ProgressBar is a text progress bar library for Ruby."
|
11
|
+
s.description = "Ruby/ProgressBar is a text progress bar library for Ruby. It can indicate progress with percentage, a progress bar, and estimated remaining time."
|
12
|
+
|
13
|
+
s.required_rubygems_version = ">= 1.3.6"
|
14
|
+
|
15
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
16
|
+
s.add_development_dependency "minitest", ">= 0"
|
17
|
+
s.add_development_dependency "yard", ">= 0"
|
18
|
+
s.add_development_dependency "rake", ">= 0"
|
19
|
+
s.add_development_dependency "simplecov", ">= 0.3.5"
|
20
|
+
s.add_development_dependency "bluecloth", ">= 0.3.5"
|
21
|
+
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
24
|
+
s.require_path = 'lib'
|
25
|
+
|
26
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
27
|
+
end
|
data/test/test.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'progressbar'
|
3
|
+
|
4
|
+
class ProgressBarTest < Test::Unit::TestCase
|
5
|
+
SleepUnit = 0.01
|
6
|
+
|
7
|
+
def do_make_progress_bar (title, total)
|
8
|
+
ProgressBar.new(title, total)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_bytes
|
12
|
+
total = 1024 * 1024
|
13
|
+
pbar = do_make_progress_bar("test(bytes)", total)
|
14
|
+
pbar.file_transfer_mode
|
15
|
+
0.step(total, 2**14) {|x|
|
16
|
+
pbar.set(x)
|
17
|
+
sleep(SleepUnit)
|
18
|
+
}
|
19
|
+
pbar.finish
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_clear
|
23
|
+
total = 100
|
24
|
+
pbar = do_make_progress_bar("test(clear)", total)
|
25
|
+
total.times {
|
26
|
+
sleep(SleepUnit)
|
27
|
+
pbar.inc
|
28
|
+
}
|
29
|
+
pbar.clear
|
30
|
+
puts
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_halt
|
34
|
+
total = 100
|
35
|
+
pbar = do_make_progress_bar("test(halt)", total)
|
36
|
+
(total / 2).times {
|
37
|
+
sleep(SleepUnit)
|
38
|
+
pbar.inc
|
39
|
+
}
|
40
|
+
pbar.halt
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_inc
|
44
|
+
total = 100
|
45
|
+
pbar = do_make_progress_bar("test(inc)", total)
|
46
|
+
total.times {
|
47
|
+
sleep(SleepUnit)
|
48
|
+
pbar.inc
|
49
|
+
}
|
50
|
+
pbar.finish
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_inc_x
|
54
|
+
total = File.size("lib/progressbar.rb")
|
55
|
+
pbar = do_make_progress_bar("test(inc(x))", total)
|
56
|
+
File.new("lib/progressbar.rb").each {|line|
|
57
|
+
sleep(SleepUnit)
|
58
|
+
pbar.inc(line.length)
|
59
|
+
}
|
60
|
+
pbar.finish
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_invalid_set
|
64
|
+
total = 100
|
65
|
+
pbar = do_make_progress_bar("test(invalid set)", total)
|
66
|
+
begin
|
67
|
+
pbar.set(200)
|
68
|
+
rescue RuntimeError => e
|
69
|
+
puts e.message
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_set
|
74
|
+
total = 1000
|
75
|
+
pbar = do_make_progress_bar("test(set)", total)
|
76
|
+
(1..total).find_all {|x| x % 10 == 0}.each {|x|
|
77
|
+
sleep(SleepUnit)
|
78
|
+
pbar.set(x)
|
79
|
+
}
|
80
|
+
pbar.finish
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_slow
|
84
|
+
total = 100000
|
85
|
+
pbar = do_make_progress_bar("test(slow)", total)
|
86
|
+
0.step(500, 1) {|x|
|
87
|
+
pbar.set(x)
|
88
|
+
sleep(SleepUnit)
|
89
|
+
}
|
90
|
+
pbar.halt
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_title
|
94
|
+
total = 100
|
95
|
+
pbar = do_make_progress_bar('test(title)', total)
|
96
|
+
total.times {|i|
|
97
|
+
pbar.inc
|
98
|
+
pbar.title = "test(#{i + 1})"
|
99
|
+
sleep(SleepUnit)
|
100
|
+
}
|
101
|
+
pbar.finish
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_total
|
105
|
+
total = 100
|
106
|
+
pbar = do_make_progress_bar('test(total)', total)
|
107
|
+
pbar.inc
|
108
|
+
total.step(1, -1) {|x|
|
109
|
+
pbar.total = x
|
110
|
+
sleep(SleepUnit)
|
111
|
+
}
|
112
|
+
pbar.finish
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_total_zero
|
116
|
+
total = 0
|
117
|
+
pbar = do_make_progress_bar("test(total=0)", total)
|
118
|
+
pbar.finish
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_custom_bar_mark
|
122
|
+
total = 100
|
123
|
+
pbar = do_make_progress_bar("test(custom)", total)
|
124
|
+
pbar.bar_mark = '='
|
125
|
+
total.times {
|
126
|
+
sleep(SleepUnit)
|
127
|
+
pbar.inc
|
128
|
+
}
|
129
|
+
pbar.finish
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
class ReversedProgressBarTest < ProgressBarTest
|
134
|
+
def do_make_progress_bar (title, total)
|
135
|
+
ReversedProgressBar.new(title, total)
|
136
|
+
end
|
137
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: progressbar_zobar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Satoru Takabayashi
|
9
|
+
- Jose Peleteiro
|
10
|
+
- David P Kleinschmidt
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2011-11-16 00:00:00.000000000Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bundler
|
18
|
+
requirement: &2153368040 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.0
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *2153368040
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: &2153367580 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *2153367580
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: yard
|
40
|
+
requirement: &2153367120 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *2153367120
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rake
|
51
|
+
requirement: &2153366660 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *2153366660
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: simplecov
|
62
|
+
requirement: &2153366200 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.3.5
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *2153366200
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: bluecloth
|
73
|
+
requirement: &2153365740 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.3.5
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: *2153365740
|
82
|
+
description: Ruby/ProgressBar is a text progress bar library for Ruby. It can indicate
|
83
|
+
progress with percentage, a progress bar, and estimated remaining time.
|
84
|
+
email:
|
85
|
+
- satoru@0xcc.net
|
86
|
+
- jose@peleteiro.net
|
87
|
+
- david@kleinschmidt.name
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- .gitignore
|
93
|
+
- .rvmrc
|
94
|
+
- ChangeLog
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE
|
98
|
+
- README.rd
|
99
|
+
- Rakefile
|
100
|
+
- VERSION
|
101
|
+
- lib/progressbar.rb
|
102
|
+
- progressbar.gemspec
|
103
|
+
- test/test.rb
|
104
|
+
homepage: http://github.com/zobar/progressbar
|
105
|
+
licenses: []
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options:
|
108
|
+
- --charset=UTF-8
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 1.3.6
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 1.8.10
|
126
|
+
signing_key:
|
127
|
+
specification_version: 3
|
128
|
+
summary: Ruby/ProgressBar is a text progress bar library for Ruby.
|
129
|
+
test_files: []
|