progress_bar 1.0.5 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +12 -0
- data/.github/workflows/pronto.yml +32 -0
- data/.github/workflows/rspec.yml +27 -0
- data/.gitignore +9 -0
- data/.reek.yml +51 -0
- data/.rubocop.yml +113 -0
- data/.travis.yml +4 -8
- data/Changelog.mkd +25 -0
- data/Gemfile +3 -1
- data/README.mkd +73 -9
- data/Rakefile +5 -3
- data/examples/enumerable.rb +5 -0
- data/examples/printing_messages.rb +22 -0
- data/examples/simple.rb +2 -1
- data/lib/progress_bar/core_ext/enumerable_with_progress.rb +9 -0
- data/lib/progress_bar/version.rb +3 -1
- data/lib/progress_bar/with_progress.rb +20 -0
- data/lib/progress_bar.rb +41 -35
- data/progress_bar.gemspec +12 -8
- 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 +42 -0
- metadata +75 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bb7f4ff94b18c74293549cabfa13a706919a372ad266ba128f51871e835640b9
|
4
|
+
data.tar.gz: 86ee5facbec3945a261948111955ca19e84b0bbf28d58beb5c67074b9fefb1f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cce378aa8152b13f210fa1e005ca9933146e70bf243257a057bd228833f0ab2ea2ebb9627e65a9d1c3114b43b9dafd531d6ceca13f412e1c6b94e68773f61e7
|
7
|
+
data.tar.gz: 23e2f70bb0d18351baf90809383607dd9d4c6f75591f8018d704cb487554e791560bde118f7c720bb0791abce42247f6a68c2ad7120f3aa05ac21686cc8aa628
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# These are supported funding model platforms
|
2
|
+
|
3
|
+
github: paul
|
4
|
+
patreon: # Replace with a single Patreon username
|
5
|
+
open_collective: # Replace with a single Open Collective username
|
6
|
+
ko_fi: # Replace with a single Ko-fi username
|
7
|
+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
8
|
+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
9
|
+
liberapay: # Replace with a single Liberapay username
|
10
|
+
issuehunt: # Replace with a single IssueHunt username
|
11
|
+
otechie: # Replace with a single Otechie username
|
12
|
+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
@@ -0,0 +1,32 @@
|
|
1
|
+
---
|
2
|
+
name: Lint
|
3
|
+
"on": [pull_request]
|
4
|
+
jobs:
|
5
|
+
lint:
|
6
|
+
name: Pronto
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v1.0.0
|
10
|
+
- uses: actions/setup-ruby@v1
|
11
|
+
with:
|
12
|
+
ruby-version: '2.7'
|
13
|
+
- name: Install dependencies
|
14
|
+
run: |
|
15
|
+
sudo apt-get update -qq
|
16
|
+
sudo apt-get install -qqy --no-install-recommends yamllint jq
|
17
|
+
gem install bundler --no-document
|
18
|
+
bundle install
|
19
|
+
gem install --no-document \
|
20
|
+
pronto \
|
21
|
+
pronto-brakeman \
|
22
|
+
pronto-flay \
|
23
|
+
pronto-reek \
|
24
|
+
pronto-rubocop \
|
25
|
+
pronto-yamllint
|
26
|
+
|
27
|
+
- name: Pronto
|
28
|
+
env:
|
29
|
+
PRONTO_GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
30
|
+
run: |
|
31
|
+
export PRONTO_PULL_REQUEST_ID=$(jq .number -r $GITHUB_EVENT_PATH)
|
32
|
+
pronto run -c origin/master -f github_status github_pr_review text
|
@@ -0,0 +1,27 @@
|
|
1
|
+
---
|
2
|
+
name: Test
|
3
|
+
"on": [pull_request]
|
4
|
+
jobs:
|
5
|
+
rspec:
|
6
|
+
name: RSpec
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby:
|
11
|
+
- 2.4.x
|
12
|
+
- 2.5.x
|
13
|
+
- 2.6.x
|
14
|
+
- 2.7.x
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v1
|
17
|
+
- uses: actions/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby }}
|
20
|
+
- name: Install dependencies
|
21
|
+
run: |
|
22
|
+
gem install bundler --no-document
|
23
|
+
bundle install
|
24
|
+
|
25
|
+
- name: RSpec
|
26
|
+
run: |
|
27
|
+
rspec
|
data/.gitignore
CHANGED
data/.reek.yml
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
---
|
2
|
+
exclude_paths:
|
3
|
+
- bin
|
4
|
+
|
5
|
+
detectors:
|
6
|
+
UtilityFunction:
|
7
|
+
public_methods_only: true
|
8
|
+
|
9
|
+
TooManyStatements:
|
10
|
+
exclude:
|
11
|
+
- initialize
|
12
|
+
max_statements: 8
|
13
|
+
|
14
|
+
RepeatedConditional:
|
15
|
+
max_ifs: 4
|
16
|
+
|
17
|
+
LongParameterList:
|
18
|
+
exclude:
|
19
|
+
- initialize
|
20
|
+
|
21
|
+
# This one just makes sure the Class/Module has a comment. Dumb.
|
22
|
+
IrresponsibleModule:
|
23
|
+
enabled: false
|
24
|
+
|
25
|
+
# Transaction result blocks are 3-deep
|
26
|
+
NestedIterators:
|
27
|
+
max_allowed_nesting: 3
|
28
|
+
|
29
|
+
UncommunicativeVariableName:
|
30
|
+
accept:
|
31
|
+
- i # array index
|
32
|
+
- c # config
|
33
|
+
- k # key
|
34
|
+
- v # value
|
35
|
+
- h # hash initializer (Hash.new { |h,k| h[k] = Hash.new })
|
36
|
+
- "_"
|
37
|
+
UncommunicativeModuleName:
|
38
|
+
accept:
|
39
|
+
- Auth0
|
40
|
+
|
41
|
+
# AS::Subscriber objects tend to rely heavily on `event` and `payload`, so its
|
42
|
+
# hard to avoid "Feature Envy", but is perfectly readable.
|
43
|
+
FeatureEnvy:
|
44
|
+
enabled: false
|
45
|
+
|
46
|
+
directories:
|
47
|
+
"spec/support":
|
48
|
+
UtilityFunction:
|
49
|
+
enabled: false
|
50
|
+
|
51
|
+
# vi:syntax=yaml
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
---
|
2
|
+
inherit_from:
|
3
|
+
- https://relaxed.ruby.style/rubocop.yml
|
4
|
+
|
5
|
+
require:
|
6
|
+
- rubocop-rspec
|
7
|
+
|
8
|
+
AllCops:
|
9
|
+
DisplayCopNames: true
|
10
|
+
DisplayStyleGuide: true
|
11
|
+
NewCops: enable
|
12
|
+
TargetRubyVersion: 2.6
|
13
|
+
|
14
|
+
Exclude:
|
15
|
+
- "vendor/**/*"
|
16
|
+
- "spec/fixtures/**/*"
|
17
|
+
- "bin/**/*"
|
18
|
+
- "script/**/*"
|
19
|
+
- "tmp/**/*"
|
20
|
+
|
21
|
+
Layout/HashAlignment:
|
22
|
+
EnforcedHashRocketStyle: table
|
23
|
+
EnforcedColonStyle: table
|
24
|
+
Lint/AmbiguousBlockAssociation:
|
25
|
+
Exclude:
|
26
|
+
- "spec/**/*" # `expect { }.to change { }` is fine
|
27
|
+
Lint/ShadowingOuterLocalVariable:
|
28
|
+
# Shadowing outer local variables with block parameters is often useful to
|
29
|
+
# not reinvent a new name for the same thing, it highlights the relation
|
30
|
+
# between the outer variable and the parameter. The cases where it's actually
|
31
|
+
# confusing are rare, and usually bad for other reasons already, for example
|
32
|
+
# because the method is too long.
|
33
|
+
Enabled: false
|
34
|
+
Metrics/BlockLength:
|
35
|
+
Exclude:
|
36
|
+
- Gemfile
|
37
|
+
- Guardfile
|
38
|
+
- shared_context
|
39
|
+
- feature
|
40
|
+
ExcludedMethods:
|
41
|
+
- configure
|
42
|
+
- context
|
43
|
+
- define
|
44
|
+
- describe
|
45
|
+
- factory
|
46
|
+
- it
|
47
|
+
- namespace
|
48
|
+
- specify
|
49
|
+
- task
|
50
|
+
- shared_examples_for
|
51
|
+
- shared_context
|
52
|
+
- feature
|
53
|
+
- define_type
|
54
|
+
Layout/LineLength:
|
55
|
+
Enabled: true
|
56
|
+
Max: 120
|
57
|
+
Metrics/ClassLength:
|
58
|
+
Exclude:
|
59
|
+
- "spec/**/*_spec.rb"
|
60
|
+
Naming/RescuedExceptionsVariableName:
|
61
|
+
PreferredName: ex
|
62
|
+
Naming/FileName:
|
63
|
+
Enabled: false
|
64
|
+
Naming/MethodParameterName:
|
65
|
+
Enabled: false
|
66
|
+
Style/EmptyLiteral:
|
67
|
+
Enabled: false
|
68
|
+
Style/FormatStringToken:
|
69
|
+
Enabled: false
|
70
|
+
Style/FrozenStringLiteralComment:
|
71
|
+
Enabled: true
|
72
|
+
Style/HashSyntax:
|
73
|
+
Exclude:
|
74
|
+
- lib/tasks/**/*.rake
|
75
|
+
Style/NumericLiterals:
|
76
|
+
Enabled: false
|
77
|
+
Style/StringConcatenation:
|
78
|
+
Enabled: false
|
79
|
+
Style/StringLiterals:
|
80
|
+
Enabled: true
|
81
|
+
EnforcedStyle: double_quotes
|
82
|
+
Style/SymbolArray:
|
83
|
+
MinSize: 4
|
84
|
+
|
85
|
+
# Rspec
|
86
|
+
Capybara/FeatureMethods:
|
87
|
+
Enabled: false
|
88
|
+
RSpec/ContextWording:
|
89
|
+
Enabled: false
|
90
|
+
RSpec/DescribeClass:
|
91
|
+
Enabled: false
|
92
|
+
RSpec/DescribedClass:
|
93
|
+
Enabled: false
|
94
|
+
RSpec/ExampleLength:
|
95
|
+
Max: 10
|
96
|
+
RSpec/ExampleWording:
|
97
|
+
Enabled: false
|
98
|
+
RSpec/ExpectChange:
|
99
|
+
EnforcedStyle: block
|
100
|
+
RSpec/ImplicitExpect:
|
101
|
+
Enabled: false
|
102
|
+
RSpec/LeadingSubject:
|
103
|
+
Enabled: false
|
104
|
+
RSpec/MultipleExpectations:
|
105
|
+
Max: 4
|
106
|
+
RSpec/NestedGroups:
|
107
|
+
Max: 4
|
108
|
+
RSpec/NotToNot:
|
109
|
+
Enabled: false
|
110
|
+
RSpec/ExpectInHook:
|
111
|
+
Enabled: false
|
112
|
+
RSpec/LetSetup:
|
113
|
+
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
script: rake spec
|
2
2
|
rvm:
|
3
|
-
-
|
4
|
-
- 2.
|
5
|
-
- 2.
|
3
|
+
- 2.2
|
4
|
+
- 2.3
|
5
|
+
- 2.4.0-preview3
|
6
6
|
- ruby-head
|
7
|
-
- jruby-19mode
|
8
|
-
- jruby-head
|
9
|
-
- rbx-2
|
10
7
|
|
11
8
|
matrix:
|
12
9
|
allow_failures:
|
13
10
|
- rvm:
|
14
|
-
-
|
15
|
-
- jruby-head
|
11
|
+
- 2.4.0-preview3
|
16
12
|
- ruby-head
|
data/Changelog.mkd
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# 1.3.3
|
2
|
+
|
3
|
+
* Fixed use of unqualified ::Time that was conflicting with another
|
4
|
+
ProgressBar gem [#58](https://github.com/paul/progress_bar/pull/58).
|
5
|
+
Thanks to [harryloewen](https://github.com/harryloewen) for the
|
6
|
+
[report](https://github.com/paul/progress_bar/issues/57)
|
7
|
+
|
8
|
+
# 1.3.2
|
9
|
+
|
10
|
+
* Added `ProgressBar#puts`, to be able to print text to the output without
|
11
|
+
interfering with the rendering of the bar output.
|
12
|
+
[#56](https://github.com/paul/progress_bar/pull/56) Thanks to
|
13
|
+
[TRex22](https://github.com/TRex22) for the suggestion in
|
14
|
+
[#44](https://github.com/paul/progress_bar/pull/44).
|
15
|
+
|
16
|
+
# 1.3.1
|
17
|
+
|
18
|
+
* Added support for passing bar options to `Enumerable#with_progress`
|
19
|
+
extension.
|
20
|
+
|
21
|
+
# 1.3.0
|
22
|
+
|
23
|
+
* Relaxed highline gem requirement to allow highline 2.0 as well as 1.6+
|
24
|
+
|
25
|
+
|
data/Gemfile
CHANGED
data/README.mkd
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ProgressBar
|
2
2
|
|
3
|
-
[![Build Status](https://
|
3
|
+
[![Build Status](https://github.com/paul/progress_bar/workflows/Test/badge.svg)](https://github.com/paul/progress_bar/actions)[![Gem Version](https://badge.fury.io/rb/progress_bar.svg)](http://badge.fury.io/rb/progress_bar)
|
4
4
|
|
5
5
|
*ProgressBar* is a simple Ruby library for displaying progress of
|
6
6
|
long-running tasks on the console. It is intended to be as simple to use
|
@@ -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]
|
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]
|
53
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
|
@@ -81,6 +113,38 @@ gem install --development progress_bar
|
|
81
113
|
rspec spec/*_spec.rb
|
82
114
|
```
|
83
115
|
|
116
|
+
## Using ProgressBar on Enumerable-alikes.
|
117
|
+
|
118
|
+
If you do a lot of progresses, you can shorten your way with this:
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
class Array
|
122
|
+
include ProgressBar::WithProgress
|
123
|
+
end
|
124
|
+
|
125
|
+
[1,2,3].each_with_progress{do_something}
|
126
|
+
|
127
|
+
# or any other Enumerable's methods:
|
128
|
+
|
129
|
+
(1..1000).to_a.with_progress.select{|i| (i % 2).zero?}
|
130
|
+
```
|
84
131
|
|
132
|
+
You can include `ProgressBar::WithProgress` in any class, having methods
|
133
|
+
`#count` and `#each`, like some DB datasets and so on.
|
85
134
|
|
135
|
+
If you are using progress_bar regularly on plain arrays, you may want to
|
136
|
+
do:
|
86
137
|
|
138
|
+
```ruby
|
139
|
+
require 'progress_bar/core_ext/enumerable_with_progress'
|
140
|
+
|
141
|
+
# it adds each_with_progress/with_progress to Array/Hash/Range
|
142
|
+
|
143
|
+
(1..400).with_progress.select{|i| (i % 2).zero?}
|
144
|
+
```
|
145
|
+
|
146
|
+
If you want to display only specific meters you can do it like so:
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
(1..400).with_progress(:bar, :elapsed).select{|i| (i % 2).zero?}
|
150
|
+
```
|
data/Rakefile
CHANGED
@@ -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/version.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ProgressBar
|
4
|
+
module WithProgress
|
5
|
+
def each_with_progress(*args, &block)
|
6
|
+
bar = ProgressBar.new(count, *args)
|
7
|
+
if block
|
8
|
+
each{ |obj| yield(obj).tap{ bar.increment! } }
|
9
|
+
else
|
10
|
+
Enumerator.new{ |yielder|
|
11
|
+
each do |obj|
|
12
|
+
(yielder << obj).tap{ bar.increment! }
|
13
|
+
end
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :with_progress, :each_with_progress
|
19
|
+
end
|
20
|
+
end
|