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.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +492 -126
  5. data/lib/tty-progressbar.rb +2 -2
  6. data/lib/tty/progressbar.rb +168 -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 +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 +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 +1 -1
  30. metadata +44 -103
  31. data/Rakefile +0 -8
  32. data/examples/color.rb +0 -18
  33. data/examples/failure.rb +0 -12
  34. data/examples/iterator.rb +0 -5
  35. data/examples/lazy.rb +0 -6
  36. data/examples/multi/main_bar.rb +0 -13
  37. data/examples/multi/simple.rb +0 -13
  38. data/examples/multi/width.rb +0 -13
  39. data/examples/simple.rb +0 -7
  40. data/examples/slow_process.rb +0 -29
  41. data/examples/speed.rb +0 -11
  42. data/examples/threaded.rb +0 -14
  43. data/examples/tokens.rb +0 -12
  44. data/examples/unicode.rb +0 -7
  45. data/spec/spec_helper.rb +0 -53
  46. data/spec/unit/advance_spec.rb +0 -25
  47. data/spec/unit/clear_spec.rb +0 -17
  48. data/spec/unit/complete_spec.rb +0 -16
  49. data/spec/unit/converter/to_bytes_spec.rb +0 -47
  50. data/spec/unit/converter/to_seconds_spec.rb +0 -15
  51. data/spec/unit/converter/to_time_spec.rb +0 -19
  52. data/spec/unit/custom_formatter_spec.rb +0 -26
  53. data/spec/unit/custom_token_spec.rb +0 -14
  54. data/spec/unit/events_spec.rb +0 -33
  55. data/spec/unit/finish_spec.rb +0 -15
  56. data/spec/unit/formatter/bar_spec.rb +0 -33
  57. data/spec/unit/formatter/byte_rate_spec.rb +0 -32
  58. data/spec/unit/formatter/current_byte_spec.rb +0 -16
  59. data/spec/unit/formatter/current_spec.rb +0 -14
  60. data/spec/unit/formatter/elapsed_spec.rb +0 -58
  61. data/spec/unit/formatter/estimated_spec.rb +0 -27
  62. data/spec/unit/formatter/mean_byte_spec.rb +0 -32
  63. data/spec/unit/formatter/mean_rate_spec.rb +0 -31
  64. data/spec/unit/formatter/percent_spec.rb +0 -16
  65. data/spec/unit/formatter/rate_spec.rb +0 -31
  66. data/spec/unit/formatter/total_byte_spec.rb +0 -16
  67. data/spec/unit/formatter/total_spec.rb +0 -16
  68. data/spec/unit/frequency_spec.rb +0 -27
  69. data/spec/unit/head_spec.rb +0 -32
  70. data/spec/unit/hide_cursor_spec.rb +0 -27
  71. data/spec/unit/inspect_spec.rb +0 -11
  72. data/spec/unit/iterate_spec.rb +0 -79
  73. data/spec/unit/log_spec.rb +0 -29
  74. data/spec/unit/meter_spec.rb +0 -70
  75. data/spec/unit/multi/advance_spec.rb +0 -123
  76. data/spec/unit/multi/events_spec.rb +0 -115
  77. data/spec/unit/multi/finish_spec.rb +0 -41
  78. data/spec/unit/multi/line_inset_spec.rb +0 -65
  79. data/spec/unit/multi/register_spec.rb +0 -35
  80. data/spec/unit/multi/reset_spec.rb +0 -28
  81. data/spec/unit/multi/stop_spec.rb +0 -15
  82. data/spec/unit/multi/width_spec.rb +0 -118
  83. data/spec/unit/new_spec.rb +0 -76
  84. data/spec/unit/pipeline_spec.rb +0 -19
  85. data/spec/unit/ratio_spec.rb +0 -31
  86. data/spec/unit/render_spec.rb +0 -25
  87. data/spec/unit/reset_spec.rb +0 -31
  88. data/spec/unit/resize_spec.rb +0 -35
  89. data/spec/unit/set_current_spec.rb +0 -43
  90. data/spec/unit/start_spec.rb +0 -14
  91. data/spec/unit/stop_spec.rb +0 -19
  92. data/spec/unit/update_spec.rb +0 -22
  93. data/spec/unit/width_spec.rb +0 -86
  94. data/tasks/console.rake +0 -9
  95. data/tasks/coverage.rake +0 -9
  96. data/tasks/spec.rake +0 -27
  97. data/tty-progressbar.gemspec +0 -32
@@ -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
@@ -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