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.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +63 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +495 -125
  5. data/lib/tty-progressbar.rb +2 -2
  6. data/lib/tty/progressbar.rb +169 -68
  7. data/lib/tty/progressbar/configuration.rb +121 -27
  8. data/lib/tty/progressbar/converter.rb +16 -19
  9. data/lib/tty/progressbar/formats.rb +120 -0
  10. data/lib/tty/progressbar/formatter.rb +33 -38
  11. data/lib/tty/progressbar/formatter/bar.rb +74 -27
  12. data/lib/tty/progressbar/formatter/byte_rate.rb +6 -20
  13. data/lib/tty/progressbar/formatter/current.rb +4 -19
  14. data/lib/tty/progressbar/formatter/current_byte.rb +9 -17
  15. data/lib/tty/progressbar/formatter/elapsed.rb +9 -18
  16. data/lib/tty/progressbar/formatter/estimated.rb +18 -20
  17. data/lib/tty/progressbar/formatter/estimated_time.rb +39 -0
  18. data/lib/tty/progressbar/formatter/mean_byte.rb +6 -20
  19. data/lib/tty/progressbar/formatter/mean_rate.rb +6 -20
  20. data/lib/tty/progressbar/formatter/percent.rb +10 -16
  21. data/lib/tty/progressbar/formatter/rate.rb +5 -19
  22. data/lib/tty/progressbar/formatter/total.rb +10 -16
  23. data/lib/tty/progressbar/formatter/total_byte.rb +14 -18
  24. data/lib/tty/progressbar/formatters.rb +53 -0
  25. data/lib/tty/progressbar/meter.rb +2 -2
  26. data/lib/tty/progressbar/multi.rb +61 -21
  27. data/lib/tty/progressbar/pipeline.rb +13 -6
  28. data/lib/tty/progressbar/timer.rb +89 -0
  29. data/lib/tty/progressbar/version.rb +3 -1
  30. metadata +56 -164
  31. data/.codeclimate.yml +0 -11
  32. data/.gitignore +0 -14
  33. data/.rspec +0 -3
  34. data/.travis.yml +0 -26
  35. data/CODE_OF_CONDUCT.md +0 -74
  36. data/Gemfile +0 -14
  37. data/Rakefile +0 -8
  38. data/appveyor.yml +0 -23
  39. data/examples/color.rb +0 -18
  40. data/examples/failure.rb +0 -12
  41. data/examples/iterator.rb +0 -5
  42. data/examples/lazy.rb +0 -6
  43. data/examples/multi/main_bar.rb +0 -13
  44. data/examples/multi/simple.rb +0 -13
  45. data/examples/multi/width.rb +0 -13
  46. data/examples/simple.rb +0 -7
  47. data/examples/slow_process.rb +0 -29
  48. data/examples/speed.rb +0 -11
  49. data/examples/threaded.rb +0 -14
  50. data/examples/tokens.rb +0 -12
  51. data/examples/unicode.rb +0 -7
  52. data/spec/spec_helper.rb +0 -51
  53. data/spec/unit/advance_spec.rb +0 -25
  54. data/spec/unit/clear_spec.rb +0 -17
  55. data/spec/unit/complete_spec.rb +0 -16
  56. data/spec/unit/converter/to_bytes_spec.rb +0 -47
  57. data/spec/unit/converter/to_seconds_spec.rb +0 -15
  58. data/spec/unit/converter/to_time_spec.rb +0 -19
  59. data/spec/unit/custom_formatter_spec.rb +0 -26
  60. data/spec/unit/custom_token_spec.rb +0 -14
  61. data/spec/unit/events_spec.rb +0 -33
  62. data/spec/unit/finish_spec.rb +0 -15
  63. data/spec/unit/formatter/bar_spec.rb +0 -16
  64. data/spec/unit/formatter/byte_rate_spec.rb +0 -32
  65. data/spec/unit/formatter/current_byte_spec.rb +0 -16
  66. data/spec/unit/formatter/current_spec.rb +0 -14
  67. data/spec/unit/formatter/elapsed_spec.rb +0 -58
  68. data/spec/unit/formatter/estimated_spec.rb +0 -27
  69. data/spec/unit/formatter/mean_byte_spec.rb +0 -32
  70. data/spec/unit/formatter/mean_rate_spec.rb +0 -31
  71. data/spec/unit/formatter/percent_spec.rb +0 -16
  72. data/spec/unit/formatter/rate_spec.rb +0 -31
  73. data/spec/unit/formatter/total_byte_spec.rb +0 -16
  74. data/spec/unit/formatter/total_spec.rb +0 -16
  75. data/spec/unit/frequency_spec.rb +0 -27
  76. data/spec/unit/head_spec.rb +0 -32
  77. data/spec/unit/hide_cursor_spec.rb +0 -27
  78. data/spec/unit/inspect_spec.rb +0 -11
  79. data/spec/unit/iterate_spec.rb +0 -79
  80. data/spec/unit/log_spec.rb +0 -29
  81. data/spec/unit/meter_spec.rb +0 -70
  82. data/spec/unit/multi/advance_spec.rb +0 -123
  83. data/spec/unit/multi/events_spec.rb +0 -115
  84. data/spec/unit/multi/finish_spec.rb +0 -41
  85. data/spec/unit/multi/line_inset_spec.rb +0 -65
  86. data/spec/unit/multi/register_spec.rb +0 -35
  87. data/spec/unit/multi/reset_spec.rb +0 -28
  88. data/spec/unit/multi/stop_spec.rb +0 -15
  89. data/spec/unit/multi/width_spec.rb +0 -118
  90. data/spec/unit/new_spec.rb +0 -76
  91. data/spec/unit/pipeline_spec.rb +0 -19
  92. data/spec/unit/ratio_spec.rb +0 -31
  93. data/spec/unit/render_spec.rb +0 -25
  94. data/spec/unit/reset_spec.rb +0 -31
  95. data/spec/unit/resize_spec.rb +0 -35
  96. data/spec/unit/set_current_spec.rb +0 -43
  97. data/spec/unit/start_spec.rb +0 -14
  98. data/spec/unit/stop_spec.rb +0 -19
  99. data/spec/unit/update_spec.rb +0 -22
  100. data/spec/unit/width_spec.rb +0 -86
  101. data/tasks/console.rake +0 -9
  102. data/tasks/coverage.rake +0 -9
  103. data/tasks/spec.rake +0 -27
  104. data/tty-progressbar.gemspec +0 -30
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -1,29 +0,0 @@
1
- RSpec.describe TTY::ProgressBar, '#log' do
2
- let(:output) { StringIO.new('', 'w+') }
3
-
4
- it "logs message" do
5
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
6
- 2.times {
7
- progress.log 'foo bar'
8
- progress.advance
9
- }
10
- output.rewind
11
- expect(output.read).to eq([
12
- "\e[1Gfoo bar\n",
13
- "\e[1G[ ]",
14
- "\e[1G[= ]",
15
- "\e[1Gfoo bar \n",
16
- "\e[1G[= ]",
17
- "\e[1G[== ]",
18
- ].join)
19
- end
20
-
21
- it "logs message under when complete" do
22
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
23
- progress.advance(10)
24
- expect(progress.complete?).to eq(true)
25
- progress.log 'foo bar'
26
- output.rewind
27
- expect(output.read).to eq("\e[1G[==========]\nfoo bar\n")
28
- end
29
- end
@@ -1,70 +0,0 @@
1
- RSpec.describe TTY::ProgressBar::Meter, '#rate' do
2
-
3
- before { Timecop.safe_mode = false }
4
-
5
- after { Timecop.return }
6
-
7
- it "measures with no samples" do
8
- meter = TTY::ProgressBar::Meter.new(1)
9
-
10
- meter.start
11
-
12
- expect(meter.rate).to eq(0)
13
- expect(meter.mean_rate).to eq(0)
14
- end
15
-
16
- it "measures with a single sample" do
17
- meter = TTY::ProgressBar::Meter.new(1)
18
- start_time = Time.at(10, 0)
19
- Timecop.freeze(start_time)
20
- meter.start
21
-
22
- meter.sample(Time.at(10, 100_000), 10)
23
-
24
- expect(meter.rate).to eq(100)
25
- expect(meter.mean_rate).to eq(100)
26
- end
27
-
28
- it "measures rate per second" do
29
- meter = TTY::ProgressBar::Meter.new(1)
30
- start_time = Time.at(10, 0)
31
- Timecop.freeze(start_time)
32
- meter.start
33
-
34
- # First sample batch
35
- meter.sample Time.at(10, 100_000), 5
36
- expect(meter.rate).to eq(50)
37
- expect(meter.mean_rate).to eq(50)
38
-
39
- meter.sample Time.at(10, 500_000), 5
40
- expect(meter.rate).to eq(20)
41
- expect(meter.mean_rate).to eq(20)
42
-
43
- meter.sample Time.at(11, 000_000), 5
44
- expect(meter.rate).to eq(15)
45
- expect(meter.mean_rate).to eq(15)
46
-
47
- meter.sample Time.at(11, 500_000), 5
48
- expect(meter.rate).to eq(10)
49
- expect(meter.mean_rate).to be_within(0.001).of(13.333)
50
-
51
- meter.sample Time.at(12, 000_000), 10
52
- expect(meter.rate).to eq(15)
53
- expect(meter.mean_rate).to eq(15)
54
- end
55
-
56
- it "clears measurements" do
57
- meter = TTY::ProgressBar::Meter.new(1)
58
- start_time = Time.at(10, 0)
59
- Timecop.freeze(start_time)
60
- meter.start
61
-
62
- meter.sample(start_time + 1, 1000)
63
- expect(meter.rates).to eq([1000, 1000])
64
- expect(meter.rate).to eq(1000)
65
-
66
- meter.clear
67
- expect(meter.rates).to eq([0])
68
- expect(meter.rate).to eq(0)
69
- end
70
- end
@@ -1,123 +0,0 @@
1
- RSpec.describe TTY::ProgressBar::Multi, 'advance' do
2
- let(:output) { StringIO.new('', 'w+') }
3
- let(:save) { TTY::Cursor.save }
4
- let(:restore) { TTY::Cursor.restore }
5
- let(:top) { TTY::ProgressBar::Multi::DEFAULT_INSET[:top] }
6
- let(:middle) { TTY::ProgressBar::Multi::DEFAULT_INSET[:middle] }
7
- let(:bottom) { TTY::ProgressBar::Multi::DEFAULT_INSET[:bottom] }
8
-
9
- it "advances progress bars correctly under multibar" do
10
- bars = TTY::ProgressBar::Multi.new(output: output)
11
-
12
- bar1 = bars.register("[:bar] one", total: 5)
13
- bar2 = bars.register("[:bar] two", total: 5)
14
-
15
- bar2.advance
16
- bar1.advance
17
-
18
- output.rewind
19
- expect(output.read).to eq([
20
- "\e[1G[= ] two\n",
21
- "\e[1G[= ] one\n"
22
- ].join)
23
-
24
- bar2.advance
25
-
26
- output.rewind
27
- expect(output.read).to eq([
28
- "\e[1G[= ] two\n",
29
- "\e[1G[= ] one\n",
30
- save,
31
- "\e[2A", # up 2 lines
32
- "\e[1G[== ] two",
33
- restore
34
- ].join)
35
-
36
- bar1.advance
37
-
38
- output.rewind
39
- expect(output.read).to eq([
40
- "\e[1G[= ] two\n",
41
- "\e[1G[= ] one\n",
42
- save,
43
- "\e[2A", # up 2 lines
44
- "\e[1G[== ] two",
45
- restore,
46
- save,
47
- "\e[1A", # up 1 line
48
- "\e[1G[== ] one",
49
- restore
50
- ].join)
51
- end
52
-
53
- it "advances progress bars correctly under top level multibar" do
54
- bars = TTY::ProgressBar::Multi.new("[:bar] main", output: output)
55
-
56
- bar1 = bars.register("[:bar] one", total: 5)
57
- bar2 = bars.register("[:bar] two", total: 5)
58
-
59
- bar2.advance
60
- bar1.advance
61
-
62
- output.rewind
63
- expect(output.read).to eq([
64
- "\e[1G#{top}[= ] main\n",
65
- "\e[1G#{bottom}[= ] two\n",
66
- save,
67
- "\e[2A", # up 2 lines
68
- "\e[1G#{top}[== ] main",
69
- restore,
70
- "\e[1G#{bottom}[= ] one\n"
71
- ].join)
72
-
73
- bar2.advance
74
-
75
- output.rewind
76
- expect(output.read).to eq([
77
- "\e[1G#{top}[= ] main\n",
78
- "\e[1G#{bottom}[= ] two\n",
79
- save,
80
- "\e[2A", # up 2 lines
81
- "\e[1G#{top}[== ] main",
82
- restore,
83
- "\e[1G#{bottom}[= ] one\n",
84
- save,
85
- "\e[3A", # up 3 lines
86
- "\e[1G#{top}[=== ] main",
87
- restore,
88
- save,
89
- "\e[2A", # up 2 lines,
90
- "\e[1G#{middle}[== ] two",
91
- restore,
92
- ].join)
93
-
94
- bar1.advance
95
-
96
- output.rewind
97
- expect(output.read).to eq([
98
- "\e[1G#{top}[= ] main\n",
99
- "\e[1G#{bottom}[= ] two\n",
100
- save,
101
- "\e[2A", # up 2 lines
102
- "\e[1G#{top}[== ] main",
103
- restore,
104
- "\e[1G#{bottom}[= ] one\n",
105
- save,
106
- "\e[3A", # up 3 lines
107
- "\e[1G#{top}[=== ] main",
108
- restore,
109
- save,
110
- "\e[2A", # up 2 lines,
111
- "\e[1G#{middle}[== ] two",
112
- restore,
113
- save,
114
- "\e[3A", # up 3 lines
115
- "\e[1G#{top}[==== ] main",
116
- restore,
117
- save,
118
- "\e[1A", # up 1 line
119
- "\e[1G#{bottom}[== ] one",
120
- restore
121
- ].join)
122
- end
123
- end