tty-progressbar 0.12.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +0 -1
- data/examples/multi/main_bar.rb +6 -6
- data/lib/tty/progressbar.rb +4 -10
- data/lib/tty/progressbar/multi.rb +29 -12
- data/lib/tty/progressbar/version.rb +1 -1
- data/spec/unit/clear_spec.rb +1 -1
- data/spec/unit/multi/events_spec.rb +60 -7
- data/spec/unit/multi/finish_spec.rb +25 -1
- data/spec/unit/multi/register_spec.rb +1 -0
- data/spec/unit/resize_spec.rb +2 -2
- data/tty-progressbar.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4da140c43179f280941fdc51b4c7927fd9dcd648
|
4
|
+
data.tar.gz: 76f93a77ce8edc4ee982476ae19f1c9c2372a5d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4478e6b69a5d1531867f16808abd03dfbdfe2a86dc3faf789b94a33dd56d449d7e4058ac58958c994af442002e661be2b932fe72c253d03390c7c4edd04e34c2
|
7
|
+
data.tar.gz: cf73492360d38934724f208ef727100444c5e6c73efdebb928edfbaec0ad790d5cf8f40bebb889c9f70136cea8512a29c9e291b91a9e047d28b4528a2f8b186e
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.12.1] - 2017-09-09
|
4
|
+
|
5
|
+
### Added
|
6
|
+
* Add rspec to gem development dependencies
|
7
|
+
|
8
|
+
### Changed
|
9
|
+
* Change line clearing to rely on tty-cursor
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
* Fix multi bar finishing before registered progress bars
|
13
|
+
|
3
14
|
## [v0.12.0] - 2017-09-03
|
4
15
|
|
5
16
|
### Added
|
@@ -127,6 +138,7 @@
|
|
127
138
|
|
128
139
|
* Initial implementation and release
|
129
140
|
|
141
|
+
[v0.12.1]: https://github.com/peter-murach/tty-progressbar/compare/v0.12.0...v0.12.1
|
130
142
|
[v0.12.0]: https://github.com/peter-murach/tty-progressbar/compare/v0.11.0...v0.12.0
|
131
143
|
[v0.11.0]: https://github.com/peter-murach/tty-progressbar/compare/v0.10.1...v0.11.0
|
132
144
|
[v0.10.1]: https://github.com/peter-murach/tty-progressbar/compare/v0.10.0...v0.10.1
|
data/Gemfile
CHANGED
data/examples/multi/main_bar.rb
CHANGED
@@ -4,14 +4,14 @@ require 'tty-progressbar'
|
|
4
4
|
|
5
5
|
bars = TTY::ProgressBar::Multi.new("main [:bar] :percent")
|
6
6
|
|
7
|
-
bar1 = bars.register "foo [:bar] :percent", total:
|
8
|
-
bar2 = bars.register "bar [:bar] :percent", total:
|
9
|
-
bar3 = bars.register "baz [:bar] :percent", total:
|
7
|
+
bar1 = bars.register "foo [:bar] :percent", total: 15
|
8
|
+
bar2 = bars.register "bar [:bar] :percent", total: 15
|
9
|
+
bar3 = bars.register "baz [:bar] :percent", total: 45
|
10
10
|
|
11
11
|
bars.start
|
12
12
|
|
13
|
-
th1 = Thread.new {
|
14
|
-
th2 = Thread.new {
|
15
|
-
th3 = Thread.new {
|
13
|
+
th1 = Thread.new { 15.times { sleep(0.1); bar1.advance } }
|
14
|
+
th2 = Thread.new { 15.times { sleep(0.1); bar2.advance } }
|
15
|
+
th3 = Thread.new { 45.times { sleep(0.1); bar3.advance } }
|
16
16
|
|
17
17
|
[th1, th2, th3].each(&:join)
|
data/lib/tty/progressbar.rb
CHANGED
@@ -20,13 +20,7 @@ module TTY
|
|
20
20
|
extend Forwardable
|
21
21
|
include MonitorMixin
|
22
22
|
|
23
|
-
ECMA_ESC = "\e".freeze
|
24
23
|
ECMA_CSI = "\e[".freeze
|
25
|
-
ECMA_CLR = 'K'.freeze
|
26
|
-
|
27
|
-
DEC_RST = 'l'.freeze
|
28
|
-
DEC_SET = 'h'.freeze
|
29
|
-
DEC_TCEM = '?25'.freeze
|
30
24
|
|
31
25
|
CURSOR_LOCK = Monitor.new
|
32
26
|
|
@@ -242,7 +236,7 @@ module TTY
|
|
242
236
|
def render
|
243
237
|
return if done?
|
244
238
|
if hide_cursor && @last_render_width == 0 && !(@current >= total)
|
245
|
-
write(
|
239
|
+
write(TTY::Cursor.hide)
|
246
240
|
end
|
247
241
|
|
248
242
|
formatted = @formatter.decorate(self, @format)
|
@@ -316,7 +310,7 @@ module TTY
|
|
316
310
|
def finish
|
317
311
|
# reenable cursor if it is turned off
|
318
312
|
if hide_cursor && @last_render_width != 0
|
319
|
-
write(
|
313
|
+
write(TTY::Cursor.show, false)
|
320
314
|
end
|
321
315
|
return if done?
|
322
316
|
@current = total unless no_width
|
@@ -334,7 +328,7 @@ module TTY
|
|
334
328
|
def stop
|
335
329
|
# reenable cursor if it is turned off
|
336
330
|
if hide_cursor && @last_render_width != 0
|
337
|
-
write(
|
331
|
+
write(TTY::Cursor.show, false)
|
338
332
|
end
|
339
333
|
return if done?
|
340
334
|
render
|
@@ -349,7 +343,7 @@ module TTY
|
|
349
343
|
#
|
350
344
|
# @api public
|
351
345
|
def clear_line
|
352
|
-
output.print(ECMA_CSI + '0m' +
|
346
|
+
output.print(ECMA_CSI + '0m' + TTY::Cursor.clear_line)
|
353
347
|
end
|
354
348
|
|
355
349
|
# Check if progress is finised
|
@@ -50,7 +50,7 @@ module TTY
|
|
50
50
|
@bars = []
|
51
51
|
@rows = 0
|
52
52
|
@top_bar = nil
|
53
|
-
@top_bar = register(format) if format
|
53
|
+
@top_bar = register(format, observable: false) if format
|
54
54
|
|
55
55
|
@callbacks = {
|
56
56
|
progress: [],
|
@@ -66,15 +66,15 @@ module TTY
|
|
66
66
|
#
|
67
67
|
# @api public
|
68
68
|
def register(format, options = {})
|
69
|
+
observable = options.delete(:observable) { true }
|
69
70
|
bar = TTY::ProgressBar.new(format, @options.merge(options))
|
70
71
|
|
71
72
|
synchronize do
|
72
73
|
bar.attach_to(self)
|
73
74
|
@bars << bar
|
74
|
-
|
75
|
+
observe(bar) if observable
|
75
76
|
if @top_bar
|
76
77
|
@top_bar.update(total: total, width: total)
|
77
|
-
observe(bar)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -95,11 +95,21 @@ module TTY
|
|
95
95
|
# @param [TTY::ProgressBar] bar
|
96
96
|
# the bar to observe for events
|
97
97
|
#
|
98
|
-
# @api
|
98
|
+
# @api private
|
99
99
|
def observe(bar)
|
100
|
-
bar.on(:progress
|
101
|
-
.on(:done)
|
102
|
-
.on(:stopped) {
|
100
|
+
bar.on(:progress, &progress_handler)
|
101
|
+
.on(:done) { emit(:done) if complete? }
|
102
|
+
.on(:stopped) { emit(:stopped) if stopped? }
|
103
|
+
end
|
104
|
+
|
105
|
+
# Handle the progress event
|
106
|
+
#
|
107
|
+
# @api private
|
108
|
+
def progress_handler
|
109
|
+
proc do
|
110
|
+
@top_bar.current = current if @top_bar
|
111
|
+
emit(:progress)
|
112
|
+
end
|
103
113
|
end
|
104
114
|
|
105
115
|
# Get the top level bar if it exists
|
@@ -123,7 +133,9 @@ module TTY
|
|
123
133
|
#
|
124
134
|
# @api public
|
125
135
|
def total
|
126
|
-
|
136
|
+
synchronize do
|
137
|
+
(@bars - [@top_bar]).dup.map(&:total).reduce(&:+)
|
138
|
+
end
|
127
139
|
end
|
128
140
|
|
129
141
|
# Calculate total current progress of all bars
|
@@ -132,7 +144,9 @@ module TTY
|
|
132
144
|
#
|
133
145
|
# @api public
|
134
146
|
def current
|
135
|
-
|
147
|
+
synchronize do
|
148
|
+
(@bars - [@top_bar]).dup.map(&:current).reduce(&:+)
|
149
|
+
end
|
136
150
|
end
|
137
151
|
|
138
152
|
# Check if all progress bars are complete
|
@@ -141,7 +155,9 @@ module TTY
|
|
141
155
|
#
|
142
156
|
# @api public
|
143
157
|
def complete?
|
144
|
-
|
158
|
+
synchronize do
|
159
|
+
(@bars - [@top_bar]).dup.all?(&:complete?)
|
160
|
+
end
|
145
161
|
end
|
146
162
|
|
147
163
|
# Check if any of the registered progress bars is stopped
|
@@ -150,7 +166,9 @@ module TTY
|
|
150
166
|
#
|
151
167
|
# @api public
|
152
168
|
def stopped?
|
153
|
-
|
169
|
+
synchronize do
|
170
|
+
(@bars - [@top_bar]).dup.any?(&:stopped?)
|
171
|
+
end
|
154
172
|
end
|
155
173
|
|
156
174
|
# Stop all progress bars
|
@@ -164,7 +182,6 @@ module TTY
|
|
164
182
|
#
|
165
183
|
# @api public
|
166
184
|
def finish
|
167
|
-
@top_bar.finish if @top_bar
|
168
185
|
@bars.dup.each(&:finish)
|
169
186
|
end
|
170
187
|
|
data/spec/unit/clear_spec.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
RSpec.describe TTY::ProgressBar::Multi, 'events' do
|
4
4
|
let(:output) { StringIO.new('', 'w+') }
|
5
5
|
|
6
|
-
it "emits :progress
|
6
|
+
it "emits :progress event when any of the registerd bars advances" do
|
7
7
|
events = []
|
8
8
|
bars = TTY::ProgressBar::Multi.new("[:bar]", output: output, total: 5)
|
9
9
|
bars.on(:progress) { events << :progress }
|
@@ -14,31 +14,57 @@ RSpec.describe TTY::ProgressBar::Multi, 'events' do
|
|
14
14
|
expect(events).to eq([:progress])
|
15
15
|
end
|
16
16
|
|
17
|
-
it "emits :done event when all progress bars finished" do
|
17
|
+
it "emits :done event when all progress bars finished under top level" do
|
18
18
|
events = []
|
19
19
|
bars = TTY::ProgressBar::Multi.new("[:bar]", output: output, total: 5)
|
20
20
|
bars.on(:done) { events << :done }
|
21
|
-
|
22
21
|
bar = bars.register "one [:bar]"
|
23
22
|
|
24
23
|
bar.finish
|
25
24
|
|
26
25
|
expect(events).to eq([:done])
|
26
|
+
expect(bar.complete?).to eq(true)
|
27
27
|
end
|
28
28
|
|
29
|
-
it "emits :done event when
|
29
|
+
it "emits :done event when all progress bars finished without top level" do
|
30
|
+
events = []
|
31
|
+
bars = TTY::ProgressBar::Multi.new(output: output)
|
32
|
+
bars.on(:done) { events << :done }
|
33
|
+
bar = bars.register "one [:bar]", total: 5
|
34
|
+
|
35
|
+
bar.finish
|
36
|
+
|
37
|
+
expect(events).to eq([:done])
|
38
|
+
expect(bars.complete?).to eq(true)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "emits :done event when top level registered bar finished" do
|
30
42
|
events = []
|
31
43
|
bars = TTY::ProgressBar::Multi.new("[:bar]", output: output, total: 5)
|
32
44
|
bars.on(:done) { events << :done }
|
33
45
|
|
34
|
-
bars.register "one [:bar]"
|
46
|
+
bar = bars.register "one [:bar]", total: 5
|
35
47
|
|
36
48
|
bars.finish
|
37
49
|
|
38
50
|
expect(events).to eq([:done])
|
51
|
+
expect(bar.complete?).to eq(true)
|
39
52
|
end
|
40
53
|
|
41
|
-
it "emits :
|
54
|
+
it "emits :done event when top level bar finished" do
|
55
|
+
events = []
|
56
|
+
bars = TTY::ProgressBar::Multi.new(output: output)
|
57
|
+
bars.on(:done) { events << :done }
|
58
|
+
|
59
|
+
bar = bars.register "one [:bar]", total: 5
|
60
|
+
|
61
|
+
bars.finish
|
62
|
+
|
63
|
+
expect(events).to eq([:done])
|
64
|
+
expect(bar.complete?).to eq(true)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "emits :stopped event when all registerd bars are stopped under top level" do
|
42
68
|
events = []
|
43
69
|
bars = TTY::ProgressBar::Multi.new("[:bar]", output: output, total: 5)
|
44
70
|
bars.on(:stopped) { events << :stopped }
|
@@ -48,9 +74,23 @@ RSpec.describe TTY::ProgressBar::Multi, 'events' do
|
|
48
74
|
bar.stop
|
49
75
|
|
50
76
|
expect(events).to eq([:stopped])
|
77
|
+
expect(bars.stopped?).to eq(true)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "emits :stopped event when all registerd bars are stopped without top level" do
|
81
|
+
events = []
|
82
|
+
bars = TTY::ProgressBar::Multi.new(output: output)
|
83
|
+
bars.on(:stopped) { events << :stopped }
|
84
|
+
|
85
|
+
bar = bars.register "one [:bar]", total: 5
|
86
|
+
|
87
|
+
bar.stop
|
88
|
+
|
89
|
+
expect(events).to eq([:stopped])
|
90
|
+
expect(bars.stopped?).to eq(true)
|
51
91
|
end
|
52
92
|
|
53
|
-
it "emits :stopped event when
|
93
|
+
it "emits :stopped event when registerd multi bar finished" do
|
54
94
|
events = []
|
55
95
|
bars = TTY::ProgressBar::Multi.new("[:bar]", output: output, total: 5)
|
56
96
|
bars.on(:stopped) { events << :stopped }
|
@@ -61,4 +101,17 @@ RSpec.describe TTY::ProgressBar::Multi, 'events' do
|
|
61
101
|
|
62
102
|
expect(events).to eq([:stopped])
|
63
103
|
end
|
104
|
+
|
105
|
+
it "emits :stopped event when multi bar finished" do
|
106
|
+
events = []
|
107
|
+
bars = TTY::ProgressBar::Multi.new(output: output)
|
108
|
+
bars.on(:stopped) { events << :stopped }
|
109
|
+
|
110
|
+
bars.register "one [:bar]", total: 5
|
111
|
+
|
112
|
+
bars.stop
|
113
|
+
|
114
|
+
expect(events).to eq([:stopped])
|
115
|
+
expect(bars.stopped?).to eq(true)
|
116
|
+
end
|
64
117
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
RSpec.describe TTY::ProgressBar::Multi, '#finish' do
|
4
4
|
let(:output) { StringIO.new('', 'w+') }
|
5
5
|
|
6
|
-
it "finishes all bars" do
|
6
|
+
it "finishes all bars with top level" do
|
7
7
|
bars = TTY::ProgressBar::Multi.new("main [:bar]", output: output)
|
8
8
|
|
9
9
|
bar1 = bars.register("[:bar]", total: 5)
|
@@ -16,4 +16,28 @@ RSpec.describe TTY::ProgressBar::Multi, '#finish' do
|
|
16
16
|
|
17
17
|
expect(bars.complete?).to eq(true)
|
18
18
|
end
|
19
|
+
|
20
|
+
it "finishes all bars without top level" do
|
21
|
+
bars = TTY::ProgressBar::Multi.new(output: output)
|
22
|
+
|
23
|
+
bar1 = bars.register("[:bar]", total: 5)
|
24
|
+
bar2 = bars.register("[:bar]", total: 10)
|
25
|
+
|
26
|
+
bar1.finish
|
27
|
+
bar2.finish
|
28
|
+
|
29
|
+
expect(bars.complete?).to eq(true)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "finishes top level" do
|
33
|
+
bars = TTY::ProgressBar::Multi.new(output: output)
|
34
|
+
|
35
|
+
bar1 = bars.register("[:bar]", total: 5)
|
36
|
+
bar2 = bars.register("[:bar]", total: 10)
|
37
|
+
|
38
|
+
bars.finish
|
39
|
+
|
40
|
+
expect(bar1.complete?).to eq(true)
|
41
|
+
expect(bar2.complete?).to eq(true)
|
42
|
+
end
|
19
43
|
end
|
@@ -17,6 +17,7 @@ RSpec.describe TTY::ProgressBar::Multi, '#register' do
|
|
17
17
|
it "uses global options to register instance" do
|
18
18
|
bars = TTY::ProgressBar::Multi.new(output: output, total: 100)
|
19
19
|
bar = double(:bar, attach_to: nil)
|
20
|
+
allow(bar).to receive(:on).and_return(bar)
|
20
21
|
allow(TTY::ProgressBar).to receive(:new).and_return(bar)
|
21
22
|
|
22
23
|
bars.register("[:bar]")
|
data/spec/unit/resize_spec.rb
CHANGED
@@ -12,7 +12,7 @@ RSpec.describe TTY::ProgressBar, '#resize' do
|
|
12
12
|
expect(output.read).to eq([
|
13
13
|
"\e[1G[== ]",
|
14
14
|
"\e[1G[==== ]",
|
15
|
-
"\e[0m\e[
|
15
|
+
"\e[0m\e[2K\e[1G",
|
16
16
|
"\e[1G[=== ]",
|
17
17
|
"\e[1G[==== ]",
|
18
18
|
"\e[1G[=====]\n"
|
@@ -28,7 +28,7 @@ RSpec.describe TTY::ProgressBar, '#resize' do
|
|
28
28
|
expect(output.read).to eq([
|
29
29
|
"\e[1G[== ]",
|
30
30
|
"\e[1G[==== ]",
|
31
|
-
"\e[0m\e[
|
31
|
+
"\e[0m\e[2K\e[1G",
|
32
32
|
"\e[1G[============ ]",
|
33
33
|
"\e[1G[================ ]",
|
34
34
|
"\e[1G[====================]\n"
|
data/tty-progressbar.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-progressbar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-cursor
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '2.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.1'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.1'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: rake
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|