tty-progressbar 0.14.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
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
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --require spec_helper
3
- --warnings
@@ -1,25 +0,0 @@
1
- ---
2
- language: ruby
3
- sudo: false
4
- cache: bundler
5
- before_install: "gem update bundler"
6
- script: "bundle exec rake ci"
7
- rvm:
8
- - 2.0.0
9
- - 2.1.10
10
- - 2.2.8
11
- - 2.3.6
12
- - 2.4.3
13
- - ruby-head
14
- - jruby-9.1.5.0
15
- - jruby-head
16
- matrix:
17
- allow_failures:
18
- - rvm: ruby-head
19
- - rvm: jruby-9.1.5.0
20
- - rvm: jruby-head
21
- fast_finish: true
22
- branches:
23
- only: master
24
- notifications:
25
- email: false
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at [email]. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,14 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :test do
6
- gem 'pastel', '~> 0.7.2'
7
- gem 'coveralls', '~> 0.8.13'
8
- gem 'simplecov', '~> 0.11.2'
9
- end
10
-
11
- group :metrics do
12
- gem 'yard', '~> 0.9.12'
13
- gem 'yardstick', '~> 0.9.9'
14
- end
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "bundler/gem_tasks"
4
-
5
- FileList['tasks/**/*.rake'].each(&method(:import))
6
-
7
- desc 'Run all specs'
8
- task ci: %w[ spec ]
@@ -1,21 +0,0 @@
1
- ---
2
- install:
3
- - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
4
- - ruby --version
5
- - gem --version
6
- - bundle install
7
- build: off
8
- test_script:
9
- - bundle exec rake ci
10
- environment:
11
- matrix:
12
- - ruby_version: "200"
13
- - ruby_version: "200-x64"
14
- - ruby_version: "21"
15
- - ruby_version: "21-x64"
16
- - ruby_version: "22"
17
- - ruby_version: "22-x64"
18
- - ruby_version: "23"
19
- - ruby_version: "23-x64"
20
- - ruby_version: "24"
21
- - ruby_version: "24-x64"
@@ -1,18 +0,0 @@
1
- require 'pastel'
2
-
3
- require_relative '../lib/tty-progressbar'
4
-
5
- pastel = Pastel.new
6
- green = pastel.on_green(" ")
7
- red = pastel.on_red(" ")
8
-
9
- bar = TTY::ProgressBar.new("|:bar|",
10
- total: 30,
11
- complete: green,
12
- incomplete: red
13
- )
14
-
15
- 30.times do
16
- sleep(0.1)
17
- bar.advance
18
- end
@@ -1,12 +0,0 @@
1
- require_relative '../lib/tty-progressbar'
2
-
3
- bar = TTY::ProgressBar.new("downloading [:bar] :percent", head: '>', total: 30)
4
- 30.times do |i|
5
- if i == 15
6
- bar.update(head: 'x')
7
- bar.stop
8
- break
9
- end
10
- sleep(0.1)
11
- bar.advance
12
- end
@@ -1,5 +0,0 @@
1
- require_relative '../lib/tty-progressbar'
2
-
3
- bar = TTY::ProgressBar.new("[:bar]", total: 30)
4
-
5
- bar.iterate(30.times) { sleep(0.1) }
@@ -1,6 +0,0 @@
1
- require_relative '../lib/tty-progressbar'
2
-
3
- bar = TTY::ProgressBar.new("[:bar] :current", total: 10, width: 20)
4
-
5
- range = 1..Float::INFINITY
6
- bar.iterate(range.lazy.take(10)) { sleep(0.1) }
@@ -1,13 +0,0 @@
1
- require_relative '../../lib/tty-progressbar'
2
-
3
- bars = TTY::ProgressBar::Multi.new("main [:bar] :percent")
4
-
5
- bar1 = bars.register "foo [:bar] :percent", total: 15
6
- bar2 = bars.register "bar [:bar] :percent", total: 15
7
- bar3 = bars.register "baz [:bar] :percent", total: 45
8
-
9
- th1 = Thread.new { 15.times { sleep(0.1); bar1.advance } }
10
- th2 = Thread.new { 15.times { sleep(0.1); bar2.advance } }
11
- th3 = Thread.new { 45.times { sleep(0.1); bar3.advance } }
12
-
13
- [th1, th2, th3].each(&:join)
@@ -1,13 +0,0 @@
1
- require_relative '../../lib/tty-progressbar'
2
-
3
- bars = TTY::ProgressBar::Multi.new
4
-
5
- bar1 = bars.register "foo [:bar] :percent", total: 20
6
- bar2 = bars.register "bar [:bar] :percent", total: 30
7
- bar3 = bars.register "baz [:bar] :percent", total: 10
8
-
9
- th1 = Thread.new { 20.times { sleep(0.2); bar1.advance } }
10
- th2 = Thread.new { 30.times { sleep(0.1); bar2.advance } }
11
- th3 = Thread.new { 10.times { sleep(0.3); bar3.advance } }
12
-
13
- [th1, th2, th3].each(&:join)
@@ -1,7 +0,0 @@
1
- require_relative '../lib/tty-progressbar'
2
-
3
- bar = TTY::ProgressBar.new("downloading [:bar] :elapsed :percent", total: 30)
4
- 30.times do
5
- sleep(0.1)
6
- bar.advance
7
- end
@@ -1,29 +0,0 @@
1
- require_relative '../lib/tty-progressbar'
2
-
3
- CONTENT_SIZE = 2048
4
- CHUNK_SIZE = 255
5
-
6
- # Dummy "long responding server"
7
- def download_from_server(offset, limit)
8
- sleep(0.1)
9
- "<chunk #{offset}..#{offset + limit}>"
10
- end
11
-
12
- def download_finished?(position)
13
- position >= CONTENT_SIZE
14
- end
15
-
16
- downloader = Enumerator.new do |y|
17
- start = 0
18
- loop do
19
- y.yield(download_from_server(start, CHUNK_SIZE))
20
- start += CHUNK_SIZE
21
- raise StopIteration if download_finished?(start)
22
- end
23
- end
24
-
25
- bar = TTY::ProgressBar.new("[:bar] :current_byte/:total_byte", total: CONTENT_SIZE)
26
-
27
- response = bar.iterate(downloader, CHUNK_SIZE).to_a.join
28
-
29
- puts response
@@ -1,11 +0,0 @@
1
- require_relative '../lib/tty-progressbar'
2
-
3
- bar = TTY::ProgressBar.new "downloading [:bar] :rate/s :mean_rate/s" do |conf|
4
- conf.total = 100
5
- conf.interval = 1
6
- end
7
-
8
- 30.times do
9
- sleep(0.1)
10
- bar.advance(Random.rand(10))
11
- end
@@ -1,14 +0,0 @@
1
- require_relative '../lib/tty-progressbar'
2
-
3
- threads = []
4
-
5
- bar = TTY::ProgressBar.new("[:bar] :percent", total: 30)
6
-
7
- threads << Thread.new {
8
- 15.times { sleep(0.1); bar.update(complete: '-', head: '-'); bar.advance(); }
9
- }
10
- threads << Thread.new {
11
- 15.times { sleep(0.1); bar.update(complete: '+', head: '+'); bar.advance(); }
12
- }
13
-
14
- threads.map(&:join)
@@ -1,12 +0,0 @@
1
- require_relative '../lib/tty-progressbar'
2
-
3
- files = [
4
- 'file1.txt', 'file2.txt', 'file3.txt', 'file4.txt', 'file5.txt',
5
- 'file6.txt', 'file7.txt', 'file8.txt', 'file9.txt', 'file10.txt'
6
- ]
7
-
8
- bar = TTY::ProgressBar.new("downloading :file :percent", total: files.size)
9
- 10.times do |num|
10
- sleep(0.1)
11
- bar.advance(file: files[num])
12
- end
@@ -1,50 +0,0 @@
1
- if ENV['COVERAGE'] || ENV['TRAVIS']
2
- require 'simplecov'
3
- require 'coveralls'
4
-
5
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
- SimpleCov::Formatter::HTMLFormatter,
7
- Coveralls::SimpleCov::Formatter
8
- ]
9
-
10
- SimpleCov.start do
11
- command_name 'spec'
12
- add_filter 'spec'
13
- end
14
- end
15
-
16
- require 'timecop'
17
- require 'tty-progressbar'
18
-
19
- class StringIO
20
- def tty?
21
- true
22
- end
23
- end
24
-
25
- RSpec.configure do |config|
26
- config.expect_with :rspec do |expectations|
27
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
28
- end
29
-
30
- config.mock_with :rspec do |mocks|
31
- mocks.verify_partial_doubles = true
32
- end
33
-
34
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
35
- config.disable_monkey_patching!
36
-
37
- # This setting enables warnings. It's recommended, but in some cases may
38
- # be too noisy due to issues in dependencies.
39
- config.warnings = true
40
-
41
- if config.files_to_run.one?
42
- config.default_formatter = 'doc'
43
- end
44
-
45
- config.profile_examples = 2
46
-
47
- config.order = :random
48
-
49
- Kernel.srand config.seed
50
- end
@@ -1,25 +0,0 @@
1
- RSpec.describe TTY::ProgressBar, '#advance' do
2
- let(:output) { StringIO.new('', 'w+') }
3
-
4
- it "advances by custom value" do
5
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
6
- progress.advance(8)
7
- expect(progress.current).to eq(8)
8
- end
9
-
10
- it "allows to go back" do
11
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
12
- 5.times { progress.advance(1) }
13
- expect(progress.current).to eq(5)
14
- 5.times { progress.advance(-1) }
15
- expect(progress.current).to eq(0)
16
- end
17
-
18
- it "cannot backtrack on finished" do
19
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
20
- 10.times { progress.advance(1) }
21
- expect(progress.current).to eq(10)
22
- 5.times { progress.advance(-1) }
23
- expect(progress.current).to eq(10)
24
- end
25
- end
@@ -1,17 +0,0 @@
1
- RSpec.describe TTY::ProgressBar, 'clear' do
2
- let(:output) { StringIO.new('', 'w+') }
3
-
4
- it "clears progress bar when finished" do
5
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 5,
6
- clear: true)
7
- 5.times { progress.advance }
8
- output.rewind
9
- expect(output.read).to eq([
10
- "\e[1G[= ]",
11
- "\e[1G[== ]",
12
- "\e[1G[=== ]",
13
- "\e[1G[==== ]",
14
- "\e[1G[=====]\e[0m\e[2K\e[1G"
15
- ].join)
16
- end
17
- end
@@ -1,16 +0,0 @@
1
- RSpec.describe TTY::ProgressBar, '#complete?' do
2
- let(:output) { StringIO.new('', 'w+') }
3
-
4
- it "checks for completness" do
5
- progress = TTY::ProgressBar.new("[:bar]", output: output, total: 3)
6
- completes = []
7
- 3.times do
8
- completes << progress.complete?
9
- progress.advance
10
- end
11
- completes << progress.complete?
12
- expect(completes).to eq([
13
- false, false, false, true
14
- ])
15
- end
16
- end
@@ -1,47 +0,0 @@
1
- RSpec.describe TTY::ProgressBar::Converter, '#to_bytes' do
2
- subject(:converter) { described_class }
3
-
4
- it "converts 1000 to bytes" do
5
- expect(converter.to_bytes(1000)).to eq('1000B')
6
- end
7
-
8
- it "converts 1024 to bytes" do
9
- expect(converter.to_bytes(1024)).to eq('1.00KB')
10
- end
11
-
12
- it "converts 1234 to bytes" do
13
- expect(converter.to_bytes(1234)).to eq('1.21KB')
14
- end
15
-
16
- it "converts 12345 to bytes" do
17
- expect(converter.to_bytes(12345)).to eq('12.06KB')
18
- end
19
-
20
- it "converts 2000 to bytes" do
21
- expect(converter.to_bytes(2000)).to eq('1.95KB')
22
- end
23
-
24
- it "converts 1234567 to bytes" do
25
- expect(converter.to_bytes(1234567)).to eq('1.18MB')
26
- end
27
-
28
- it "converts 1234567 to bytes with :separator" do
29
- expect(converter.to_bytes(1234567, separator: ',')).to eq('1,18MB')
30
- end
31
-
32
- it "converts 1234567 to bytes with :unit_separator" do
33
- expect(converter.to_bytes(1234567, unit_separator: ' ')).to eq('1.18 MB')
34
- end
35
-
36
- it "converts 1234567 to bytes with comma as a separator" do
37
- expect(converter.to_bytes(1234567, decimals: 1)).to eq('1.2MB')
38
- end
39
-
40
- it "converts 10_000_000 to bytes" do
41
- expect(converter.to_bytes(10_000_000)).to eq('9.54MB')
42
- end
43
-
44
- it "convert 10_000_000_000 to bytes" do
45
- expect(converter.to_bytes(10_000_000_000)).to eq('9.31GB')
46
- end
47
- end