tty-progressbar 0.17.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -0
- data/LICENSE.txt +1 -1
- data/README.md +492 -126
- data/lib/tty-progressbar.rb +2 -2
- data/lib/tty/progressbar.rb +168 -68
- data/lib/tty/progressbar/configuration.rb +121 -27
- data/lib/tty/progressbar/converter.rb +16 -19
- data/lib/tty/progressbar/formats.rb +120 -0
- data/lib/tty/progressbar/formatter.rb +33 -38
- data/lib/tty/progressbar/formatter/bar.rb +74 -27
- data/lib/tty/progressbar/formatter/byte_rate.rb +6 -20
- data/lib/tty/progressbar/formatter/current.rb +4 -19
- data/lib/tty/progressbar/formatter/current_byte.rb +9 -17
- data/lib/tty/progressbar/formatter/elapsed.rb +9 -18
- data/lib/tty/progressbar/formatter/estimated.rb +14 -18
- data/lib/tty/progressbar/formatter/estimated_time.rb +37 -0
- data/lib/tty/progressbar/formatter/mean_byte.rb +6 -20
- data/lib/tty/progressbar/formatter/mean_rate.rb +6 -20
- data/lib/tty/progressbar/formatter/percent.rb +10 -16
- data/lib/tty/progressbar/formatter/rate.rb +5 -19
- data/lib/tty/progressbar/formatter/total.rb +10 -16
- data/lib/tty/progressbar/formatter/total_byte.rb +14 -18
- data/lib/tty/progressbar/formatters.rb +53 -0
- data/lib/tty/progressbar/meter.rb +2 -2
- data/lib/tty/progressbar/multi.rb +61 -21
- data/lib/tty/progressbar/pipeline.rb +13 -6
- data/lib/tty/progressbar/timer.rb +89 -0
- data/lib/tty/progressbar/version.rb +1 -1
- metadata +44 -103
- data/Rakefile +0 -8
- data/examples/color.rb +0 -18
- data/examples/failure.rb +0 -12
- data/examples/iterator.rb +0 -5
- data/examples/lazy.rb +0 -6
- data/examples/multi/main_bar.rb +0 -13
- data/examples/multi/simple.rb +0 -13
- data/examples/multi/width.rb +0 -13
- data/examples/simple.rb +0 -7
- data/examples/slow_process.rb +0 -29
- data/examples/speed.rb +0 -11
- data/examples/threaded.rb +0 -14
- data/examples/tokens.rb +0 -12
- data/examples/unicode.rb +0 -7
- data/spec/spec_helper.rb +0 -53
- data/spec/unit/advance_spec.rb +0 -25
- data/spec/unit/clear_spec.rb +0 -17
- data/spec/unit/complete_spec.rb +0 -16
- data/spec/unit/converter/to_bytes_spec.rb +0 -47
- data/spec/unit/converter/to_seconds_spec.rb +0 -15
- data/spec/unit/converter/to_time_spec.rb +0 -19
- data/spec/unit/custom_formatter_spec.rb +0 -26
- data/spec/unit/custom_token_spec.rb +0 -14
- data/spec/unit/events_spec.rb +0 -33
- data/spec/unit/finish_spec.rb +0 -15
- data/spec/unit/formatter/bar_spec.rb +0 -33
- data/spec/unit/formatter/byte_rate_spec.rb +0 -32
- data/spec/unit/formatter/current_byte_spec.rb +0 -16
- data/spec/unit/formatter/current_spec.rb +0 -14
- data/spec/unit/formatter/elapsed_spec.rb +0 -58
- data/spec/unit/formatter/estimated_spec.rb +0 -27
- data/spec/unit/formatter/mean_byte_spec.rb +0 -32
- data/spec/unit/formatter/mean_rate_spec.rb +0 -31
- data/spec/unit/formatter/percent_spec.rb +0 -16
- data/spec/unit/formatter/rate_spec.rb +0 -31
- data/spec/unit/formatter/total_byte_spec.rb +0 -16
- data/spec/unit/formatter/total_spec.rb +0 -16
- data/spec/unit/frequency_spec.rb +0 -27
- data/spec/unit/head_spec.rb +0 -32
- data/spec/unit/hide_cursor_spec.rb +0 -27
- data/spec/unit/inspect_spec.rb +0 -11
- data/spec/unit/iterate_spec.rb +0 -79
- data/spec/unit/log_spec.rb +0 -29
- data/spec/unit/meter_spec.rb +0 -70
- data/spec/unit/multi/advance_spec.rb +0 -123
- data/spec/unit/multi/events_spec.rb +0 -115
- data/spec/unit/multi/finish_spec.rb +0 -41
- data/spec/unit/multi/line_inset_spec.rb +0 -65
- data/spec/unit/multi/register_spec.rb +0 -35
- data/spec/unit/multi/reset_spec.rb +0 -28
- data/spec/unit/multi/stop_spec.rb +0 -15
- data/spec/unit/multi/width_spec.rb +0 -118
- data/spec/unit/new_spec.rb +0 -76
- data/spec/unit/pipeline_spec.rb +0 -19
- data/spec/unit/ratio_spec.rb +0 -31
- data/spec/unit/render_spec.rb +0 -25
- data/spec/unit/reset_spec.rb +0 -31
- data/spec/unit/resize_spec.rb +0 -35
- data/spec/unit/set_current_spec.rb +0 -43
- data/spec/unit/start_spec.rb +0 -14
- data/spec/unit/stop_spec.rb +0 -19
- data/spec/unit/update_spec.rb +0 -22
- data/spec/unit/width_spec.rb +0 -86
- data/tasks/console.rake +0 -9
- data/tasks/coverage.rake +0 -9
- data/tasks/spec.rake +0 -27
- data/tty-progressbar.gemspec +0 -32
@@ -1,16 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, ':current_byte token' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "displays bytes processed" do
|
5
|
-
progress = described_class.new(":current_byte", output: output, total: 102_400)
|
6
|
-
5.times { progress.advance(20_480) }
|
7
|
-
output.rewind
|
8
|
-
expect(output.read).to eq([
|
9
|
-
"\e[1G20.00KB",
|
10
|
-
"\e[1G40.00KB",
|
11
|
-
"\e[1G60.00KB",
|
12
|
-
"\e[1G80.00KB",
|
13
|
-
"\e[1G100.00KB\n"
|
14
|
-
].join)
|
15
|
-
end
|
16
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, ':current token' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "displays current value" do
|
5
|
-
progress = TTY::ProgressBar.new("|:current|", output: output, total: 10)
|
6
|
-
3.times { progress.advance }
|
7
|
-
output.rewind
|
8
|
-
expect(output.read).to eq([
|
9
|
-
"\e[1G|1|",
|
10
|
-
"\e[1G|2|",
|
11
|
-
"\e[1G|3|"
|
12
|
-
].join)
|
13
|
-
end
|
14
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, ':elapsed token' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
before { Timecop.safe_mode = false }
|
5
|
-
|
6
|
-
it "displays elapsed time" do
|
7
|
-
time_now = Time.local(2014, 10, 5, 12, 0, 0)
|
8
|
-
Timecop.freeze(time_now)
|
9
|
-
progress = TTY::ProgressBar.new(":elapsed", output: output, total: 10)
|
10
|
-
|
11
|
-
5.times do |sec|
|
12
|
-
time_now = Time.local(2014, 10, 5, 12, 0, sec)
|
13
|
-
Timecop.freeze(time_now)
|
14
|
-
progress.advance
|
15
|
-
end
|
16
|
-
|
17
|
-
output.rewind
|
18
|
-
expect(output.read).to eq([
|
19
|
-
"\e[1G 0s",
|
20
|
-
"\e[1G 1s",
|
21
|
-
"\e[1G 2s",
|
22
|
-
"\e[1G 3s",
|
23
|
-
"\e[1G 4s"
|
24
|
-
].join)
|
25
|
-
Timecop.return
|
26
|
-
end
|
27
|
-
|
28
|
-
it "resets elapsed time" do
|
29
|
-
time_now = Time.local(2014, 10, 5, 12, 0, 0)
|
30
|
-
Timecop.freeze(time_now)
|
31
|
-
progress = TTY::ProgressBar.new(":elapsed", output: output, total: 5)
|
32
|
-
|
33
|
-
5.times do |sec|
|
34
|
-
time_now = Time.local(2014, 10, 5, 12, 0, sec)
|
35
|
-
Timecop.freeze(time_now)
|
36
|
-
progress.advance
|
37
|
-
end
|
38
|
-
expect(progress.complete?).to be(true)
|
39
|
-
progress.reset
|
40
|
-
2.times do |sec|
|
41
|
-
time_now = Time.local(2014, 10, 5, 13, 0, sec)
|
42
|
-
Timecop.freeze(time_now)
|
43
|
-
progress.advance
|
44
|
-
end
|
45
|
-
|
46
|
-
output.rewind
|
47
|
-
expect(output.read).to eq([
|
48
|
-
"\e[1G 0s",
|
49
|
-
"\e[1G 1s",
|
50
|
-
"\e[1G 2s",
|
51
|
-
"\e[1G 3s",
|
52
|
-
"\e[1G 4s\n",
|
53
|
-
"\e[1G 0s",
|
54
|
-
"\e[1G 1s"
|
55
|
-
].join)
|
56
|
-
Timecop.return
|
57
|
-
end
|
58
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, ':eta token' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
before { Timecop.safe_mode = false }
|
5
|
-
|
6
|
-
it "displays elapsed time" do
|
7
|
-
time_now = Time.local(2014, 10, 5, 12, 0, 0)
|
8
|
-
Timecop.freeze(time_now)
|
9
|
-
progress = TTY::ProgressBar.new(":eta", output: output, total: 5)
|
10
|
-
|
11
|
-
5.times do |sec|
|
12
|
-
time_now = Time.local(2014, 10, 5, 12, 0, sec)
|
13
|
-
Timecop.freeze(time_now)
|
14
|
-
progress.advance
|
15
|
-
end
|
16
|
-
|
17
|
-
output.rewind
|
18
|
-
expect(output.read).to eq([
|
19
|
-
"\e[1G 0s",
|
20
|
-
"\e[1G 1s",
|
21
|
-
"\e[1G 1s",
|
22
|
-
"\e[1G 0s",
|
23
|
-
"\e[1G 0s\n"
|
24
|
-
].join)
|
25
|
-
Timecop.return
|
26
|
-
end
|
27
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, ':mean_byte token' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
before { Timecop.safe_mode = false }
|
5
|
-
|
6
|
-
it "shows mean rate in bytes per sec" do
|
7
|
-
time_now = Time.local(2014, 10, 5, 12, 0, 0)
|
8
|
-
Timecop.freeze(time_now)
|
9
|
-
progress = TTY::ProgressBar.new(":mean_byte", output: output, total: 10000, interval: 1)
|
10
|
-
# Generate a serie of advances at 2s intervals
|
11
|
-
# t+0 advance=0 total=0
|
12
|
-
# t+2 advance=1000 total=1000
|
13
|
-
# t+4 advance=2000 total=3000
|
14
|
-
# t+6 advance=3000 total=6000
|
15
|
-
# t+8 advance=4000 total=10_000
|
16
|
-
# NOTE: mean_byte uses 1024 for the scale in K, M ...
|
17
|
-
5.times do |i|
|
18
|
-
time_now = Time.local(2014, 10, 5, 12, 0, i * 2)
|
19
|
-
Timecop.freeze(time_now)
|
20
|
-
progress.advance(i * 1000)
|
21
|
-
end
|
22
|
-
output.rewind
|
23
|
-
expect(output.read).to eq([
|
24
|
-
"\e[1G0B",
|
25
|
-
"\e[1G500B",
|
26
|
-
"\e[1G750B",
|
27
|
-
"\e[1G1000B",
|
28
|
-
"\e[1G1.22KB\n"
|
29
|
-
].join)
|
30
|
-
Timecop.return
|
31
|
-
end
|
32
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, ':mean_rate token' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
before { Timecop.safe_mode = false }
|
5
|
-
|
6
|
-
it "shows current rate per sec" do
|
7
|
-
time_now = Time.local(2014, 10, 5, 12, 0, 0)
|
8
|
-
Timecop.freeze(time_now)
|
9
|
-
progress = TTY::ProgressBar.new(":mean_rate", output: output, total: 100, interval: 1)
|
10
|
-
# Generate a serie of advances at 2s intervals
|
11
|
-
# t+0 advance=0 total=0
|
12
|
-
# t+2 advance=10 total=10
|
13
|
-
# t+4 advance=20 total=30
|
14
|
-
# t+6 advance=30 total=60
|
15
|
-
# t+8 advance=40 total=100
|
16
|
-
5.times do |i|
|
17
|
-
time_now = Time.local(2014, 10, 5, 12, 0, i * 2)
|
18
|
-
Timecop.freeze(time_now)
|
19
|
-
progress.advance(i * 10)
|
20
|
-
end
|
21
|
-
output.rewind
|
22
|
-
expect(output.read).to eq([
|
23
|
-
"\e[1G 0.00",
|
24
|
-
"\e[1G 5.00",
|
25
|
-
"\e[1G 7.50",
|
26
|
-
"\e[1G10.00",
|
27
|
-
"\e[1G12.50\n"
|
28
|
-
].join)
|
29
|
-
Timecop.return
|
30
|
-
end
|
31
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, ':percent token' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "displays percent finished" do
|
5
|
-
progress = TTY::ProgressBar.new(":percent", output: output, total: 5)
|
6
|
-
5.times { progress.advance }
|
7
|
-
output.rewind
|
8
|
-
expect(output.read).to eq([
|
9
|
-
"\e[1G20%",
|
10
|
-
"\e[1G40%",
|
11
|
-
"\e[1G60%",
|
12
|
-
"\e[1G80%",
|
13
|
-
"\e[1G100%\n"
|
14
|
-
].join)
|
15
|
-
end
|
16
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, ':rate token' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
before { Timecop.safe_mode = false }
|
5
|
-
|
6
|
-
it "shows current rate per sec" do
|
7
|
-
time_now = Time.local(2014, 10, 5, 12, 0, 0)
|
8
|
-
Timecop.freeze(time_now)
|
9
|
-
progress = TTY::ProgressBar.new(":rate", output: output, total: 100, interval: 1)
|
10
|
-
# Generate a serie of advances at 2s intervals
|
11
|
-
# t+0 advance=0 total=0
|
12
|
-
# t+2 advance=10 total=10
|
13
|
-
# t+4 advance=20 total=30
|
14
|
-
# t+6 advance=30 total=60
|
15
|
-
# t+8 advance=40 total=100
|
16
|
-
5.times do |i|
|
17
|
-
time_now = Time.local(2014, 10, 5, 12, 0, i * 2)
|
18
|
-
Timecop.freeze(time_now)
|
19
|
-
progress.advance(i * 10)
|
20
|
-
end
|
21
|
-
output.rewind
|
22
|
-
expect(output.read).to eq([
|
23
|
-
"\e[1G 0.00",
|
24
|
-
"\e[1G 5.00",
|
25
|
-
"\e[1G10.00",
|
26
|
-
"\e[1G15.00",
|
27
|
-
"\e[1G20.00\n"
|
28
|
-
].join)
|
29
|
-
Timecop.return
|
30
|
-
end
|
31
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, ':total_byte token' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "displays bytes total" do
|
5
|
-
progress = described_class.new(":total_byte", output: output, total: 102_400)
|
6
|
-
5.times { progress.advance(20_480) }
|
7
|
-
output.rewind
|
8
|
-
expect(output.read).to eq([
|
9
|
-
"\e[1G100.00KB",
|
10
|
-
"\e[1G100.00KB",
|
11
|
-
"\e[1G100.00KB",
|
12
|
-
"\e[1G100.00KB",
|
13
|
-
"\e[1G100.00KB\n"
|
14
|
-
].join)
|
15
|
-
end
|
16
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, ':total token' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "displays bytes total" do
|
5
|
-
progress = described_class.new(":total", output: output, total: 102_400)
|
6
|
-
5.times { progress.advance(20_480) }
|
7
|
-
output.rewind
|
8
|
-
expect(output.read).to eq([
|
9
|
-
"\e[1G102400",
|
10
|
-
"\e[1G102400",
|
11
|
-
"\e[1G102400",
|
12
|
-
"\e[1G102400",
|
13
|
-
"\e[1G102400\n"
|
14
|
-
].join)
|
15
|
-
end
|
16
|
-
end
|
data/spec/unit/frequency_spec.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, 'frequency' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
before { Timecop.safe_mode = false }
|
5
|
-
|
6
|
-
it "limits frequency to 500Hz, permiting every second one" do
|
7
|
-
time_now = Time.local(2014, 10, 5, 12, 0, 0, 0)
|
8
|
-
Timecop.freeze(time_now)
|
9
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10, frequency: 500)
|
10
|
-
|
11
|
-
10.times do |sec|
|
12
|
-
time_now = Time.local(2014, 10, 5, 12, 0, 0, sec * 1000)
|
13
|
-
Timecop.freeze(time_now)
|
14
|
-
progress.advance
|
15
|
-
end
|
16
|
-
|
17
|
-
output.rewind
|
18
|
-
expect(output.read).to eq([
|
19
|
-
"\e[1G[=== ]",
|
20
|
-
"\e[1G[===== ]",
|
21
|
-
"\e[1G[======= ]",
|
22
|
-
"\e[1G[========= ]",
|
23
|
-
"\e[1G[==========]\n"
|
24
|
-
].join)
|
25
|
-
Timecop.return
|
26
|
-
end
|
27
|
-
end
|
data/spec/unit/head_spec.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, ':head' do
|
2
|
-
let(:output) { StringIO.new('', 'w+')}
|
3
|
-
|
4
|
-
it "animates head" do
|
5
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, head: '>', total: 5)
|
6
|
-
5.times { progress.advance }
|
7
|
-
output.rewind
|
8
|
-
expect(output.read).to eq([
|
9
|
-
"\e[1G[> ]",
|
10
|
-
"\e[1G[=> ]",
|
11
|
-
"\e[1G[==> ]",
|
12
|
-
"\e[1G[===> ]",
|
13
|
-
"\e[1G[====>]\n"
|
14
|
-
].join)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "customises all output characters" do
|
18
|
-
progress = TTY::ProgressBar.new("[:bar]",
|
19
|
-
output: output,
|
20
|
-
head: 'ᗧ',
|
21
|
-
complete: '-', incomplete: '.', total: 5)
|
22
|
-
5.times { progress.advance }
|
23
|
-
output.rewind
|
24
|
-
expect(output.read).to eq([
|
25
|
-
"\e[1G[ᗧ....]",
|
26
|
-
"\e[1G[-ᗧ...]",
|
27
|
-
"\e[1G[--ᗧ..]",
|
28
|
-
"\e[1G[---ᗧ.]",
|
29
|
-
"\e[1G[----ᗧ]\n"
|
30
|
-
].join)
|
31
|
-
end
|
32
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, '#hide_cursor' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "hides cursor" do
|
5
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output,
|
6
|
-
total: 5, hide_cursor: true)
|
7
|
-
5.times { progress.advance }
|
8
|
-
output.rewind
|
9
|
-
expect(output.read).to eq([
|
10
|
-
"\e[?25l\e[1G[= ]",
|
11
|
-
"\e[1G[== ]",
|
12
|
-
"\e[1G[=== ]",
|
13
|
-
"\e[1G[==== ]",
|
14
|
-
"\e[1G[=====]\n\e[?25h"
|
15
|
-
].join)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "reenables cursor on finish" do
|
19
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output,
|
20
|
-
total: 5, hide_cursor: true)
|
21
|
-
|
22
|
-
progress.advance(6)
|
23
|
-
expect(progress.complete?).to eq(true)
|
24
|
-
output.rewind
|
25
|
-
expect(output.read).to eq("\e[1G[=====]\n\e[?25h")
|
26
|
-
end
|
27
|
-
end
|
data/spec/unit/inspect_spec.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, '#inspect' do
|
2
|
-
it "inspects bar properties" do
|
3
|
-
bar = described_class.new("downloading [:bar] :total", total: 30)
|
4
|
-
expect(bar.inspect).to eq(%q{#<TTY::ProgressBar @format="downloading [:bar] :total", @current="0", @total="30", @width="30", @complete="=", @head="=", @incomplete=" ", @interval="1">})
|
5
|
-
end
|
6
|
-
|
7
|
-
it "prints string format" do
|
8
|
-
bar = described_class.new("downloading [:bar] :total", total: 30)
|
9
|
-
expect(bar.to_s).to eq("downloading [:bar] :total")
|
10
|
-
end
|
11
|
-
end
|
data/spec/unit/iterate_spec.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, '#iterate' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "iterates over a collection and yields" do
|
5
|
-
bar = TTY::ProgressBar.new("[:bar]", output: output)
|
6
|
-
values = []
|
7
|
-
bar.iterate(5.times) { |val| values << val}
|
8
|
-
|
9
|
-
expect(bar.complete?).to eq(true)
|
10
|
-
output.rewind
|
11
|
-
expect(output.read).to eq([
|
12
|
-
"\e[1G[= ]",
|
13
|
-
"\e[1G[== ]",
|
14
|
-
"\e[1G[=== ]",
|
15
|
-
"\e[1G[==== ]",
|
16
|
-
"\e[1G[=====]\n"
|
17
|
-
].join)
|
18
|
-
expect(values).to eq([0, 1, 2, 3, 4])
|
19
|
-
end
|
20
|
-
|
21
|
-
it "iterates over a collection with a step" do
|
22
|
-
bar = TTY::ProgressBar.new("[:bar]", output: output)
|
23
|
-
values = []
|
24
|
-
bar.iterate(4.times, 5) { |val| values << val }
|
25
|
-
|
26
|
-
expect(bar.complete?).to eq(true)
|
27
|
-
output.rewind
|
28
|
-
expect(output.read).to eq([
|
29
|
-
"\e[1G[===== ]",
|
30
|
-
"\e[1G[========== ]",
|
31
|
-
"\e[1G[=============== ]",
|
32
|
-
"\e[1G[====================]\n"
|
33
|
-
].join)
|
34
|
-
expect(values).to eq([0, 1, 2, 3])
|
35
|
-
end
|
36
|
-
|
37
|
-
it "iterates over a collection and returns enumerable" do
|
38
|
-
bar = TTY::ProgressBar.new("[:bar]", output: output)
|
39
|
-
values = []
|
40
|
-
progress = bar.iterate(5.times)
|
41
|
-
|
42
|
-
expect(bar.complete?).to eq(false)
|
43
|
-
|
44
|
-
progress.each { |v| values << v }
|
45
|
-
|
46
|
-
expect(values).to eq([0,1,2,3,4])
|
47
|
-
end
|
48
|
-
|
49
|
-
it "does not uses collection's count if total is provided" do
|
50
|
-
bar = TTY::ProgressBar.new("[:bar]", output: output, total: 5)
|
51
|
-
iterable = 5.times
|
52
|
-
expect(iterable).not_to receive(:count)
|
53
|
-
progress = bar.iterate(iterable)
|
54
|
-
values = []
|
55
|
-
|
56
|
-
progress.each { |v| values << v }
|
57
|
-
|
58
|
-
expect(values).to eq([0,1,2,3,4])
|
59
|
-
end
|
60
|
-
|
61
|
-
it "iterates over an infinite enumerator and renders bar correctly" do
|
62
|
-
bar = TTY::ProgressBar.new("[:bar]", output: output, total: 5)
|
63
|
-
infinite_iter = (1..Float::INFINITY).lazy
|
64
|
-
|
65
|
-
progress = bar.iterate(infinite_iter)
|
66
|
-
|
67
|
-
10.times { progress.next }
|
68
|
-
|
69
|
-
expect(bar.complete?).to eq(true)
|
70
|
-
output.rewind
|
71
|
-
expect(output.read).to eq([
|
72
|
-
"\e[1G[= ]",
|
73
|
-
"\e[1G[== ]",
|
74
|
-
"\e[1G[=== ]",
|
75
|
-
"\e[1G[==== ]",
|
76
|
-
"\e[1G[=====]\n"
|
77
|
-
].join)
|
78
|
-
end
|
79
|
-
end
|