tty-progressbar 0.15.0 → 0.18.1

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 +5 -5
  2. data/CHANGELOG.md +84 -21
  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 +175 -72
  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 -31
@@ -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
@@ -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,28 +0,0 @@
1
- RSpec.describe TTY::ProgressBar::Multi, '#reset' do
2
- let(:output) { StringIO.new('', 'w+') }
3
-
4
- it "leaves multibar state alone" do
5
- main = TTY::ProgressBar::Multi.new("", output: output, total: 10)
6
- progress = main.register("[:bar]")
7
- progress.advance(10)
8
- expect(progress.complete?).to be(true)
9
- progress.reset
10
- expect(progress.complete?).to be(false)
11
- progress.advance(10)
12
- output.rewind
13
-
14
- top = TTY::ProgressBar::Multi::DEFAULT_INSET[:top]
15
- bottom = TTY::ProgressBar::Multi::DEFAULT_INSET[:bottom]
16
-
17
- progress_updates =
18
- output.read.scan(/#{Regexp.escape top}|#{Regexp.escape bottom}/)
19
- expect(progress_updates.shift).to match(top)
20
- expect(progress_updates.shift).to match(top)
21
- expect(progress_updates.shift).to match(bottom)
22
- expect(progress_updates.shift).to match(bottom)
23
- expect(progress_updates.shift).to match(bottom)
24
- expect(progress_updates.shift).to match(bottom)
25
-
26
- expect(progress_updates).to be_empty
27
- end
28
- 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
@@ -1,118 +0,0 @@
1
- RSpec.describe TTY::ProgressBar::Multi, 'width' 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 "sets top level bar width to maximum columns when exceeds terminal width" do
10
- allow(TTY::Screen).to receive(:width).and_return(15)
11
-
12
- bars = TTY::ProgressBar::Multi.new("[:bar] main", output: output)
13
-
14
- bar1 = bars.register("[:bar] one", total: 20)
15
- bar2 = bars.register("[:bar] two", total: 20)
16
-
17
- bar1.advance(10)
18
- bar2.advance(10)
19
-
20
- output.rewind
21
- expect(output.read).to eq([
22
- "\e[1G#{top}[== ] main\n",
23
- "\e[1G#{bottom}[=== ] one\n",
24
- save,
25
- "\e[2A", # up 2 lines
26
- "\e[1G#{top}[=== ] main",
27
- restore,
28
- "\e[1G#{bottom}[=== ] two\n"
29
- ].join)
30
-
31
- bar1.advance(10)
32
-
33
- output.rewind
34
- expect(output.read).to eq([
35
- "\e[1G#{top}[== ] main\n",
36
- "\e[1G#{bottom}[=== ] one\n",
37
- save,
38
- "\e[2A", # up 2 lines
39
- "\e[1G#{top}[=== ] main",
40
- restore,
41
- "\e[1G#{bottom}[=== ] two\n",
42
- save,
43
- "\e[3A", # up 3 lines
44
- "\e[1G#{top}[===== ] main",
45
- restore,
46
- save,
47
- "\e[2A", # up 2 lines
48
- "\e[1G#{middle}[=====] one",
49
- restore,
50
- save,
51
- "\e[2A", # up 2 lines
52
- "#{middle}\n", # bar finished
53
- restore
54
- ].join)
55
-
56
- bar2.advance(10)
57
-
58
- output.rewind
59
- expect(output.read).to eq([
60
- "\e[1G#{top}[== ] main\n",
61
- "\e[1G#{bottom}[=== ] one\n",
62
- save,
63
- "\e[2A", # up 2 lines
64
- "\e[1G#{top}[=== ] main",
65
- restore,
66
- "\e[1G#{bottom}[=== ] two\n",
67
- save,
68
- "\e[3A", # up 3 lines
69
- "\e[1G#{top}[===== ] main",
70
- restore,
71
- save,
72
- "\e[2A", # up 2 lines
73
- "\e[1G#{middle}[=====] one",
74
- restore,
75
- save,
76
- "\e[2A", # up 2 lines
77
- "#{middle}\n", # bar finished
78
- restore,
79
- save,
80
- "\e[3A", # up 3 lines
81
- "\e[1G#{top}[======] main",
82
- restore,
83
- save,
84
- "\e[3A", # up 1 line
85
- "#{top}\n",
86
- restore,
87
- save,
88
- "\e[1A", # up 1 line
89
- "\e[1G#{bottom}[=====] two",
90
- restore,
91
- save,
92
- "\e[1A", # up 1 line
93
- "#{bottom}\n",
94
- restore
95
- ].join)
96
- end
97
-
98
- it "sets top level bar width to a custom value" do
99
- bars = TTY::ProgressBar::Multi.new("[:bar] main", output: output, width: 20)
100
-
101
- bar1 = bars.register("[:bar] one", total: 20)
102
- bar2 = bars.register("[:bar] two", total: 20)
103
-
104
- bar1.advance(10)
105
- bar2.advance(10)
106
-
107
- output.rewind
108
- expect(output.read).to eq([
109
- "\e[1G#{top}[===== ] main\n",
110
- "\e[1G#{bottom}[========== ] one\n",
111
- save,
112
- "\e[2A", # up 2 lines
113
- "\e[1G#{top}[========== ] main",
114
- restore,
115
- "\e[1G#{bottom}[========== ] two\n"
116
- ].join)
117
- end
118
- end
@@ -1,76 +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 "allows to change formatting string" do
11
- bar = TTY::ProgressBar.new("[:bar]", output: output, total: 4)
12
- bar.advance(2)
13
- bar.format = "(:bar)"
14
- bar.advance(2)
15
- output.rewind
16
-
17
- expect(output.read).to eq("\e[1G[== ]\e[1G(====)\n")
18
- end
19
-
20
- it "displays output where width == total" do
21
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
22
- progress.advance
23
- output.rewind
24
- expect(output.read).to eq("\e[1G[= ]")
25
- end
26
-
27
- it "yields configuration to block" do
28
- progress = TTY::ProgressBar.new "[:bar]" do |config|
29
- config.output = output
30
- config.total = 10
31
- config.clear = true
32
- end
33
- expect(progress.output).to eq(output)
34
- expect(progress.total).to eq(10)
35
- expect(progress.width).to eq(10)
36
- expect(progress.clear).to eq(true)
37
- end
38
-
39
- it "displays output where width > total" do
40
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 5, width: 10)
41
- 5.times { progress.advance }
42
- output.rewind
43
- expect(output.read).to eq([
44
- "\e[1G[== ]",
45
- "\e[1G[==== ]",
46
- "\e[1G[====== ]",
47
- "\e[1G[======== ]",
48
- "\e[1G[==========]\n"
49
- ].join)
50
- end
51
-
52
- it "displays output where width < total" do
53
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10, width: 5)
54
- 10.times { progress.advance }
55
- output.rewind
56
- expect(output.read).to eq([
57
- "\e[1G[= ]",
58
- "\e[1G[= ]",
59
- "\e[1G[== ]",
60
- "\e[1G[== ]",
61
- "\e[1G[=== ]",
62
- "\e[1G[=== ]",
63
- "\e[1G[==== ]",
64
- "\e[1G[==== ]",
65
- "\e[1G[=====]",
66
- "\e[1G[=====]\n"
67
- ].join)
68
- end
69
-
70
- it "displays total value" do
71
- progress = TTY::ProgressBar.new("|:total|", output: output, total: 10)
72
- progress.advance(3)
73
- output.rewind
74
- expect(output.read).to eq("\e[1G|10|")
75
- end
76
- end