progress_bar 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/pronto.yml +1 -1
- data/.github/workflows/rspec.yml +5 -4
- data/.rubocop.yml +6 -6
- data/Changelog.mkd +8 -0
- data/Gemfile +2 -0
- data/README.mkd +40 -8
- data/Rakefile +5 -3
- data/examples/enumerable.rb +3 -2
- data/examples/printing_messages.rb +22 -0
- data/examples/simple.rb +2 -1
- data/lib/progress_bar.rb +39 -35
- data/lib/progress_bar/core_ext/enumerable_with_progress.rb +3 -1
- data/lib/progress_bar/version.rb +3 -1
- data/lib/progress_bar/with_progress.rb +6 -4
- data/progress_bar.gemspec +2 -3
- data/spec/arguments_spec.rb +16 -19
- data/spec/bar_spec.rb +9 -9
- data/spec/counter_spec.rb +18 -23
- data/spec/elapsed_spec.rb +17 -15
- data/spec/eta_spec.rb +19 -18
- data/spec/percentage_spec.rb +17 -18
- data/spec/print_spec.rb +21 -0
- data/spec/progress_bar_spec.rb +16 -16
- data/spec/rate_spec.rb +24 -24
- data/spec/spec_helper.rb +4 -4
- data/spec/with_progress_spec.rb +18 -12
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93deaf290ed6e467982f59e116823785ec82927e7c490b46fa4379dc08b23777
|
4
|
+
data.tar.gz: c7888385f8bdb280e39fb63d212bcdc75ee5f20a04aaccff753e35d110151e6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f384ee668213ae7b49b5b3d7b22c3ee8ccaabe1303b46f34f7f5f7db4713aeeff03480acd8ca515084cdfaad64f849c4078272a3b5ad43c79ae78ea78f149ec
|
7
|
+
data.tar.gz: 353313ddaec29915b98efcaa0f60d470b08094b729b6b8b8afb33c38c6cad0ee17f26f6ea9d5fb532fc5649fd4cb7b18382e86087b6a80e42aa648d4bee82d43
|
data/.github/workflows/rspec.yml
CHANGED
@@ -8,11 +8,12 @@ jobs:
|
|
8
8
|
strategy:
|
9
9
|
matrix:
|
10
10
|
ruby:
|
11
|
-
- 2.4
|
12
|
-
- 2.5
|
13
|
-
- 2.6
|
11
|
+
- 2.4.x
|
12
|
+
- 2.5.x
|
13
|
+
- 2.6.x
|
14
|
+
- 2.7.x
|
14
15
|
steps:
|
15
|
-
- uses: actions/checkout@v1
|
16
|
+
- uses: actions/checkout@v1
|
16
17
|
- uses: actions/setup-ruby@v1
|
17
18
|
with:
|
18
19
|
ruby-version: ${{ matrix.ruby }}
|
data/.rubocop.yml
CHANGED
@@ -5,12 +5,10 @@ inherit_from:
|
|
5
5
|
require:
|
6
6
|
- rubocop-rspec
|
7
7
|
|
8
|
-
Rails:
|
9
|
-
Enabled: true
|
10
|
-
|
11
8
|
AllCops:
|
12
9
|
DisplayCopNames: true
|
13
10
|
DisplayStyleGuide: true
|
11
|
+
NewCops: enable
|
14
12
|
TargetRubyVersion: 2.6
|
15
13
|
|
16
14
|
Exclude:
|
@@ -20,7 +18,7 @@ AllCops:
|
|
20
18
|
- "script/**/*"
|
21
19
|
- "tmp/**/*"
|
22
20
|
|
23
|
-
Layout/
|
21
|
+
Layout/HashAlignment:
|
24
22
|
EnforcedHashRocketStyle: table
|
25
23
|
EnforcedColonStyle: table
|
26
24
|
Lint/AmbiguousBlockAssociation:
|
@@ -53,7 +51,7 @@ Metrics/BlockLength:
|
|
53
51
|
- shared_context
|
54
52
|
- feature
|
55
53
|
- define_type
|
56
|
-
|
54
|
+
Layout/LineLength:
|
57
55
|
Enabled: true
|
58
56
|
Max: 120
|
59
57
|
Metrics/ClassLength:
|
@@ -63,7 +61,7 @@ Naming/RescuedExceptionsVariableName:
|
|
63
61
|
PreferredName: ex
|
64
62
|
Naming/FileName:
|
65
63
|
Enabled: false
|
66
|
-
Naming/
|
64
|
+
Naming/MethodParameterName:
|
67
65
|
Enabled: false
|
68
66
|
Style/EmptyLiteral:
|
69
67
|
Enabled: false
|
@@ -76,6 +74,8 @@ Style/HashSyntax:
|
|
76
74
|
- lib/tasks/**/*.rake
|
77
75
|
Style/NumericLiterals:
|
78
76
|
Enabled: false
|
77
|
+
Style/StringConcatenation:
|
78
|
+
Enabled: false
|
79
79
|
Style/StringLiterals:
|
80
80
|
Enabled: true
|
81
81
|
EnforcedStyle: double_quotes
|
data/Changelog.mkd
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# 1.3.2
|
2
|
+
|
3
|
+
* Added `ProgressBar#puts`, to be able to print text to the output without
|
4
|
+
interfering with the rendering of the bar output.
|
5
|
+
[#56](https://github.com/paul/progress_bar/pull/56) Thanks to
|
6
|
+
[TRex22](https://github.com/TRex22) for the suggestion in
|
7
|
+
[#44](https://github.com/paul/progress_bar/pull/44).
|
8
|
+
|
1
9
|
# 1.3.1
|
2
10
|
|
3
11
|
* Added support for passing bar options to `Enumerable#with_progress`
|
data/Gemfile
CHANGED
data/README.mkd
CHANGED
@@ -20,14 +20,16 @@ lots of progress bar alternatives, and we thank you for using ProgressBar!
|
|
20
20
|
|
21
21
|
## The Easy Way
|
22
22
|
|
23
|
+
```ruby
|
24
|
+
require 'progress_bar'
|
23
25
|
|
24
|
-
|
25
|
-
bar = ProgressBar.new
|
26
|
+
bar = ProgressBar.new
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
100.times do
|
29
|
+
sleep 0.1
|
30
|
+
bar.increment!
|
31
|
+
end
|
32
|
+
```
|
31
33
|
|
32
34
|
Produces output like:
|
33
35
|
|
@@ -42,15 +44,43 @@ it.*
|
|
42
44
|
Usually, the defaults should be fine, the only thing you'll need to
|
43
45
|
tweak is the max.
|
44
46
|
|
45
|
-
|
47
|
+
```ruby
|
48
|
+
bar = ProgressBar.new(1000)
|
49
|
+
```
|
46
50
|
|
47
51
|
## Larger Steps
|
48
52
|
|
49
53
|
If you want to process several things, and update less often, you can
|
50
54
|
pass a number to `#increment!`
|
51
55
|
|
56
|
+
```ruby
|
52
57
|
bar.increment! 42
|
58
|
+
```
|
59
|
+
|
60
|
+
## Printing additional output
|
61
|
+
|
62
|
+
Sometimes you want to print some additional messages in the output, but since the ProgressBar uses terminal control characters to replace the text on the same line on every update, the output looks funny:
|
63
|
+
|
64
|
+
[####################################### ] [ 59.00%] [00:06]
|
65
|
+
Hello!
|
66
|
+
[######################################### ] [ 60.00%] [00:05]
|
53
67
|
|
68
|
+
To prevent this, you can use `ProgressBar#puts` so ProgressBar knows you want to print something, and it'll clear the bar before printing, then resume printing on the next line:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
100.times do |i|
|
72
|
+
sleep 0.1
|
73
|
+
bar.puts "Halfway there!" if i == 50
|
74
|
+
bar.increment!
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
Produces output like:
|
79
|
+
|
80
|
+
Halfway there!
|
81
|
+
[##################################] [100/100] [100%] [00:10] [00:00] [ 9.98/s]
|
82
|
+
|
83
|
+
Try it out in `examples/printing_messages.rb` to see how it looks.
|
54
84
|
|
55
85
|
## Picking the meters
|
56
86
|
|
@@ -58,7 +88,9 @@ By default, ProgressBar will use all available meters (this will
|
|
58
88
|
probably change). To select which meters you want, and in which order,
|
59
89
|
pass them to the constructor:
|
60
90
|
|
61
|
-
|
91
|
+
```ruby
|
92
|
+
bar = ProgressBar.new(100, :bar, :rate, :eta)
|
93
|
+
```
|
62
94
|
|
63
95
|
|
64
96
|
### Available Meters
|
data/Rakefile
CHANGED
data/examples/enumerable.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
|
3
|
+
require_relative "../lib/progress_bar/core_ext/enumerable_with_progress"
|
3
4
|
|
4
|
-
|
5
|
+
(20...34).with_progress.select{ |i| sleep 0.1; (i % 2).zero? }
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../lib/progress_bar"
|
4
|
+
|
5
|
+
bar = ProgressBar.new
|
6
|
+
|
7
|
+
100.times do |i|
|
8
|
+
sleep 0.1
|
9
|
+
bar.puts("Some long text\nthat contains newlines") if i == 10
|
10
|
+
bar.puts("Halfway there!") if i == 50
|
11
|
+
bar.puts("Almost done!") if i == 90
|
12
|
+
bar.increment!
|
13
|
+
end
|
14
|
+
|
15
|
+
__END__
|
16
|
+
|
17
|
+
$ ruby examples/printing_messages.rb
|
18
|
+
Some long text
|
19
|
+
that contains newlines
|
20
|
+
Halfway there!
|
21
|
+
Almost done!
|
22
|
+
[##################################] [100/100] [100%] [00:10] [00:00] [ 9.98/s]
|
data/examples/simple.rb
CHANGED
data/lib/progress_bar.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
require
|
3
|
-
require
|
3
|
+
require "options"
|
4
|
+
require "highline"
|
4
5
|
|
5
6
|
class ProgressBar
|
6
7
|
Error = Class.new(StandardError)
|
@@ -9,34 +10,41 @@ class ProgressBar
|
|
9
10
|
attr_accessor :count, :max, :meters
|
10
11
|
|
11
12
|
def initialize(*args)
|
12
|
-
|
13
13
|
@count = 0
|
14
14
|
@max = 100
|
15
15
|
@meters = [:bar, :counter, :percentage, :elapsed, :eta, :rate]
|
16
16
|
|
17
|
-
@max
|
17
|
+
@max = args.shift if args.first.is_a? Numeric
|
18
18
|
raise ArgumentError, "Max must be a positive integer" unless @max >= 0
|
19
19
|
|
20
|
-
@meters
|
20
|
+
@meters = args unless args.empty?
|
21
21
|
|
22
22
|
@last_write = ::Time.at(0)
|
23
23
|
@start = ::Time.now
|
24
24
|
|
25
|
-
@hl
|
25
|
+
@hl = HighLine.new
|
26
|
+
@terminal_width = 80
|
27
|
+
@last_width_adjustment = Time.at(0)
|
26
28
|
end
|
27
29
|
|
28
30
|
def increment!(count = 1)
|
29
|
-
|
31
|
+
@count += count
|
30
32
|
now = ::Time.now
|
31
|
-
if (now - @last_write) > 0.2 ||
|
33
|
+
if (now - @last_write) > 0.2 || @count >= max
|
32
34
|
write
|
33
35
|
@last_write = now
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
37
|
-
def
|
39
|
+
def puts(text)
|
38
40
|
clear!
|
39
|
-
|
41
|
+
$stderr.write(text)
|
42
|
+
$stderr.puts
|
43
|
+
write
|
44
|
+
end
|
45
|
+
|
46
|
+
def write
|
47
|
+
print "\r" + to_s
|
40
48
|
end
|
41
49
|
|
42
50
|
def remaining
|
@@ -73,8 +81,8 @@ class ProgressBar
|
|
73
81
|
|
74
82
|
def to_s
|
75
83
|
self.count = max if count > max
|
76
|
-
meters.inject(
|
77
|
-
text << render(meter)
|
84
|
+
meters.inject(String.new) do |text, meter|
|
85
|
+
text << "#{render(meter)} "
|
78
86
|
end.strip
|
79
87
|
end
|
80
88
|
|
@@ -85,7 +93,7 @@ class ProgressBar
|
|
85
93
|
end
|
86
94
|
|
87
95
|
def clear!
|
88
|
-
print "\r"
|
96
|
+
print "\r" + " " * terminal_width + "\r"
|
89
97
|
end
|
90
98
|
|
91
99
|
def render(meter)
|
@@ -97,13 +105,11 @@ class ProgressBar
|
|
97
105
|
end
|
98
106
|
|
99
107
|
def render_bar
|
100
|
-
return
|
108
|
+
return "" if bar_width < 2
|
109
|
+
|
101
110
|
progress_width = (ratio * (bar_width - 2)).floor
|
102
111
|
remainder_width = bar_width - 2 - progress_width
|
103
|
-
"["
|
104
|
-
"#" * progress_width +
|
105
|
-
" " * remainder_width +
|
106
|
-
"]"
|
112
|
+
"[#{'#' * progress_width}#{' ' * remainder_width}]"
|
107
113
|
end
|
108
114
|
|
109
115
|
def render_counter
|
@@ -124,20 +130,17 @@ class ProgressBar
|
|
124
130
|
end
|
125
131
|
|
126
132
|
def render_rate
|
127
|
-
"[%#{max_width+3}.2f/s]" % rate
|
133
|
+
"[%#{max_width + 3}.2f/s]" % rate
|
128
134
|
end
|
129
135
|
|
130
136
|
def terminal_width
|
131
137
|
# HighLine check takes a long time, so only update width every second.
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
@terminal_width = 80
|
139
|
-
end
|
140
|
-
@terminal_width
|
138
|
+
now = ::Time.now
|
139
|
+
if now - @last_width_adjustment > 1
|
140
|
+
@last_width_adjustment = now
|
141
|
+
new_width = @hl.output_cols.to_i
|
142
|
+
new_width = 80 if new_width < 1
|
143
|
+
@terminal_width = new_width
|
141
144
|
else
|
142
145
|
@terminal_width
|
143
146
|
end
|
@@ -148,12 +151,12 @@ class ProgressBar
|
|
148
151
|
end
|
149
152
|
|
150
153
|
def non_bar_width
|
151
|
-
meters.reject { |
|
154
|
+
meters.reject { |meter| meter == :bar }.inject(0) do |width, meter|
|
152
155
|
width += width_of(meter) + 1
|
153
156
|
end
|
154
157
|
end
|
155
158
|
|
156
|
-
def counter_width
|
159
|
+
def counter_width # [ 1/100]
|
157
160
|
max_width * 2 + 3
|
158
161
|
end
|
159
162
|
|
@@ -181,14 +184,15 @@ class ProgressBar
|
|
181
184
|
max.to_s.length
|
182
185
|
end
|
183
186
|
|
187
|
+
HOUR = 3600
|
188
|
+
MINUTE = 60
|
184
189
|
def format_interval(interval)
|
185
|
-
if interval >
|
186
|
-
"%02i:%02i:%02i" % [interval/
|
190
|
+
if interval > HOUR
|
191
|
+
"%02i:%02i:%02i" % [interval / HOUR, interval % HOUR / MINUTE, interval % MINUTE]
|
187
192
|
else
|
188
|
-
"%02i:%02i" % [interval/
|
193
|
+
"%02i:%02i" % [interval / MINUTE, interval % MINUTE]
|
189
194
|
end
|
190
195
|
end
|
191
|
-
|
192
196
|
end
|
193
197
|
|
194
|
-
require_relative
|
198
|
+
require_relative "progress_bar/with_progress"
|
data/lib/progress_bar/version.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ProgressBar
|
2
4
|
module WithProgress
|
3
5
|
def each_with_progress(*args, &block)
|
4
6
|
bar = ProgressBar.new(count, *args)
|
5
7
|
if block
|
6
|
-
each{|obj| yield(obj).tap{bar.increment!}}
|
8
|
+
each{ |obj| yield(obj).tap{ bar.increment! } }
|
7
9
|
else
|
8
|
-
Enumerator.new{|yielder|
|
9
|
-
|
10
|
-
(yielder << obj).tap{bar.increment!}
|
10
|
+
Enumerator.new{ |yielder|
|
11
|
+
each do |obj|
|
12
|
+
(yielder << obj).tap{ bar.increment! }
|
11
13
|
end
|
12
14
|
}
|
13
15
|
end
|
data/progress_bar.gemspec
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require "progress_bar/version"
|
3
|
+
require_relative "lib/progress_bar/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
6
|
s.name = "progress_bar"
|
@@ -14,7 +13,7 @@ Gem::Specification.new do |s|
|
|
14
13
|
s.summary = "Simple Progress Bar for output to a terminal"
|
15
14
|
s.description = "Give people feedback about long-running tasks without overloading them with information: Use a progress bar, like Curl or Wget!"
|
16
15
|
|
17
|
-
s.
|
16
|
+
s.required_ruby_version = ">= 2.4.0"
|
18
17
|
|
19
18
|
s.add_dependency("highline", [">= 1.6", "< 3"])
|
20
19
|
s.add_dependency("options", "~> 2.3.0")
|
data/spec/arguments_spec.rb
CHANGED
@@ -1,40 +1,37 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
4
|
+
|
5
|
+
describe "ProgressBar arguments" do
|
6
|
+
let(:default_max) { 100 }
|
7
|
+
let(:default_meters) { [:bar, :counter, :percentage, :elapsed, :eta, :rate] }
|
8
8
|
|
9
9
|
it "should set appropriate defaults without any arguments" do
|
10
10
|
bar = ProgressBar.new
|
11
|
-
bar.max.
|
12
|
-
bar.meters.
|
11
|
+
expect(bar.max).to eq default_max
|
12
|
+
expect(bar.meters).to eq default_meters
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should allow a single argument specifying the max" do
|
16
16
|
bar = ProgressBar.new(123)
|
17
|
-
bar.max.
|
18
|
-
bar.meters.
|
17
|
+
expect(bar.max).to eq 123
|
18
|
+
expect(bar.meters).to eq default_meters
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should allow specifying just the meters" do
|
22
22
|
bar = ProgressBar.new(:bar, :eta)
|
23
|
-
bar.max.
|
24
|
-
bar.meters.
|
23
|
+
expect(bar.max).to eq default_max
|
24
|
+
expect(bar.meters).to eq [:bar, :eta]
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should allow specyfing the max and meters" do
|
28
28
|
bar = ProgressBar.new(123, :bar, :eta)
|
29
|
-
bar.max.
|
30
|
-
bar.meters.
|
29
|
+
expect(bar.max).to eq 123
|
30
|
+
expect(bar.meters).to eq [:bar, :eta]
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should raise an error when initial max is nonsense" do
|
34
|
-
|
35
|
-
|
36
|
-
}.should raise_error(ProgressBar::ArgumentError)
|
34
|
+
expect { ProgressBar.new(-1) }
|
35
|
+
.to raise_error(ProgressBar::ArgumentError)
|
37
36
|
end
|
38
|
-
|
39
37
|
end
|
40
|
-
|
data/spec/bar_spec.rb
CHANGED
@@ -1,37 +1,39 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
4
|
+
|
5
|
+
describe "ProgressBar bar output" do
|
4
6
|
let(:max) { 100 }
|
5
7
|
let(:terminal_width) { 12 }
|
6
8
|
|
7
9
|
let(:progress_bar) { ProgressBar.new(max, :bar) }
|
8
10
|
|
9
11
|
before do
|
10
|
-
progress_bar.
|
12
|
+
allow(progress_bar).to receive(:terminal_width).and_return(terminal_width)
|
11
13
|
progress_bar.count = count
|
12
14
|
end
|
13
15
|
|
14
16
|
subject { progress_bar.to_s }
|
15
17
|
|
16
|
-
describe
|
18
|
+
describe "at count=0" do
|
17
19
|
let(:count) { 0 }
|
18
20
|
|
19
21
|
it { should == "[ ]" }
|
20
22
|
end
|
21
23
|
|
22
|
-
describe
|
24
|
+
describe "at count=50" do
|
23
25
|
let(:count) { 50 }
|
24
26
|
|
25
27
|
it { should == "[##### ]" }
|
26
28
|
end
|
27
29
|
|
28
|
-
describe
|
30
|
+
describe "at count=100" do
|
29
31
|
let(:count) { 100 }
|
30
32
|
|
31
33
|
it { should == "[##########]" }
|
32
34
|
end
|
33
35
|
|
34
|
-
describe
|
36
|
+
describe "at count=25 (non-integer divide, should round down)" do
|
35
37
|
let(:count) { 25 }
|
36
38
|
|
37
39
|
it { should == "[## ]" }
|
@@ -50,6 +52,4 @@ describe 'ProgressBar bar output' do
|
|
50
52
|
end
|
51
53
|
end
|
52
54
|
end
|
53
|
-
|
54
55
|
end
|
55
|
-
|
data/spec/counter_spec.rb
CHANGED
@@ -1,50 +1,45 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
4
|
+
|
5
|
+
describe "ProgressBar counter output" do
|
6
|
+
let(:progress_bar) { ProgressBar.new(100, :counter) }
|
7
7
|
|
8
|
-
subject {
|
8
|
+
subject { progress_bar.to_s }
|
9
9
|
|
10
|
-
describe
|
10
|
+
describe "at count=0" do
|
11
11
|
before do
|
12
|
-
|
12
|
+
progress_bar.count = 0
|
13
13
|
end
|
14
14
|
|
15
15
|
it { should == "[ 0/100]" }
|
16
16
|
end
|
17
17
|
|
18
|
-
describe
|
18
|
+
describe "at count=50" do
|
19
19
|
before do
|
20
|
-
|
20
|
+
progress_bar.count = 50
|
21
21
|
end
|
22
22
|
|
23
23
|
it { should == "[ 50/100]" }
|
24
24
|
end
|
25
25
|
|
26
|
-
describe
|
26
|
+
describe "at count=100" do
|
27
27
|
before do
|
28
|
-
|
28
|
+
progress_bar.count = 100
|
29
29
|
end
|
30
30
|
|
31
31
|
it { should == "[100/100]" }
|
32
32
|
end
|
33
33
|
|
34
|
-
describe
|
35
|
-
|
36
|
-
@progress_bar = ProgressBar.new(42, :counter)
|
37
|
-
end
|
34
|
+
describe "with a shorter max" do
|
35
|
+
let(:progress_bar) { ProgressBar.new(42, :counter) }
|
38
36
|
|
39
|
-
it { should ==
|
37
|
+
it { should == "[ 0/42]" }
|
40
38
|
end
|
41
39
|
|
42
|
-
describe
|
43
|
-
|
44
|
-
@progress_bar = ProgressBar.new(4242, :counter)
|
45
|
-
end
|
40
|
+
describe "with a longer max" do
|
41
|
+
let(:progress_bar) { ProgressBar.new(4242, :counter) }
|
46
42
|
|
47
|
-
it { should ==
|
43
|
+
it { should == "[ 0/4242]" }
|
48
44
|
end
|
49
|
-
|
50
45
|
end
|
data/spec/elapsed_spec.rb
CHANGED
@@ -1,48 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
require File.expand_path(File.join(File.dirname(__FILE__),
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
4
|
+
|
5
|
+
describe "ProgressBar elapsed output" do
|
6
|
+
let(:progress_bar) { ProgressBar.new(100, :elapsed) }
|
3
7
|
|
4
|
-
describe 'ProgressBar elapsed output' do
|
5
8
|
before do
|
6
9
|
Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
|
7
|
-
|
10
|
+
progress_bar
|
8
11
|
Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 10) # 10 seconds later
|
9
12
|
end
|
10
13
|
|
11
|
-
subject {
|
14
|
+
subject { progress_bar.to_s }
|
12
15
|
|
13
|
-
describe
|
16
|
+
describe "at count=0" do
|
14
17
|
before do
|
15
|
-
|
18
|
+
progress_bar.count = 0
|
16
19
|
end
|
17
20
|
|
18
21
|
it { should == "[00:10]" }
|
19
22
|
end
|
20
23
|
|
21
|
-
describe
|
24
|
+
describe "at count=50" do
|
22
25
|
before do
|
23
|
-
|
26
|
+
progress_bar.count = 50
|
24
27
|
end
|
25
28
|
|
26
29
|
it { should == "[00:10]" }
|
27
30
|
end
|
28
31
|
|
29
|
-
describe
|
32
|
+
describe "at count=100" do
|
30
33
|
before do
|
31
|
-
|
34
|
+
progress_bar.count = 100
|
32
35
|
end
|
33
36
|
|
34
37
|
it { should == "[00:10]" }
|
35
38
|
end
|
36
39
|
|
37
|
-
describe
|
40
|
+
describe "with times over 1 hour" do
|
41
|
+
let(:progress_bar) { ProgressBar.new(42, :elapsed) }
|
42
|
+
|
38
43
|
before do
|
39
44
|
Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
|
40
|
-
@progress_bar = ProgressBar.new(42, :elapsed)
|
41
45
|
Timecop.freeze Time.utc(2010, 3, 10, 2, 0, 0) # 2 hours later
|
42
46
|
end
|
43
47
|
|
44
|
-
it { should ==
|
48
|
+
it { should == "[02:00:00]" }
|
45
49
|
end
|
46
|
-
|
47
50
|
end
|
48
|
-
|
data/spec/eta_spec.rb
CHANGED
@@ -1,50 +1,51 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
4
|
+
|
5
|
+
describe "ProgressBar eta output" do
|
6
|
+
let(:progress_bar) { ProgressBar.new(100, :eta) }
|
2
7
|
|
3
|
-
describe 'ProgressBar eta output' do
|
4
8
|
before do
|
5
9
|
Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
|
6
|
-
|
10
|
+
progress_bar
|
7
11
|
Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 10) # 10 seconds later
|
8
12
|
end
|
9
13
|
|
10
|
-
subject {
|
14
|
+
subject { progress_bar.to_s }
|
11
15
|
|
12
|
-
describe
|
16
|
+
describe "at count=0" do
|
13
17
|
before do
|
14
|
-
|
18
|
+
progress_bar.count = 0
|
15
19
|
end
|
16
20
|
|
17
21
|
it { should == "[00:00]" }
|
18
22
|
end
|
19
23
|
|
20
|
-
describe
|
24
|
+
describe "at count=50" do
|
21
25
|
before do
|
22
|
-
|
26
|
+
progress_bar.count = 50
|
23
27
|
end
|
24
28
|
|
25
29
|
it { should == "[00:10]" }
|
26
30
|
end
|
27
31
|
|
28
|
-
describe
|
32
|
+
describe "at count=100" do
|
29
33
|
before do
|
30
|
-
|
34
|
+
progress_bar.count = 100
|
31
35
|
end
|
32
36
|
|
33
37
|
it { should == "[00:00]" }
|
34
38
|
end
|
35
39
|
|
36
|
-
describe
|
40
|
+
describe "with times over 1 hour" do
|
41
|
+
let(:progress_bar) { ProgressBar.new(42, :eta) }
|
42
|
+
|
37
43
|
before do
|
38
44
|
Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
|
39
|
-
|
40
|
-
@progress_bar.count = 21
|
45
|
+
progress_bar.count = 21
|
41
46
|
Timecop.freeze Time.utc(2010, 3, 10, 2, 0, 0) # 2 hours later
|
42
47
|
end
|
43
48
|
|
44
|
-
it { should ==
|
49
|
+
it { should == "[02:00:00]" }
|
45
50
|
end
|
46
|
-
|
47
51
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
data/spec/percentage_spec.rb
CHANGED
@@ -1,44 +1,43 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
4
|
+
|
5
|
+
describe "ProgressBar percentage output" do
|
6
|
+
let(:progress_bar) { ProgressBar.new(100, :percentage) }
|
7
7
|
|
8
|
-
subject {
|
8
|
+
subject { progress_bar.to_s }
|
9
9
|
|
10
|
-
describe
|
10
|
+
describe "at count=0" do
|
11
11
|
before do
|
12
|
-
|
12
|
+
progress_bar.count = 0
|
13
13
|
end
|
14
14
|
|
15
15
|
it { should == "[ 0%]" }
|
16
16
|
end
|
17
17
|
|
18
|
-
describe
|
18
|
+
describe "at count=50" do
|
19
19
|
before do
|
20
|
-
|
20
|
+
progress_bar.count = 50
|
21
21
|
end
|
22
22
|
|
23
23
|
it { should == "[ 50%]" }
|
24
24
|
end
|
25
25
|
|
26
|
-
describe
|
26
|
+
describe "at count=100" do
|
27
27
|
before do
|
28
|
-
|
28
|
+
progress_bar.count = 100
|
29
29
|
end
|
30
30
|
|
31
31
|
it { should == "[100%]" }
|
32
32
|
end
|
33
33
|
|
34
|
-
describe
|
34
|
+
describe "with a max that is not 100" do
|
35
|
+
let(:progress_bar) { ProgressBar.new(42, :percentage) }
|
36
|
+
|
35
37
|
before do
|
36
|
-
|
37
|
-
@progress_bar.count = 21
|
38
|
+
progress_bar.count = 21
|
38
39
|
end
|
39
40
|
|
40
|
-
it { should ==
|
41
|
+
it { should == "[ 50.00%]" }
|
41
42
|
end
|
42
|
-
|
43
43
|
end
|
44
|
-
|
data/spec/print_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe "ProgressBar print output" do
|
6
|
+
let(:progress_bar) { ProgressBar.new(:counter) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
allow(progress_bar).to receive(:terminal_width).and_return(10)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should replace the current bar with the text, and continue the bar on the next line" do
|
13
|
+
expect {
|
14
|
+
progress_bar.increment!
|
15
|
+
progress_bar.puts("Hello, world!")
|
16
|
+
}.to output("\r[ 1/100]" \
|
17
|
+
"\r#{' ' * 10}" \
|
18
|
+
"\rHello, world!\n" \
|
19
|
+
"\r[ 1/100]").to_stderr
|
20
|
+
end
|
21
|
+
end
|
data/spec/progress_bar_spec.rb
CHANGED
@@ -1,47 +1,47 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
4
|
+
|
5
|
+
describe "ProgressBar bar output" do
|
6
|
+
let(:progress_bar) { ProgressBar.new(100) }
|
2
7
|
|
3
|
-
describe 'ProgressBar bar output' do
|
4
8
|
before do
|
5
9
|
Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
|
6
|
-
|
7
|
-
@progress_bar.stub(:terminal_width) { 60 }
|
10
|
+
allow(progress_bar).to receive(:terminal_width).and_return(60)
|
8
11
|
Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 10) # 10 seconds later
|
9
12
|
end
|
10
13
|
|
11
|
-
subject {
|
14
|
+
subject { progress_bar.to_s }
|
12
15
|
|
13
|
-
describe
|
16
|
+
describe "at count=0" do
|
14
17
|
before do
|
15
|
-
|
18
|
+
progress_bar.count = 0
|
16
19
|
end
|
17
20
|
|
18
21
|
it { should == "[ ] [ 0/100] [ 0%] [00:10] [00:00] [ 0.00/s]" }
|
19
22
|
end
|
20
23
|
|
21
|
-
describe
|
24
|
+
describe "at count=50" do
|
22
25
|
before do
|
23
|
-
|
26
|
+
progress_bar.count = 50
|
24
27
|
end
|
25
28
|
|
26
29
|
it { should == "[####### ] [ 50/100] [ 50%] [00:10] [00:10] [ 5.00/s]" }
|
27
30
|
end
|
28
31
|
|
29
|
-
describe
|
32
|
+
describe "at count=100" do
|
30
33
|
before do
|
31
|
-
|
34
|
+
progress_bar.count = 100
|
32
35
|
end
|
33
36
|
|
34
37
|
it { should == "[##############] [100/100] [100%] [00:10] [00:00] [ 10.00/s]" }
|
35
38
|
end
|
36
39
|
|
37
|
-
describe
|
40
|
+
describe "at count=105" do
|
38
41
|
before do
|
39
|
-
|
42
|
+
progress_bar.count = 105
|
40
43
|
end
|
41
44
|
|
42
45
|
it { should == "[##############] [100/100] [100%] [00:10] [00:00] [ 10.00/s]" }
|
43
46
|
end
|
44
|
-
|
45
47
|
end
|
46
|
-
|
47
|
-
|
data/spec/rate_spec.rb
CHANGED
@@ -1,63 +1,63 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
4
|
+
|
5
|
+
describe "ProgressBar rate output" do
|
6
|
+
let(:progress_bar) { ProgressBar.new(100, :rate) }
|
2
7
|
|
3
|
-
describe 'ProgressBar rate output' do
|
4
8
|
before do
|
5
9
|
Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
|
6
|
-
|
10
|
+
progress_bar
|
7
11
|
Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 10) # 10 seconds later
|
8
12
|
end
|
9
13
|
|
10
|
-
subject {
|
14
|
+
subject { progress_bar.to_s }
|
11
15
|
|
12
|
-
describe
|
16
|
+
describe "at count=0" do
|
13
17
|
before do
|
14
|
-
|
18
|
+
progress_bar.count = 0
|
15
19
|
end
|
16
20
|
|
17
21
|
it { should == "[ 0.00/s]" }
|
18
22
|
end
|
19
23
|
|
20
|
-
describe
|
24
|
+
describe "at count=50" do
|
21
25
|
before do
|
22
|
-
|
26
|
+
progress_bar.count = 50
|
23
27
|
end
|
24
28
|
|
25
29
|
it { should == "[ 5.00/s]" }
|
26
30
|
end
|
27
31
|
|
28
|
-
describe
|
32
|
+
describe "at count=100" do
|
29
33
|
before do
|
30
|
-
|
34
|
+
progress_bar.count = 100
|
31
35
|
end
|
32
36
|
|
33
37
|
it { should == "[ 10.00/s]" }
|
34
38
|
end
|
35
39
|
|
36
|
-
describe
|
40
|
+
describe "with a shorter max" do
|
41
|
+
let(:progress_bar) { ProgressBar.new(42, :rate) }
|
42
|
+
|
37
43
|
before do
|
38
44
|
Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
|
39
|
-
|
40
|
-
@progress_bar.count = 21
|
45
|
+
progress_bar.count = 21
|
41
46
|
Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 10) # 10 seconds later
|
42
47
|
end
|
43
48
|
|
44
|
-
it { should ==
|
49
|
+
it { should == "[ 2.10/s]" }
|
45
50
|
end
|
46
51
|
|
47
|
-
describe
|
52
|
+
describe "with a longer max" do
|
53
|
+
let(:progress_bar) { ProgressBar.new(4242, :rate) }
|
54
|
+
|
48
55
|
before do
|
49
56
|
Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
|
50
|
-
|
51
|
-
@progress_bar.count = 21
|
57
|
+
progress_bar.count = 21
|
52
58
|
Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 10) # 10 seconds later
|
53
59
|
end
|
54
60
|
|
55
|
-
it { should ==
|
61
|
+
it { should == "[ 2.10/s]" }
|
56
62
|
end
|
57
|
-
|
58
63
|
end
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
require File.expand_path(File.join(File.dirname(__FILE__),
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib/progress_bar"))
|
3
4
|
|
4
|
-
require
|
5
|
-
require
|
5
|
+
require "rspec"
|
6
|
+
require "timecop"
|
6
7
|
|
7
8
|
RSpec.configure do |cfg|
|
8
9
|
cfg.after do
|
9
10
|
Timecop.return
|
10
11
|
end
|
11
12
|
end
|
12
|
-
|
data/spec/with_progress_spec.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
2
4
|
|
3
5
|
describe ProgressBar::WithProgress do
|
4
|
-
context
|
5
|
-
let!(:bar){ProgressBar.new}
|
6
|
+
context "with block" do
|
7
|
+
let!(:bar){ ProgressBar.new }
|
8
|
+
|
6
9
|
before{
|
7
|
-
Range.
|
8
|
-
allow(ProgressBar).to receive(:new){|max| bar.max = max; bar}
|
10
|
+
Range.include ProgressBar::WithProgress
|
11
|
+
allow(ProgressBar).to receive(:new){ |max| bar.max = max; bar }
|
9
12
|
}
|
10
|
-
|
13
|
+
|
14
|
+
it "should set max and increment on each iteration" do
|
11
15
|
(1..20).each_with_progress do |i|
|
12
16
|
break if i > 10
|
13
17
|
end
|
@@ -16,19 +20,21 @@ describe ProgressBar::WithProgress do
|
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
19
|
-
context
|
20
|
-
let!(:bar){ProgressBar.new}
|
23
|
+
context "without block" do
|
24
|
+
let!(:bar){ ProgressBar.new }
|
25
|
+
|
21
26
|
before{
|
22
|
-
Range.
|
23
|
-
allow(ProgressBar).to receive(:new){|max| bar.max = max; bar}
|
27
|
+
Range.include ProgressBar::WithProgress
|
28
|
+
allow(ProgressBar).to receive(:new){ |max| bar.max = max; bar }
|
24
29
|
}
|
25
|
-
|
30
|
+
|
31
|
+
it "should give Enumerator" do
|
26
32
|
enum = (1..20).each_with_progress
|
27
33
|
expect(enum).to be_kind_of(Enumerator)
|
28
34
|
expect(bar.max).to eq 20
|
29
35
|
expect(bar.count).to eq 0
|
30
36
|
|
31
|
-
res = enum.map{|i| i + 1}
|
37
|
+
res = enum.map{ |i| i + 1 }
|
32
38
|
expect(res).to eq (2..21).to_a
|
33
39
|
expect(bar.count).to eq 20
|
34
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: progress_bar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Sadauskas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- README.mkd
|
151
151
|
- Rakefile
|
152
152
|
- examples/enumerable.rb
|
153
|
+
- examples/printing_messages.rb
|
153
154
|
- examples/simple.rb
|
154
155
|
- lib/progress_bar.rb
|
155
156
|
- lib/progress_bar/core_ext/enumerable_with_progress.rb
|
@@ -166,6 +167,7 @@ files:
|
|
166
167
|
- spec/elapsed_spec.rb
|
167
168
|
- spec/eta_spec.rb
|
168
169
|
- spec/percentage_spec.rb
|
170
|
+
- spec/print_spec.rb
|
169
171
|
- spec/progress_bar_spec.rb
|
170
172
|
- spec/rate_spec.rb
|
171
173
|
- spec/spec_helper.rb
|
@@ -182,14 +184,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
182
184
|
requirements:
|
183
185
|
- - ">="
|
184
186
|
- !ruby/object:Gem::Version
|
185
|
-
version:
|
187
|
+
version: 2.4.0
|
186
188
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
189
|
requirements:
|
188
190
|
- - ">="
|
189
191
|
- !ruby/object:Gem::Version
|
190
192
|
version: '0'
|
191
193
|
requirements: []
|
192
|
-
rubygems_version: 3.
|
194
|
+
rubygems_version: 3.1.2
|
193
195
|
signing_key:
|
194
196
|
specification_version: 4
|
195
197
|
summary: Simple Progress Bar for output to a terminal
|
@@ -200,6 +202,7 @@ test_files:
|
|
200
202
|
- spec/elapsed_spec.rb
|
201
203
|
- spec/eta_spec.rb
|
202
204
|
- spec/percentage_spec.rb
|
205
|
+
- spec/print_spec.rb
|
203
206
|
- spec/progress_bar_spec.rb
|
204
207
|
- spec/rate_spec.rb
|
205
208
|
- spec/spec_helper.rb
|