tty-progressbar 0.14.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +98 -21
  3. data/LICENSE.txt +1 -1
  4. data/README.md +511 -119
  5. data/lib/tty-progressbar.rb +2 -2
  6. data/lib/tty/progressbar.rb +216 -87
  7. data/lib/tty/progressbar/configuration.rb +124 -16
  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 +87 -29
  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 +14 -18
  17. data/lib/tty/progressbar/formatter/estimated_time.rb +37 -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 +69 -23
  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 +65 -151
  31. data/.codeclimate.yml +0 -11
  32. data/.gitignore +0 -14
  33. data/.rspec +0 -3
  34. data/.travis.yml +0 -25
  35. data/CODE_OF_CONDUCT.md +0 -74
  36. data/Gemfile +0 -14
  37. data/Rakefile +0 -8
  38. data/appveyor.yml +0 -21
  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/simple.rb +0 -7
  46. data/examples/slow_process.rb +0 -29
  47. data/examples/speed.rb +0 -11
  48. data/examples/threaded.rb +0 -14
  49. data/examples/tokens.rb +0 -12
  50. data/spec/spec_helper.rb +0 -50
  51. data/spec/unit/advance_spec.rb +0 -25
  52. data/spec/unit/clear_spec.rb +0 -17
  53. data/spec/unit/complete_spec.rb +0 -16
  54. data/spec/unit/converter/to_bytes_spec.rb +0 -47
  55. data/spec/unit/converter/to_seconds_spec.rb +0 -15
  56. data/spec/unit/converter/to_time_spec.rb +0 -19
  57. data/spec/unit/custom_formatter_spec.rb +0 -26
  58. data/spec/unit/custom_token_spec.rb +0 -14
  59. data/spec/unit/events_spec.rb +0 -33
  60. data/spec/unit/finish_spec.rb +0 -15
  61. data/spec/unit/formatter/bar_spec.rb +0 -16
  62. data/spec/unit/formatter/byte_rate_spec.rb +0 -32
  63. data/spec/unit/formatter/current_byte_spec.rb +0 -16
  64. data/spec/unit/formatter/current_spec.rb +0 -14
  65. data/spec/unit/formatter/elapsed_spec.rb +0 -58
  66. data/spec/unit/formatter/estimated_spec.rb +0 -27
  67. data/spec/unit/formatter/mean_byte_spec.rb +0 -32
  68. data/spec/unit/formatter/mean_rate_spec.rb +0 -31
  69. data/spec/unit/formatter/percent_spec.rb +0 -16
  70. data/spec/unit/formatter/rate_spec.rb +0 -31
  71. data/spec/unit/formatter/total_byte_spec.rb +0 -16
  72. data/spec/unit/formatter/total_spec.rb +0 -16
  73. data/spec/unit/frequency_spec.rb +0 -27
  74. data/spec/unit/head_spec.rb +0 -32
  75. data/spec/unit/hide_cursor_spec.rb +0 -27
  76. data/spec/unit/inspect_spec.rb +0 -11
  77. data/spec/unit/iterate_spec.rb +0 -79
  78. data/spec/unit/log_spec.rb +0 -29
  79. data/spec/unit/meter_spec.rb +0 -70
  80. data/spec/unit/multi/advance_spec.rb +0 -123
  81. data/spec/unit/multi/events_spec.rb +0 -115
  82. data/spec/unit/multi/finish_spec.rb +0 -41
  83. data/spec/unit/multi/line_inset_spec.rb +0 -65
  84. data/spec/unit/multi/register_spec.rb +0 -35
  85. data/spec/unit/multi/stop_spec.rb +0 -15
  86. data/spec/unit/new_spec.rb +0 -66
  87. data/spec/unit/pipeline_spec.rb +0 -19
  88. data/spec/unit/ratio_spec.rb +0 -31
  89. data/spec/unit/reset_spec.rb +0 -31
  90. data/spec/unit/resize_spec.rb +0 -35
  91. data/spec/unit/set_current_spec.rb +0 -43
  92. data/spec/unit/start_spec.rb +0 -14
  93. data/spec/unit/stop_spec.rb +0 -19
  94. data/spec/unit/update_spec.rb +0 -22
  95. data/spec/unit/width_spec.rb +0 -21
  96. data/tasks/console.rake +0 -9
  97. data/tasks/coverage.rake +0 -9
  98. data/tasks/spec.rake +0 -27
  99. data/tty-progressbar.gemspec +0 -30
@@ -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[?25h\e[1G[=====]\n"
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")
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
@@ -1,115 +0,0 @@
1
- RSpec.describe TTY::ProgressBar::Multi, 'events' do
2
- let(:output) { StringIO.new('', 'w+') }
3
-
4
- it "emits :progress event when any of the registerd bars advances" do
5
- events = []
6
- bars = TTY::ProgressBar::Multi.new("[:bar]", output: output, total: 5)
7
- bars.on(:progress) { events << :progress }
8
-
9
- bar = bars.register "one [:bar]"
10
- bar.advance
11
-
12
- expect(events).to eq([:progress])
13
- end
14
-
15
- it "emits :done event when all progress bars finished under top level" do
16
- events = []
17
- bars = TTY::ProgressBar::Multi.new("[:bar]", output: output, total: 5)
18
- bars.on(:done) { events << :done }
19
- bar = bars.register "one [:bar]"
20
-
21
- bar.finish
22
-
23
- expect(events).to eq([:done])
24
- expect(bar.complete?).to eq(true)
25
- end
26
-
27
- it "emits :done event when all progress bars finished without top level" do
28
- events = []
29
- bars = TTY::ProgressBar::Multi.new(output: output)
30
- bars.on(:done) { events << :done }
31
- bar = bars.register "one [:bar]", total: 5
32
-
33
- bar.finish
34
-
35
- expect(events).to eq([:done])
36
- expect(bars.complete?).to eq(true)
37
- end
38
-
39
- it "emits :done event when top level registered bar finished" do
40
- events = []
41
- bars = TTY::ProgressBar::Multi.new("[:bar]", output: output, total: 5)
42
- bars.on(:done) { events << :done }
43
-
44
- bar = bars.register "one [:bar]", total: 5
45
-
46
- bars.finish
47
-
48
- expect(events).to eq([:done])
49
- expect(bar.complete?).to eq(true)
50
- end
51
-
52
- it "emits :done event when top level bar finished" do
53
- events = []
54
- bars = TTY::ProgressBar::Multi.new(output: output)
55
- bars.on(:done) { events << :done }
56
-
57
- bar = bars.register "one [:bar]", total: 5
58
-
59
- bars.finish
60
-
61
- expect(events).to eq([:done])
62
- expect(bar.complete?).to eq(true)
63
- end
64
-
65
- it "emits :stopped event when all registerd bars are stopped under top level" do
66
- events = []
67
- bars = TTY::ProgressBar::Multi.new("[:bar]", output: output, total: 5)
68
- bars.on(:stopped) { events << :stopped }
69
-
70
- bar = bars.register "one [:bar]"
71
-
72
- bar.stop
73
-
74
- expect(events).to eq([:stopped])
75
- expect(bars.stopped?).to eq(true)
76
- end
77
-
78
- it "emits :stopped event when all registerd bars are stopped without top level" do
79
- events = []
80
- bars = TTY::ProgressBar::Multi.new(output: output)
81
- bars.on(:stopped) { events << :stopped }
82
-
83
- bar = bars.register "one [:bar]", total: 5
84
-
85
- bar.stop
86
-
87
- expect(events).to eq([:stopped])
88
- expect(bars.stopped?).to eq(true)
89
- end
90
-
91
- it "emits :stopped event when registerd multi bar finished" do
92
- events = []
93
- bars = TTY::ProgressBar::Multi.new("[:bar]", output: output, total: 5)
94
- bars.on(:stopped) { events << :stopped }
95
-
96
- bars.register "one [:bar]"
97
-
98
- bars.stop
99
-
100
- expect(events).to eq([:stopped])
101
- end
102
-
103
- it "emits :stopped event when multi bar finished" do
104
- events = []
105
- bars = TTY::ProgressBar::Multi.new(output: output)
106
- bars.on(:stopped) { events << :stopped }
107
-
108
- bars.register "one [:bar]", total: 5
109
-
110
- bars.stop
111
-
112
- expect(events).to eq([:stopped])
113
- expect(bars.stopped?).to eq(true)
114
- end
115
- end