tty-progressbar 0.15.1 → 0.18.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +63 -0
- data/LICENSE.txt +1 -1
- data/README.md +495 -125
- data/lib/tty-progressbar.rb +2 -2
- data/lib/tty/progressbar.rb +169 -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 +18 -20
- data/lib/tty/progressbar/formatter/estimated_time.rb +39 -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 +3 -1
- metadata +56 -164
- data/.codeclimate.yml +0 -11
- data/.gitignore +0 -14
- data/.rspec +0 -3
- data/.travis.yml +0 -26
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -14
- data/Rakefile +0 -8
- data/appveyor.yml +0 -23
- 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 -51
- 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/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 -30
data/spec/unit/complete_spec.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, '#complete?' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "checks for completness" do
|
5
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 3)
|
6
|
-
completes = []
|
7
|
-
3.times do
|
8
|
-
completes << progress.complete?
|
9
|
-
progress.advance
|
10
|
-
end
|
11
|
-
completes << progress.complete?
|
12
|
-
expect(completes).to eq([
|
13
|
-
false, false, false, true
|
14
|
-
])
|
15
|
-
end
|
16
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar::Converter, '#to_bytes' do
|
2
|
-
subject(:converter) { described_class }
|
3
|
-
|
4
|
-
it "converts 1000 to bytes" do
|
5
|
-
expect(converter.to_bytes(1000)).to eq('1000B')
|
6
|
-
end
|
7
|
-
|
8
|
-
it "converts 1024 to bytes" do
|
9
|
-
expect(converter.to_bytes(1024)).to eq('1.00KB')
|
10
|
-
end
|
11
|
-
|
12
|
-
it "converts 1234 to bytes" do
|
13
|
-
expect(converter.to_bytes(1234)).to eq('1.21KB')
|
14
|
-
end
|
15
|
-
|
16
|
-
it "converts 12345 to bytes" do
|
17
|
-
expect(converter.to_bytes(12345)).to eq('12.06KB')
|
18
|
-
end
|
19
|
-
|
20
|
-
it "converts 2000 to bytes" do
|
21
|
-
expect(converter.to_bytes(2000)).to eq('1.95KB')
|
22
|
-
end
|
23
|
-
|
24
|
-
it "converts 1234567 to bytes" do
|
25
|
-
expect(converter.to_bytes(1234567)).to eq('1.18MB')
|
26
|
-
end
|
27
|
-
|
28
|
-
it "converts 1234567 to bytes with :separator" do
|
29
|
-
expect(converter.to_bytes(1234567, separator: ',')).to eq('1,18MB')
|
30
|
-
end
|
31
|
-
|
32
|
-
it "converts 1234567 to bytes with :unit_separator" do
|
33
|
-
expect(converter.to_bytes(1234567, unit_separator: ' ')).to eq('1.18 MB')
|
34
|
-
end
|
35
|
-
|
36
|
-
it "converts 1234567 to bytes with comma as a separator" do
|
37
|
-
expect(converter.to_bytes(1234567, decimals: 1)).to eq('1.2MB')
|
38
|
-
end
|
39
|
-
|
40
|
-
it "converts 10_000_000 to bytes" do
|
41
|
-
expect(converter.to_bytes(10_000_000)).to eq('9.54MB')
|
42
|
-
end
|
43
|
-
|
44
|
-
it "convert 10_000_000_000 to bytes" do
|
45
|
-
expect(converter.to_bytes(10_000_000_000)).to eq('9.31GB')
|
46
|
-
end
|
47
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar::Converter, '#to_seconds' do
|
2
|
-
subject(:converter) { described_class }
|
3
|
-
|
4
|
-
it "ensure 5 digit precision for < 1" do
|
5
|
-
expect(converter.to_seconds(0.000005)).to eq("0.00001")
|
6
|
-
end
|
7
|
-
|
8
|
-
it "rounds 0 to 0.00" do
|
9
|
-
expect(converter.to_seconds(0)).to eq(" 0.00")
|
10
|
-
end
|
11
|
-
|
12
|
-
it "ensures 2 digit precision for > 1" do
|
13
|
-
expect(converter.to_seconds(11.2)).to eq("11.20")
|
14
|
-
end
|
15
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar::Converter, '#to_time' do
|
2
|
-
subject(:converter) { described_class }
|
3
|
-
|
4
|
-
it "converts seconds to seconds" do
|
5
|
-
expect(converter.to_time(15)).to eq("15s")
|
6
|
-
end
|
7
|
-
|
8
|
-
it "converts seconds to minutes" do
|
9
|
-
expect(converter.to_time(100)).to eq(" 1m40s")
|
10
|
-
end
|
11
|
-
|
12
|
-
it "converts seconds to small hours" do
|
13
|
-
expect(converter.to_time(3600)).to eq(" 1h 0m")
|
14
|
-
end
|
15
|
-
|
16
|
-
it "converts secodns to hours" do
|
17
|
-
expect(converter.to_time(100 * 3600)).to eq("100h")
|
18
|
-
end
|
19
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, 'custom formatter' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "allows for custom tag" do
|
5
|
-
progress = TTY::ProgressBar.new(":hi", output: output, total: 10)
|
6
|
-
|
7
|
-
stub_const("HiFormatter", Class.new do
|
8
|
-
def initialize(progress)
|
9
|
-
@progress = progress
|
10
|
-
end
|
11
|
-
|
12
|
-
def matches?(value)
|
13
|
-
value.to_s =~ /:hi/
|
14
|
-
end
|
15
|
-
|
16
|
-
def format(value)
|
17
|
-
value.gsub(/:hi/, "Hello")
|
18
|
-
end
|
19
|
-
end)
|
20
|
-
|
21
|
-
progress.use(HiFormatter)
|
22
|
-
progress.advance
|
23
|
-
output.rewind
|
24
|
-
expect(output.read).to eq("\e[1GHello")
|
25
|
-
end
|
26
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, 'custom token' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "allows to specify custom tokens" do
|
5
|
-
progress = TTY::ProgressBar.new("(:current) :title", output: output, total: 4)
|
6
|
-
progress.advance(title: 'Hello Piotr!')
|
7
|
-
progress.advance(3, title: 'Bye Piotr!')
|
8
|
-
output.rewind
|
9
|
-
expect(output.read).to eq([
|
10
|
-
"\e[1G(1) Hello Piotr!",
|
11
|
-
"\e[1G(4) Bye Piotr! \n"
|
12
|
-
].join)
|
13
|
-
end
|
14
|
-
end
|
data/spec/unit/events_spec.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, 'events' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "emits :progress event when advancing" do
|
5
|
-
events = []
|
6
|
-
bar = TTY::ProgressBar.new("[:bar]", output: output, total: 5)
|
7
|
-
bar.on(:progress) { events << :progress }
|
8
|
-
|
9
|
-
bar.advance
|
10
|
-
|
11
|
-
expect(events).to eq([:progress])
|
12
|
-
end
|
13
|
-
|
14
|
-
it "emits :done event when finished" do
|
15
|
-
events = []
|
16
|
-
bar = TTY::ProgressBar.new("[:bar]", output: output, total: 5)
|
17
|
-
bar.on(:done) { events << :done }
|
18
|
-
|
19
|
-
bar.finish
|
20
|
-
|
21
|
-
expect(events).to eq([:done])
|
22
|
-
end
|
23
|
-
|
24
|
-
it "emits :stopped event" do
|
25
|
-
events = []
|
26
|
-
bar = TTY::ProgressBar.new("[:bar]", output: output, total: 5)
|
27
|
-
bar.on(:stopped) { events << :stopped }
|
28
|
-
|
29
|
-
bar.stop
|
30
|
-
|
31
|
-
expect(events).to eq([:stopped])
|
32
|
-
end
|
33
|
-
end
|
data/spec/unit/finish_spec.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, '#finish' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it 'finishes progress' do
|
5
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
|
6
|
-
progress.advance
|
7
|
-
progress.finish
|
8
|
-
expect(progress.complete?).to be(true)
|
9
|
-
output.rewind
|
10
|
-
expect(output.read).to eq([
|
11
|
-
"\e[1G[= ]",
|
12
|
-
"\e[1G[==========]\n"
|
13
|
-
].join)
|
14
|
-
end
|
15
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, ':bar token' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
it "animates bar" do
|
5
|
-
progress = TTY::ProgressBar.new("[:bar]", output: output, 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
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
RSpec.describe TTY::ProgressBar, ':byte_rate token' do
|
2
|
-
let(:output) { StringIO.new('', 'w+') }
|
3
|
-
|
4
|
-
before { Timecop.safe_mode = false }
|
5
|
-
|
6
|
-
it "shows current 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(":byte_rate", 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[1G1000B",
|
27
|
-
"\e[1G1.46KB",
|
28
|
-
"\e[1G1.95KB\n"
|
29
|
-
].join)
|
30
|
-
Timecop.return
|
31
|
-
end
|
32
|
-
end
|
@@ -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
|