tty-progressbar 0.14.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +98 -21
- data/LICENSE.txt +1 -1
- data/README.md +511 -119
- data/lib/tty-progressbar.rb +2 -2
- data/lib/tty/progressbar.rb +216 -87
- data/lib/tty/progressbar/configuration.rb +124 -16
- 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 +87 -29
- 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 +69 -23
- data/lib/tty/progressbar/pipeline.rb +13 -6
- data/lib/tty/progressbar/timer.rb +89 -0
- data/lib/tty/progressbar/version.rb +3 -1
- metadata +65 -151
- data/.codeclimate.yml +0 -11
- data/.gitignore +0 -14
- data/.rspec +0 -3
- data/.travis.yml +0 -25
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -14
- data/Rakefile +0 -8
- data/appveyor.yml +0 -21
- 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/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/spec/spec_helper.rb +0 -50
- 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 -16
- 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/stop_spec.rb +0 -15
- data/spec/unit/new_spec.rb +0 -66
- data/spec/unit/pipeline_spec.rb +0 -19
- data/spec/unit/ratio_spec.rb +0 -31
- 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 -21
- data/tasks/console.rake +0 -9
- data/tasks/coverage.rake +0 -9
- data/tasks/spec.rake +0 -27
- data/tty-progressbar.gemspec +0 -30
@@ -1,41 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar::Multi, '#finish' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "finishes all bars with top level" do
|
5
|
-
bars = TTY::ProgressBar::Multi.new("main [:bar]", output: output)
|
6
|
-
|
7
|
-
bar1 = bars.register("[:bar]", total: 5)
|
8
|
-
bar2 = bars.register("[:bar]", total: 10)
|
9
|
-
|
10
|
-
expect(bars.complete?).to eq(false)
|
11
|
-
|
12
|
-
bar1.finish
|
13
|
-
bar2.finish
|
14
|
-
|
15
|
-
expect(bars.complete?).to eq(true)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "finishes all bars without top level" do
|
19
|
-
bars = TTY::ProgressBar::Multi.new(output: output)
|
20
|
-
|
21
|
-
bar1 = bars.register("[:bar]", total: 5)
|
22
|
-
bar2 = bars.register("[:bar]", total: 10)
|
23
|
-
|
24
|
-
bar1.finish
|
25
|
-
bar2.finish
|
26
|
-
|
27
|
-
expect(bars.complete?).to eq(true)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "finishes top level" do
|
31
|
-
bars = TTY::ProgressBar::Multi.new(output: output)
|
32
|
-
|
33
|
-
bar1 = bars.register("[:bar]", total: 5)
|
34
|
-
bar2 = bars.register("[:bar]", total: 10)
|
35
|
-
|
36
|
-
bars.finish
|
37
|
-
|
38
|
-
expect(bar1.complete?).to eq(true)
|
39
|
-
expect(bar2.complete?).to eq(true)
|
40
|
-
end
|
41
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar::Multi, '#line_inset' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "doesn't create inset when no top level bar" do
|
5
|
-
bars = TTY::ProgressBar::Multi.new(output: output)
|
6
|
-
|
7
|
-
bar = bars.register 'example'
|
8
|
-
|
9
|
-
expect(bars.line_inset(bar)).to eq('')
|
10
|
-
end
|
11
|
-
|
12
|
-
it "defaults to the empty string for the top level bar" do
|
13
|
-
bars = TTY::ProgressBar::Multi.new("Top level spinner", output: output)
|
14
|
-
|
15
|
-
expect(bars.line_inset(bars.top_bar))
|
16
|
-
.to eq(TTY::ProgressBar::Multi::DEFAULT_INSET[:top])
|
17
|
-
end
|
18
|
-
|
19
|
-
it "returns middle character for a top level bar" do
|
20
|
-
bars = TTY::ProgressBar::Multi.new("Top level bar", output: output)
|
21
|
-
|
22
|
-
bar = bars.register 'middle', total: 10
|
23
|
-
bar2 = bars.register 'bottom', total: 10
|
24
|
-
|
25
|
-
bar.start
|
26
|
-
bar2.start
|
27
|
-
|
28
|
-
expect(bars.line_inset(bar))
|
29
|
-
.to eq(TTY::ProgressBar::Multi::DEFAULT_INSET[:middle])
|
30
|
-
end
|
31
|
-
|
32
|
-
it "decorates last bar" do
|
33
|
-
bars = TTY::ProgressBar::Multi.new("Top spinner", output: output)
|
34
|
-
|
35
|
-
bar1 = bars.register 'middle', total: 10
|
36
|
-
bar = bars.register 'bottom', total: 10
|
37
|
-
|
38
|
-
bar1.start
|
39
|
-
bar.start
|
40
|
-
|
41
|
-
expect(bars.line_inset(bar))
|
42
|
-
.to eq(TTY::ProgressBar::Multi::DEFAULT_INSET[:bottom])
|
43
|
-
end
|
44
|
-
|
45
|
-
it "allows customization" do
|
46
|
-
opts = {
|
47
|
-
output: output,
|
48
|
-
style: {
|
49
|
-
top: ". ",
|
50
|
-
middle: "--",
|
51
|
-
bottom: "---",
|
52
|
-
}
|
53
|
-
}
|
54
|
-
bars = TTY::ProgressBar::Multi.new("Top level spinner", opts)
|
55
|
-
middle_bar = bars.register "", total: 10
|
56
|
-
bottom_bar = bars.register "", total: 10
|
57
|
-
|
58
|
-
middle_bar.start
|
59
|
-
bottom_bar.start
|
60
|
-
|
61
|
-
expect(bars.line_inset(bars.top_bar)).to eq(". ")
|
62
|
-
expect(bars.line_inset(middle_bar)).to eq("--")
|
63
|
-
expect(bars.line_inset(bottom_bar)).to eq("---")
|
64
|
-
end
|
65
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar::Multi, '#register' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "registers a TTY::ProgressBar instance" do
|
5
|
-
bars = TTY::ProgressBar::Multi.new(output: output)
|
6
|
-
allow_any_instance_of(TTY::ProgressBar).to receive(:attach_to)
|
7
|
-
expect_any_instance_of(TTY::ProgressBar).to receive(:attach_to)
|
8
|
-
|
9
|
-
bar = bars.register("[:bar]")
|
10
|
-
|
11
|
-
expect(bar).to be_instance_of(TTY::ProgressBar)
|
12
|
-
expect(bars.length).to eq(1)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "uses global options to register instance" do
|
16
|
-
bars = TTY::ProgressBar::Multi.new(output: output, total: 100)
|
17
|
-
bar = double(:bar, attach_to: nil)
|
18
|
-
allow(bar).to receive(:on).and_return(bar)
|
19
|
-
allow(TTY::ProgressBar).to receive(:new).and_return(bar)
|
20
|
-
|
21
|
-
bars.register("[:bar]")
|
22
|
-
|
23
|
-
expect(TTY::ProgressBar).to have_received(:new).with("[:bar]", {total: 100, output: output})
|
24
|
-
end
|
25
|
-
|
26
|
-
it "registers bars with top level" do
|
27
|
-
bars = TTY::ProgressBar::Multi.new("main [:bar]", output: output)
|
28
|
-
|
29
|
-
bars.register("[:bar]", total: 5)
|
30
|
-
bars.register("[:bar]", total: 10)
|
31
|
-
|
32
|
-
expect(bars.total).to eq(15)
|
33
|
-
expect(bars.current).to eq(0)
|
34
|
-
end
|
35
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar::Multi, '#stop' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "stops all bars when top level stops" do
|
5
|
-
bars = TTY::ProgressBar::Multi.new("main [:bar]", output: output)
|
6
|
-
|
7
|
-
bar1 = bars.register("[:bar]", total: 5)
|
8
|
-
bar2 = bars.register("[:bar]", total: 10)
|
9
|
-
|
10
|
-
bars.stop
|
11
|
-
|
12
|
-
expect(bar1.stopped?).to eq(true)
|
13
|
-
expect(bar2.stopped?).to eq(true)
|
14
|
-
end
|
15
|
-
end
|
data/spec/unit/new_spec.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, '::new' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "fails to initialize without formatting string" do
|
5
|
-
expect {
|
6
|
-
TTY::ProgressBar.new(output: output)
|
7
|
-
}.to raise_error(ArgumentError, /Expected bar formatting string, got `{:output=>#{output}}` instead\./)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "displays output where width == total" do
|
11
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
|
12
|
-
progress.advance
|
13
|
-
output.rewind
|
14
|
-
expect(output.read).to eq("\e[1G[= ]")
|
15
|
-
end
|
16
|
-
|
17
|
-
it "yields configuration to block" do
|
18
|
-
progress = TTY::ProgressBar.new "[:bar]" do |config|
|
19
|
-
config.output = output
|
20
|
-
config.total = 10
|
21
|
-
config.clear = true
|
22
|
-
end
|
23
|
-
expect(progress.output).to eq(output)
|
24
|
-
expect(progress.total).to eq(10)
|
25
|
-
expect(progress.width).to eq(10)
|
26
|
-
expect(progress.clear).to eq(true)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "displays output where width > total" do
|
30
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 5, width: 10)
|
31
|
-
5.times { progress.advance }
|
32
|
-
output.rewind
|
33
|
-
expect(output.read).to eq([
|
34
|
-
"\e[1G[== ]",
|
35
|
-
"\e[1G[==== ]",
|
36
|
-
"\e[1G[====== ]",
|
37
|
-
"\e[1G[======== ]",
|
38
|
-
"\e[1G[==========]\n"
|
39
|
-
].join)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "displays output where width < total" do
|
43
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10, width: 5)
|
44
|
-
10.times { progress.advance }
|
45
|
-
output.rewind
|
46
|
-
expect(output.read).to eq([
|
47
|
-
"\e[1G[= ]",
|
48
|
-
"\e[1G[= ]",
|
49
|
-
"\e[1G[== ]",
|
50
|
-
"\e[1G[== ]",
|
51
|
-
"\e[1G[=== ]",
|
52
|
-
"\e[1G[=== ]",
|
53
|
-
"\e[1G[==== ]",
|
54
|
-
"\e[1G[==== ]",
|
55
|
-
"\e[1G[=====]",
|
56
|
-
"\e[1G[=====]\n"
|
57
|
-
].join)
|
58
|
-
end
|
59
|
-
|
60
|
-
it "displays total value" do
|
61
|
-
progress = TTY::ProgressBar.new("|:total|", output: output, total: 10)
|
62
|
-
progress.advance(3)
|
63
|
-
output.rewind
|
64
|
-
expect(output.read).to eq("\e[1G|10|")
|
65
|
-
end
|
66
|
-
end
|
data/spec/unit/pipeline_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar::Pipeline, '#decorate' do
|
2
|
-
subject(:pipeline) { described_class.new }
|
3
|
-
|
4
|
-
it "decorates tokenized string with pipeline formatters" do
|
5
|
-
pipeline.use TTY::ProgressBar::CurrentFormatter
|
6
|
-
pipeline.use TTY::ProgressBar::TotalFormatter
|
7
|
-
progress_bar = double(current: '3', total: '10')
|
8
|
-
tokenized = "[:current/:total]"
|
9
|
-
expect(pipeline.decorate(progress_bar, tokenized)).to eq("[3/10]")
|
10
|
-
end
|
11
|
-
|
12
|
-
it "enumerates pipeline formatters" do
|
13
|
-
pipeline.use TTY::ProgressBar::CurrentFormatter
|
14
|
-
pipeline.use TTY::ProgressBar::TotalFormatter
|
15
|
-
yielded = []
|
16
|
-
pipeline.each { |formatter| yielded << formatter }
|
17
|
-
expect(yielded.size).to eq(2)
|
18
|
-
end
|
19
|
-
end
|
data/spec/unit/ratio_spec.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, '#ratio=' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "allows to set ratio" do
|
5
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
|
6
|
-
progress.ratio = 0.7
|
7
|
-
expect(progress.current).to eq(7)
|
8
|
-
output.rewind
|
9
|
-
expect(output.read).to eq([
|
10
|
-
"\e[1G[======= ]"
|
11
|
-
].join)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "finds closest available step from the ratio" do
|
15
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 3)
|
16
|
-
progress.ratio = 0.5
|
17
|
-
expect(progress.current).to eq(1)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "doesn't allow to set wrong ratio" do
|
21
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 3)
|
22
|
-
progress.ratio = 3.2
|
23
|
-
expect(progress.current).to eq(3)
|
24
|
-
expect(progress.complete?).to eq(true)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "avoids division by zero" do
|
28
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 0)
|
29
|
-
expect(progress.ratio).to eq(0)
|
30
|
-
end
|
31
|
-
end
|
data/spec/unit/reset_spec.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, '#reset' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "resets current progress" do
|
5
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
|
6
|
-
progress.advance(5)
|
7
|
-
progress.reset
|
8
|
-
2.times { progress.advance(3) }
|
9
|
-
output.rewind
|
10
|
-
expect(output.read).to eq([
|
11
|
-
"\e[1G[===== ]",
|
12
|
-
"\e[1G[=== ]",
|
13
|
-
"\e[1G[====== ]"
|
14
|
-
].join)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "resets finished progress" do
|
18
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
|
19
|
-
progress.advance(10)
|
20
|
-
expect(progress.complete?).to be(true)
|
21
|
-
progress.reset
|
22
|
-
expect(progress.complete?).to be(false)
|
23
|
-
2.times { progress.advance(3) }
|
24
|
-
output.rewind
|
25
|
-
expect(output.read).to eq([
|
26
|
-
"\e[1G[==========]\n",
|
27
|
-
"\e[1G[=== ]",
|
28
|
-
"\e[1G[====== ]"
|
29
|
-
].join)
|
30
|
-
end
|
31
|
-
end
|
data/spec/unit/resize_spec.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, '#resize' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "resizes output down by x2" do
|
5
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 5, width: 10)
|
6
|
-
2.times { progress.advance }
|
7
|
-
progress.resize(5)
|
8
|
-
3.times { progress.advance }
|
9
|
-
output.rewind
|
10
|
-
expect(output.read).to eq([
|
11
|
-
"\e[1G[== ]",
|
12
|
-
"\e[1G[==== ]",
|
13
|
-
"\e[0m\e[2K\e[1G",
|
14
|
-
"\e[1G[=== ]",
|
15
|
-
"\e[1G[==== ]",
|
16
|
-
"\e[1G[=====]\n"
|
17
|
-
].join)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "resizes output up by x2" do
|
21
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 5, width: 10)
|
22
|
-
2.times { progress.advance }
|
23
|
-
progress.resize(20)
|
24
|
-
3.times { progress.advance }
|
25
|
-
output.rewind
|
26
|
-
expect(output.read).to eq([
|
27
|
-
"\e[1G[== ]",
|
28
|
-
"\e[1G[==== ]",
|
29
|
-
"\e[0m\e[2K\e[1G",
|
30
|
-
"\e[1G[============ ]",
|
31
|
-
"\e[1G[================ ]",
|
32
|
-
"\e[1G[====================]\n"
|
33
|
-
].join)
|
34
|
-
end
|
35
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, '#current=' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "allows to go back" do
|
5
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
|
6
|
-
3.times { progress.advance }
|
7
|
-
progress.current = 5
|
8
|
-
expect(progress.current).to eq(5)
|
9
|
-
output.rewind
|
10
|
-
expect(output.read).to eq([
|
11
|
-
"\e[1G[= ]",
|
12
|
-
"\e[1G[== ]",
|
13
|
-
"\e[1G[=== ]",
|
14
|
-
"\e[1G[===== ]"
|
15
|
-
].join)
|
16
|
-
progress.current = 0
|
17
|
-
expect(progress.current).to eq(0)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "doesn't allow to go over total" do
|
21
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
|
22
|
-
progress.current = 12
|
23
|
-
expect(progress.current).to eq(10)
|
24
|
-
output.rewind
|
25
|
-
expect(output.read).to eq("\e[1G[==========]\n")
|
26
|
-
end
|
27
|
-
|
28
|
-
it "doesn't allow to go below 0" do
|
29
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
|
30
|
-
progress.current = -1
|
31
|
-
expect(progress.current).to eq(0)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "cannot backtrack on finished" do
|
35
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
|
36
|
-
progress.current = 10
|
37
|
-
expect(progress.current).to eq(10)
|
38
|
-
progress.current = 5
|
39
|
-
expect(progress.current).to eq(10)
|
40
|
-
output.rewind
|
41
|
-
expect(output.read).to eq("\e[1G[==========]\n")
|
42
|
-
end
|
43
|
-
end
|
data/spec/unit/start_spec.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, '#start' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "starts timer and draws initial progress" do
|
5
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
|
6
|
-
progress.start
|
7
|
-
progress.advance
|
8
|
-
output.rewind
|
9
|
-
expect(output.read).to eq([
|
10
|
-
"\e[1G[ ]",
|
11
|
-
"\e[1G[= ]"
|
12
|
-
].join)
|
13
|
-
end
|
14
|
-
end
|
data/spec/unit/stop_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, '#stop' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it 'stops progress' do
|
5
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
|
6
|
-
5.times { |i|
|
7
|
-
progress.stop if i == 3
|
8
|
-
progress.advance
|
9
|
-
}
|
10
|
-
expect(progress.complete?).to be(false)
|
11
|
-
output.rewind
|
12
|
-
expect(output.read).to eq([
|
13
|
-
"\e[1G[= ]",
|
14
|
-
"\e[1G[== ]",
|
15
|
-
"\e[1G[=== ]",
|
16
|
-
"\e[1G[=== ]\n"
|
17
|
-
].join)
|
18
|
-
end
|
19
|
-
end
|
data/spec/unit/update_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, '#update' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "updates bar configuration options" do
|
5
|
-
progress = TTY::ProgressBar.new "[:bar]" do |config|
|
6
|
-
config.output = output
|
7
|
-
config.total = 10
|
8
|
-
end
|
9
|
-
10.times { |i|
|
10
|
-
progress.update(complete: '-', head: '>') if i == 2
|
11
|
-
progress.advance(2)
|
12
|
-
}
|
13
|
-
output.rewind
|
14
|
-
expect(output.read).to eq([
|
15
|
-
"\e[1G[== ]",
|
16
|
-
"\e[1G[==== ]",
|
17
|
-
"\e[1G[-----> ]",
|
18
|
-
"\e[1G[-------> ]",
|
19
|
-
"\e[1G[--------->]\n"
|
20
|
-
].join)
|
21
|
-
end
|
22
|
-
end
|