tty-progressbar 0.15.0 → 0.18.1

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 (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,19 +0,0 @@
1
- RSpec.describe TTY::ProgressBar::Pipeline, '#decorate' do
2
- subject(:pipeline) { described_class.new }
3
-
4
- it "decorates tokenized string with pipeline formatters" do
5
- pipeline.use TTY::ProgressBar::CurrentFormatter
6
- pipeline.use TTY::ProgressBar::TotalFormatter
7
- progress_bar = double(current: '3', total: '10')
8
- tokenized = "[:current/:total]"
9
- expect(pipeline.decorate(progress_bar, tokenized)).to eq("[3/10]")
10
- end
11
-
12
- it "enumerates pipeline formatters" do
13
- pipeline.use TTY::ProgressBar::CurrentFormatter
14
- pipeline.use TTY::ProgressBar::TotalFormatter
15
- yielded = []
16
- pipeline.each { |formatter| yielded << formatter }
17
- expect(yielded.size).to eq(2)
18
- end
19
- end
@@ -1,31 +0,0 @@
1
- RSpec.describe TTY::ProgressBar, '#ratio=' do
2
- let(:output) { StringIO.new('', 'w+') }
3
-
4
- it "allows to set ratio" do
5
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
6
- progress.ratio = 0.7
7
- expect(progress.current).to eq(7)
8
- output.rewind
9
- expect(output.read).to eq([
10
- "\e[1G[======= ]"
11
- ].join)
12
- end
13
-
14
- it "finds closest available step from the ratio" do
15
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 3)
16
- progress.ratio = 0.5
17
- expect(progress.current).to eq(1)
18
- end
19
-
20
- it "doesn't allow to set wrong ratio" do
21
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 3)
22
- progress.ratio = 3.2
23
- expect(progress.current).to eq(3)
24
- expect(progress.complete?).to eq(true)
25
- end
26
-
27
- it "avoids division by zero" do
28
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 0)
29
- expect(progress.ratio).to eq(0)
30
- end
31
- end
@@ -1,25 +0,0 @@
1
- RSpec.describe TTY::ProgressBar, "#render" do
2
- let(:output) { StringIO.new("", "w+") }
3
-
4
- it "pads out longer previous lines" do
5
- progress = TTY::ProgressBar.new ":current_byte" do |config|
6
- config.no_width = true
7
- config.output = output
8
- config.total = 1_048_577
9
- end
10
-
11
- progress.advance(1)
12
- progress.advance(1_048_574)
13
- progress.advance(1)
14
- progress.advance(1)
15
-
16
- output.rewind
17
-
18
- expect(output.read).to eq([
19
- "\e[1G1B",
20
- "\e[1G1024.00KB", # must not pad, line is longer
21
- "\e[1G1.00MB ", # must pad out "0KB"
22
- "\e[1G1.00MB", # must not pad, line is equal
23
- ].join)
24
- end
25
- end
@@ -1,31 +0,0 @@
1
- RSpec.describe TTY::ProgressBar, '#reset' do
2
- let(:output) { StringIO.new('', 'w+') }
3
-
4
- it "resets current progress" do
5
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
6
- progress.advance(5)
7
- progress.reset
8
- 2.times { progress.advance(3) }
9
- output.rewind
10
- expect(output.read).to eq([
11
- "\e[1G[===== ]",
12
- "\e[1G[=== ]",
13
- "\e[1G[====== ]"
14
- ].join)
15
- end
16
-
17
- it "resets finished progress" do
18
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
19
- progress.advance(10)
20
- expect(progress.complete?).to be(true)
21
- progress.reset
22
- expect(progress.complete?).to be(false)
23
- 2.times { progress.advance(3) }
24
- output.rewind
25
- expect(output.read).to eq([
26
- "\e[1G[==========]\n",
27
- "\e[1G[=== ]",
28
- "\e[1G[====== ]"
29
- ].join)
30
- end
31
- end
@@ -1,35 +0,0 @@
1
- RSpec.describe TTY::ProgressBar, '#resize' do
2
- let(:output) { StringIO.new('', 'w+') }
3
-
4
- it "resizes output down by x2" do
5
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 5, width: 10)
6
- 2.times { progress.advance }
7
- progress.resize(5)
8
- 3.times { progress.advance }
9
- output.rewind
10
- expect(output.read).to eq([
11
- "\e[1G[== ]",
12
- "\e[1G[==== ]",
13
- "\e[0m\e[2K\e[1G",
14
- "\e[1G[=== ] ",
15
- "\e[1G[==== ]",
16
- "\e[1G[=====]\n"
17
- ].join)
18
- end
19
-
20
- it "resizes output up by x2" do
21
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 5, width: 10)
22
- 2.times { progress.advance }
23
- progress.resize(20)
24
- 3.times { progress.advance }
25
- output.rewind
26
- expect(output.read).to eq([
27
- "\e[1G[== ]",
28
- "\e[1G[==== ]",
29
- "\e[0m\e[2K\e[1G",
30
- "\e[1G[============ ]",
31
- "\e[1G[================ ]",
32
- "\e[1G[====================]\n"
33
- ].join)
34
- end
35
- end
@@ -1,43 +0,0 @@
1
- RSpec.describe TTY::ProgressBar, '#current=' do
2
- let(:output) { StringIO.new('', 'w+') }
3
-
4
- it "allows to go back" do
5
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
6
- 3.times { progress.advance }
7
- progress.current = 5
8
- expect(progress.current).to eq(5)
9
- output.rewind
10
- expect(output.read).to eq([
11
- "\e[1G[= ]",
12
- "\e[1G[== ]",
13
- "\e[1G[=== ]",
14
- "\e[1G[===== ]"
15
- ].join)
16
- progress.current = 0
17
- expect(progress.current).to eq(0)
18
- end
19
-
20
- it "doesn't allow to go over total" do
21
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
22
- progress.current = 12
23
- expect(progress.current).to eq(10)
24
- output.rewind
25
- expect(output.read).to eq("\e[1G[==========]\n")
26
- end
27
-
28
- it "doesn't allow to go below 0" do
29
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
30
- progress.current = -1
31
- expect(progress.current).to eq(0)
32
- end
33
-
34
- it "cannot backtrack on finished" do
35
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
36
- progress.current = 10
37
- expect(progress.current).to eq(10)
38
- progress.current = 5
39
- expect(progress.current).to eq(10)
40
- output.rewind
41
- expect(output.read).to eq("\e[1G[==========]\n")
42
- end
43
- end
@@ -1,14 +0,0 @@
1
- RSpec.describe TTY::ProgressBar, '#start' do
2
- let(:output) { StringIO.new('', 'w+') }
3
-
4
- it "starts timer and draws initial progress" do
5
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
6
- progress.start
7
- progress.advance
8
- output.rewind
9
- expect(output.read).to eq([
10
- "\e[1G[ ]",
11
- "\e[1G[= ]"
12
- ].join)
13
- end
14
- end
@@ -1,19 +0,0 @@
1
- RSpec.describe TTY::ProgressBar, '#stop' do
2
- let(:output) { StringIO.new('', 'w+') }
3
-
4
- it 'stops progress' do
5
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
6
- 5.times { |i|
7
- progress.stop if i == 3
8
- progress.advance
9
- }
10
- expect(progress.complete?).to be(false)
11
- output.rewind
12
- expect(output.read).to eq([
13
- "\e[1G[= ]",
14
- "\e[1G[== ]",
15
- "\e[1G[=== ]",
16
- "\e[1G[=== ]\n"
17
- ].join)
18
- end
19
- end
@@ -1,22 +0,0 @@
1
- RSpec.describe TTY::ProgressBar, '#update' do
2
- let(:output) { StringIO.new('', 'w+') }
3
-
4
- it "updates bar configuration options" do
5
- progress = TTY::ProgressBar.new "[:bar]" do |config|
6
- config.output = output
7
- config.total = 10
8
- end
9
- 10.times { |i|
10
- progress.update(complete: '-', head: '>') if i == 2
11
- progress.advance(2)
12
- }
13
- output.rewind
14
- expect(output.read).to eq([
15
- "\e[1G[== ]",
16
- "\e[1G[==== ]",
17
- "\e[1G[-----> ]",
18
- "\e[1G[-------> ]",
19
- "\e[1G[--------->]\n"
20
- ].join)
21
- end
22
- end
@@ -1,86 +0,0 @@
1
- RSpec.describe TTY::ProgressBar, '#width' do
2
- let(:output) { StringIO.new('', 'w+') }
3
-
4
- it "handles width exceeding terminal width" do
5
- progress = TTY::ProgressBar.new "[:bar]" do |config|
6
- config.output = output
7
- config.total = 5
8
- config.width = 1024
9
- end
10
- allow(TTY::Screen).to receive(:width).and_return(20)
11
-
12
- 5.times { progress.advance }
13
- output.rewind
14
-
15
- expect(output.read).to eq([
16
- "\e[1G[==== ]",
17
- "\e[1G[======= ]",
18
- "\e[1G[=========== ]",
19
- "\e[1G[============== ]",
20
- "\e[1G[==================]\n"
21
- ].join)
22
- end
23
-
24
- it "handles unicode characters width in formatting string" do
25
- bar = TTY::ProgressBar.new("あめかんむり[:bar]", output: output, total: 20)
26
- allow(TTY::Screen).to receive(:width).and_return(20)
27
-
28
- 4.times { bar.advance(5) }
29
- output.rewind
30
-
31
- expect(output.read).to eq([
32
- "\e[1Gあめかんむり[== ]",
33
- "\e[1Gあめかんむり[=== ]",
34
- "\e[1Gあめかんむり[===== ]",
35
- "\e[1Gあめかんむり[======]\n"
36
- ].join)
37
- end
38
-
39
- it "handles unicodes characters within bar" do
40
- bar = TTY::ProgressBar.new("[:bar]", output: output, total: 20,
41
- complete: 'あ', incomplete: 'め')
42
- allow(TTY::Screen).to receive(:width).and_return(20)
43
-
44
- 4.times { bar.advance(5) }
45
- output.rewind
46
-
47
- expect(output.read).to eq([
48
- "\e[1G[あああめめめめめめ]",
49
- "\e[1G[あああああめめめめ]",
50
- "\e[1G[あああああああめめ]",
51
- "\e[1G[あああああああああ]\n"
52
- ].join)
53
- end
54
-
55
- it "handles unicodes characters within bar" do
56
- bar = TTY::ProgressBar.new("[:bar]", output: output, total: 20,
57
- complete: 'あ', incomplete: ' ')
58
- allow(TTY::Screen).to receive(:width).and_return(20)
59
-
60
- 4.times { bar.advance(5) }
61
- output.rewind
62
-
63
- expect(output.read).to eq([
64
- "\e[1G[あああ ]",
65
- "\e[1G[あああああ ]",
66
- "\e[1G[あああああああ ]",
67
- "\e[1G[あああああああああ]\n"
68
- ].join)
69
- end
70
-
71
- it "handles unicodes characters within bar" do
72
- bar = TTY::ProgressBar.new("[:bar]", output: output, total: 20,
73
- complete: 'x', incomplete: 'め')
74
- allow(TTY::Screen).to receive(:width).and_return(20)
75
-
76
- 4.times { bar.advance(5) }
77
- output.rewind
78
-
79
- expect(output.read).to eq([
80
- "\e[1G[xxxxxめめめめめめ]",
81
- "\e[1G[xxxxxxxxxめめめめ]",
82
- "\e[1G[xxxxxxxxxxxxxxめめ]",
83
- "\e[1G[xxxxxxxxxxxxxxxxxx]\n"
84
- ].join)
85
- end
86
- end
@@ -1,9 +0,0 @@
1
- desc 'Load gem inside irb console'
2
- task :console do
3
- require 'irb'
4
- require 'irb/completion'
5
- require_relative '../lib/tty-progressbar'
6
- ARGV.clear
7
- IRB.start
8
- end
9
- task :c => :console
@@ -1,9 +0,0 @@
1
- desc 'Measure code coverage'
2
- task :coverage do
3
- begin
4
- original, ENV['COVERAGE'] = ENV['COVERAGE'], 'true'
5
- Rake::Task['spec'].invoke
6
- ensure
7
- ENV['COVERAGE'] = original
8
- end
9
- end
@@ -1,27 +0,0 @@
1
- begin
2
- require 'rspec/core/rake_task'
3
-
4
- desc 'Run all specs'
5
- RSpec::Core::RakeTask.new(:spec) do |task|
6
- task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb'
7
- end
8
-
9
- namespace :spec do
10
- desc 'Run unit specs'
11
- RSpec::Core::RakeTask.new(:unit) do |task|
12
- task.pattern = 'spec/unit{,/*/**}/*_spec.rb'
13
- end
14
-
15
- desc 'Run integration specs'
16
- RSpec::Core::RakeTask.new(:integration) do |task|
17
- task.pattern = 'spec/integration{,/*/**}/*_spec.rb'
18
- end
19
- end
20
-
21
- rescue LoadError
22
- %w[spec spec:unit spec:integration].each do |name|
23
- task name do
24
- $stderr.puts "In order to run #{name}, do `gem install rspec`"
25
- end
26
- end
27
- end
@@ -1,31 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'tty/progressbar/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "tty-progressbar"
8
- spec.version = TTY::ProgressBar::VERSION
9
- spec.authors = ["Piotr Murach"]
10
- spec.email = [""]
11
- spec.summary = %q{A flexible progress bars drawing in terminal emulators.}
12
- spec.description = %q{A flexible progress bars drawing in terminal emulators.}
13
- spec.homepage = "https://piotrmurach.github.io/tty/"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.required_ruby_version = '>= 2.0.0'
22
-
23
- spec.add_dependency 'tty-cursor', '~> 0.5.0'
24
- spec.add_dependency 'tty-screen', '~> 0.6.4'
25
- spec.add_dependency 'unicode-display_width', '~> 1.3'
26
-
27
- spec.add_development_dependency 'bundler', '>= 1.5.0', '< 2.0'
28
- spec.add_development_dependency 'rspec', '~> 3.1'
29
- spec.add_development_dependency 'timecop', '~> 0.9.1'
30
- spec.add_development_dependency 'rake'
31
- end