progressbar 1.8.1 → 1.11.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 (49) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/LICENSE.txt +1 -1
  5. data/README.md +111 -18
  6. data/Rakefile +0 -0
  7. data/lib/progressbar.rb +4 -0
  8. data/lib/ruby-progressbar/base.rb +25 -3
  9. data/lib/ruby-progressbar/calculators/length.rb +15 -3
  10. data/lib/ruby-progressbar/components/bar.rb +7 -1
  11. data/lib/ruby-progressbar/components/rate.rb +1 -1
  12. data/lib/ruby-progressbar/components/time.rb +12 -14
  13. data/lib/ruby-progressbar/format/formatter.rb +1 -1
  14. data/lib/ruby-progressbar/format/molecule.rb +4 -2
  15. data/lib/ruby-progressbar/format/string.rb +3 -3
  16. data/lib/ruby-progressbar/output.rb +14 -7
  17. data/lib/ruby-progressbar/outputs/non_tty.rb +1 -1
  18. data/lib/ruby-progressbar/outputs/null.rb +33 -0
  19. data/lib/ruby-progressbar/outputs/tty.rb +1 -1
  20. data/lib/ruby-progressbar/progress.rb +4 -0
  21. data/lib/ruby-progressbar/refinements.rb +1 -0
  22. data/lib/ruby-progressbar/refinements/enumerator.rb +23 -0
  23. data/lib/ruby-progressbar/time.rb +7 -5
  24. data/lib/ruby-progressbar/timer.rb +1 -1
  25. data/lib/ruby-progressbar/version.rb +1 -1
  26. metadata +50 -97
  27. metadata.gz.sig +0 -0
  28. data/lib/ruby-progressbar/calculators/length_spec.rb +0 -9
  29. data/spec/fixtures/benchmark.rb +0 -28
  30. data/spec/ruby-progressbar/base_spec.rb +0 -949
  31. data/spec/ruby-progressbar/calculators/length_calculator_spec.rb +0 -17
  32. data/spec/ruby-progressbar/calculators/running_average_spec.rb +0 -19
  33. data/spec/ruby-progressbar/components/bar_spec.rb +0 -234
  34. data/spec/ruby-progressbar/components/percentage_spec.rb +0 -9
  35. data/spec/ruby-progressbar/components/rate_spec.rb +0 -9
  36. data/spec/ruby-progressbar/components/throttle_spec.rb +0 -157
  37. data/spec/ruby-progressbar/components/time_spec.rb +0 -307
  38. data/spec/ruby-progressbar/components/title_spec.rb +0 -12
  39. data/spec/ruby-progressbar/format/formatter_spec.rb +0 -9
  40. data/spec/ruby-progressbar/format/molecule_spec.rb +0 -30
  41. data/spec/ruby-progressbar/format/string_spec.rb +0 -9
  42. data/spec/ruby-progressbar/output_spec.rb +0 -7
  43. data/spec/ruby-progressbar/outputs/non_tty_spec.rb +0 -9
  44. data/spec/ruby-progressbar/outputs/tty_spec.rb +0 -9
  45. data/spec/ruby-progressbar/progress_spec.rb +0 -156
  46. data/spec/ruby-progressbar/time_spec.rb +0 -45
  47. data/spec/ruby-progressbar/timer_spec.rb +0 -7
  48. data/spec/spec_helper.rb +0 -6
  49. data/spec/support/time.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 961db6323b945f7b6373152fb44363bfd8a6ac51
4
- data.tar.gz: 379bef4d424ce616f2f7b98e0de4881474d3c636
2
+ SHA256:
3
+ metadata.gz: d5bc49bb14e8635e80a71dd8aae8e6e80d42b1eedda7342c4b3ff975487bd119
4
+ data.tar.gz: af44f894c1ab7d25ae2ce4a4f150bc565e68669aa8f24220cb91e59eb6cb98ae
5
5
  SHA512:
6
- metadata.gz: 45799ecf9e67670603bb0cbeb959508fbe148a30681d07c5dff599b8fb3ee9aefa06d1ac24f42552977b463760340d83724b0d4193297ffa60dcf49654d10084
7
- data.tar.gz: 60430265e9174a0fe0a1484986d956683b8dea789683fb78c7956852bf9c5759b569d6e476ad0c6871084f32ee27ff43fd274a598985722e0d1d870870c6c90d
6
+ metadata.gz: 231ae03f6609373a4dbe57ab1fe4866b03afadc376b6766e00c60c3fde434acc39a69df57f68496d4927285d69437f5573f1a8be608fd2e997e4f9eaa9ee1890
7
+ data.tar.gz: 4efaeb90bd8c1d420a39fc73df3c17d1d3745ccf3f0987528eb9f6750b8fe0b06633ae19a3dd9ec634a55883a1f6271710935e7d10744c409fc0c4eb64f414ed
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2016 The Kompanee, Ltd
1
+ Copyright (c) 2010-2019 The Kompanee, Ltd
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,38 +1,131 @@
1
1
  Ruby/ProgressBar
2
- ================================
3
- [![Gem Version](https://img.shields.io/gem/v/ruby-progressbar.svg)](https://rubygems.org/gems/ruby-progressbar) ![Rubygems Rank Overall](https://img.shields.io/gem/rt/ruby-progressbar.svg) ![Rubygems Rank Daily](https://img.shields.io/gem/rd/ruby-progressbar.svg) ![Rubygems Downloads](https://img.shields.io/gem/dv/ruby-progressbar/stable.svg) [![Build Status](https://img.shields.io/travis/jfelchner/ruby-progressbar/master.svg)](http://travis-ci.org/jfelchner/ruby-progressbar) [![Code Climate](https://codeclimate.com/github/jfelchner/ruby-progressbar.svg)](https://codeclimate.com/github/jfelchner/ruby-progressbar) [![Code Climate](https://codeclimate.com/github/jfelchner/ruby-progressbar/coverage.svg)](https://codeclimate.com/github/jfelchner/ruby-progressbar)
2
+ ================================================================================
4
3
 
5
- <img src="https://www.dropbox.com/s/pe9o1yobxtubof8/ruby-progressbar-cage.png?dl=1" align="right" />
4
+ <div align="center">
5
+ <a href="https://rubygems.org/gems/ruby-progressbar" alt="RubyGems Version">
6
+ <img src="https://img.shields.io/gem/v/ruby-progressbar.svg?style=flat-square&label=current-version" alt="RubyGems Version" />
7
+ </a>
6
8
 
7
- The **ultimate** text progress bar library for Ruby! It'll **SMASH YOU OVER THE HEAD** with a **PURE RUSH** of progress bar excitement!
9
+ <a href="https://rubygems.org/gems/ruby-progressbar" alt="RubyGems Rank Overall">
10
+ <img src="https://img.shields.io/gem/rt/ruby-progressbar.svg?style=flat-square&label=total-rank" alt="RubyGems Rank Overall" />
11
+ </a>
8
12
 
9
- Don't miss out on what all the kids are talking about! If you want everyone to know that your gem or app can survive _in the cage_ then YOU WANT **RUBY-PROGRESSBAR**!
13
+ <a href="https://rubygems.org/gems/ruby-progressbar" alt="RubyGems Rank Daily">
14
+ <img src="https://img.shields.io/gem/rd/ruby-progressbar.svg?style=flat-square&label=daily-rank" alt="RubyGems Rank Daily" />
15
+ </a>
10
16
 
11
- &nbsp;
17
+ <a href="https://rubygems.org/gems/ruby-progressbar" alt="RubyGems Downloads">
18
+ <img src="https://img.shields.io/gem/dt/ruby-progressbar.svg?style=flat-square&label=total-downloads" alt="RubyGems Downloads" />
19
+ </a>
12
20
 
13
- Full Reference
14
- --------------------------------
21
+ <a href="https://github.com/jfelchner/ruby-progressbar/actions?query=workflow%3ABuild" alt="Build Status">
22
+ <img src="https://img.shields.io/github/workflow/status/jfelchner/ruby-progressbar/Build?label=CI&style=flat-square&logo=github" alt="Build Status" />
23
+ </a>
24
+
25
+ <a href="#" alt="Maintainability">
26
+ <img src="https://img.shields.io/codeclimate/maintainability/jfelchner/ruby-progressbar?style=flat-square&label=grade" alt="Maintainability" />
27
+ </a>
28
+ </div>
29
+
30
+ <br>
31
+
32
+ <img src="https://kompanee-public-assets.s3.amazonaws.com/readmes/ruby-progressbar-cage.png" align="right" />
33
+
34
+ The **ultimate** text progress bar library for Ruby! It'll **SMASH YOU OVER THE
35
+ HEAD** with a **PURE RUSH** of progress bar excitement!
36
+
37
+ Don't miss out on what all the kids are talking about! If you want everyone to
38
+ know that your gem or app can survive _in the cage_ then YOU WANT
39
+ **RUBY-PROGRESSBAR**!
40
+
41
+ <br>
42
+
43
+ It's Better Than The Other 186,312 Progress Bar Libraries Because
44
+ --------------------------------------------------------------------------------
45
+
46
+ * It has [stood the test of time][history] (2008-today)
47
+
48
+ * Full test suite
49
+
50
+ * [_**ZERO**_ dependencies][gemspec]
51
+
52
+ * Used by [tons of other open source projects][dependencies] (which means we
53
+ find out about bugs quickly)
54
+
55
+ * It's pretty [freakin' sweet](https://www.youtube.com/watch?v=On3IoVhf_GM)
56
+
57
+ * And most importantly... our awesome [contributors][contributors]
58
+
59
+ Basic Usage
60
+ --------------------------------------------------------------------------------
15
61
 
16
- There's gotten to be too much awesome to pack into one page. Visit the [wiki](https://github.com/jfelchner/ruby-progressbar/wiki) for the full documentation.
62
+ ### Creation
17
63
 
18
- Here's a [quick link](https://github.com/jfelchner/ruby-progressbar/wiki/Basic-Usage) to the 'Basic Usage' section.
64
+ It's simple to get started:
65
+
66
+ ```ruby
67
+ progressbar = ProgressBar.create
68
+ ```
69
+
70
+ Creates a basic progress bar beginning at `0`, a maximum capacity of `100` and
71
+ tells it to start.
72
+
73
+ ```text
74
+ Progress: | |
75
+ ```
76
+
77
+ ### Marking Progress
78
+
79
+ Every call to `#increment` will advance the bar by `1`. Therefore:
80
+
81
+ ```ruby
82
+ 50.times { progressbar.increment }
83
+ ```
84
+
85
+ Would output an advancing line which would end up here:
86
+
87
+ ```text
88
+ Progress: |=================================== |
89
+ ```
90
+
91
+ ### Animation
92
+
93
+ ![Basic Usage Marking Progress](http://kompanee-public-assets.s3.amazonaws.com/readmes/ruby-progressbar-basic-usage-marking-progress-2.gif)
94
+
95
+ Full Reference
96
+ --------------------------------------------------------------------------------
97
+
98
+ There's gotten to be too much awesome to pack into one page. Visit the
99
+ [wiki][wiki] for the full documentation.
19
100
 
20
101
  Issues
21
- --------------------------------
102
+ --------------------------------------------------------------------------------
22
103
 
23
- If you have problems, please create a [Github issue](https://github.com/jfelchner/ruby-progressbar/issues).
104
+ If you have problems, please create a [Github issue][issues].
24
105
 
25
106
  Credits
26
- --------------------------------
107
+ --------------------------------------------------------------------------------
27
108
 
28
- ![The Kompanee](https://www.dropbox.com/s/86jfka1d6bhv8as/kompanee-text-black.png?dl=1)
109
+ ![The Kompanee][kompanee-logo]
29
110
 
30
- ruby-progressbar is maintained by [The Kompanee, Ltd.](http://www.thekompanee.com)
111
+ ruby-progressbar is maintained by [The Kompanee, Ltd.][kompanee-site]
31
112
 
32
113
  The names and logos for The Kompanee are trademarks of The Kompanee, Ltd.
33
114
 
34
115
  License
35
- --------------------------------
116
+ --------------------------------------------------------------------------------
117
+
118
+ ruby-progressbar 1.0 is Copyright &copy; 2011-2021 The Kompanee. It is free
119
+ software, and may be redistributed under the terms specified in the LICENSE
120
+ file.
121
+ ruby-progressbar 0.9.0 is Copyright &copy; 2008 [Satoru Takabayashi][satoru]
36
122
 
37
- ruby-progressbar 1.0 is Copyright &copy; 2011-2016 The Kompanee. It is free software, and may be redistributed under the terms specified in the LICENSE file.
38
- ruby-progressbar 0.9.0 is Copyright &copy; 2008 [Satoru Takabayashi](http://namazu.org/~satoru/)
123
+ [contributors]: https://github.com/jfelchner/ruby-progressbar/graphs/contributors
124
+ [dependencies]: https://github.com/jfelchner/ruby-progressbar/network/dependents
125
+ [gemspec]: https://github.com/jfelchner/ruby-progressbar/blob/master/ruby-progressbar.gemspec
126
+ [history]: https://github.com/jfelchner/ruby-progressbar/wiki/History
127
+ [issues]: https://github.com/jfelchner/ruby-progressbar/issues
128
+ [kompanee-logo]: https://kompanee-public-assets.s3.amazonaws.com/readmes/kompanee-horizontal-black.png
129
+ [kompanee-site]: http://www.thekompanee.com
130
+ [satoru]: http://0xcc.net
131
+ [wiki]: https://github.com/jfelchner/ruby-progressbar/wiki
data/Rakefile CHANGED
File without changes
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'ruby-progressbar/output'
3
4
  require 'ruby-progressbar/outputs/tty'
4
5
  require 'ruby-progressbar/outputs/non_tty'
@@ -10,6 +11,9 @@ require 'ruby-progressbar/calculators/running_average'
10
11
  require 'ruby-progressbar/components'
11
12
  require 'ruby-progressbar/format'
12
13
  require 'ruby-progressbar/base'
14
+ require 'ruby-progressbar/refinements' if Module.
15
+ private_instance_methods.
16
+ include?(:using)
13
17
 
14
18
  class ProgressBar
15
19
  def self.create(*args)
@@ -13,7 +13,7 @@ class Base
13
13
  :progress,
14
14
  :total
15
15
 
16
- def initialize(options = {})
16
+ def initialize(options = {}) # rubocop:disable Metrics/AbcSize
17
17
  self.autostart = options.fetch(:autostart, true)
18
18
  self.autofinish = options.fetch(:autofinish, true)
19
19
  self.finished = false
@@ -37,8 +37,6 @@ class Base
37
37
  end
38
38
 
39
39
  def start(options = {})
40
- clear
41
-
42
40
  timer.start
43
41
  update_progress(:start, options)
44
42
  end
@@ -125,6 +123,30 @@ class Base
125
123
  Format::Formatter.process(@format, output.length, self)
126
124
  end
127
125
 
126
+ # rubocop:disable Metrics/AbcSize, Layout/LineLength
127
+ def to_h
128
+ {
129
+ 'output_stream' => output.__send__(:stream),
130
+ 'length' => output.length,
131
+ 'title' => title_comp.title,
132
+ 'progress_mark' => bar.progress_mark,
133
+ 'remainder_mark' => bar.remainder_mark,
134
+ 'progress' => progressable.progress,
135
+ 'total' => progressable.total,
136
+ 'percentage' => progressable.percentage_completed_with_precision.to_f,
137
+ 'elapsed_time_in_seconds' => time.__send__(:timer).elapsed_seconds,
138
+ 'estimated_time_remaining_in_seconds' => time.__send__(:estimated_seconds_remaining),
139
+ 'base_rate_of_change' => rate.__send__(:base_rate),
140
+ 'scaled_rate_of_change' => rate.__send__(:scaled_rate),
141
+ 'unknown_progress_animation_steps' => bar.upa_steps,
142
+ 'throttle_rate' => output.__send__(:throttle).rate,
143
+ 'started?' => started?,
144
+ 'stopped?' => stopped?,
145
+ 'finished?' => finished?
146
+ }
147
+ end
148
+ # rubocop:enable Metrics/AbcSize, Layout/LineLength
149
+
128
150
  def inspect
129
151
  "#<ProgressBar:#{progress}/#{total || 'unknown'}>"
130
152
  end
@@ -2,10 +2,12 @@ class ProgressBar
2
2
  module Calculators
3
3
  class Length
4
4
  attr_reader :length_override
5
- attr_accessor :current_length
5
+ attr_accessor :current_length,
6
+ :output
6
7
 
7
8
  def initialize(options = {})
8
9
  self.length_override = options[:length]
10
+ self.output = options[:output]
9
11
  self.current_length = nil
10
12
  end
11
13
 
@@ -37,21 +39,25 @@ class Length
37
39
 
38
40
  # This code was copied and modified from Rake, available under MIT-LICENSE
39
41
  # Copyright (c) 2003, 2004 Jim Weirich
42
+ # rubocop:disable Style/RescueStandardError
40
43
  def terminal_width
41
44
  return 80 unless unix?
42
45
 
43
46
  result = dynamic_width
44
- result < 20 ? 80 : result
47
+ (result < 20) ? 80 : result
45
48
  rescue
46
49
  80
47
50
  end
51
+ # rubocop:enable Style/RescueStandardError
48
52
 
49
53
  # rubocop:disable Lint/DuplicateMethods
50
54
  begin
51
55
  require 'io/console'
52
56
 
53
57
  def dynamic_width
54
- if IO.console
58
+ if output && output.tty? && output.respond_to?(:winsize)
59
+ dynamic_width_via_output_stream_object
60
+ elsif IO.console
55
61
  dynamic_width_via_io_object
56
62
  else
57
63
  dynamic_width_via_system_calls
@@ -62,6 +68,12 @@ class Length
62
68
  dynamic_width_via_system_calls
63
69
  end
64
70
  end
71
+ # rubocop:enable Lint/DuplicateMethods
72
+
73
+ def dynamic_width_via_output_stream_object
74
+ _rows, columns = output.winsize
75
+ columns
76
+ end
65
77
 
66
78
  def dynamic_width_via_io_object
67
79
  _rows, columns = IO.console.winsize
@@ -57,7 +57,13 @@ class Bar
57
57
  def complete_bar(length)
58
58
  self.length = length
59
59
 
60
- to_s
60
+ to_s(:format => :standard)
61
+ end
62
+
63
+ def complete_bar_with_percentage(length)
64
+ self.length = length
65
+
66
+ to_s(:format => :integrated_percentage)
61
67
  end
62
68
 
63
69
  def unknown_string
@@ -18,7 +18,7 @@ class Rate
18
18
  private
19
19
 
20
20
  def rate_of_change(format_string = '%i')
21
- return 0 unless elapsed_seconds.positive?
21
+ return 0 unless elapsed_seconds > 0
22
22
 
23
23
  format_string % scaled_rate
24
24
  end
@@ -12,6 +12,10 @@ class Time
12
12
  NO_TIME_ELAPSED_TEXT = '--:--:--'.freeze
13
13
  ESTIMATED_LABEL = ' ETA'.freeze
14
14
  ELAPSED_LABEL = 'Time'.freeze
15
+ OOB_TEXT_TO_FORMAT = {
16
+ :unknown => OOB_UNKNOWN_TIME_TEXT,
17
+ :friendly => OOB_FRIENDLY_TIME_TEXT
18
+ }.freeze
15
19
 
16
20
  def initialize(options = {})
17
21
  self.out_of_bounds_time_format = options[:out_of_bounds_time_format]
@@ -53,8 +57,7 @@ class Time
53
57
 
54
58
  def out_of_bounds_time_format=(format)
55
59
  unless OOB_TIME_FORMATS.include? format
56
- fail 'Invalid Out Of Bounds time format. Valid formats are ' +
57
- OOB_TIME_FORMATS.inspect
60
+ fail StandardError, "Invalid Out Of Bounds time format. Valid formats are #{OOB_TIME_FORMATS.inspect}"
58
61
  end
59
62
 
60
63
  @out_of_bounds_time_format = format
@@ -63,12 +66,14 @@ class Time
63
66
  private
64
67
 
65
68
  def estimated
66
- return OOB_UNKNOWN_TIME_TEXT if progress.unknown? || progress.none? || timer.stopped?
69
+ memo_estimated_seconds_remaining = estimated_seconds_remaining
67
70
 
68
- hours, minutes, seconds = timer.divide_seconds(estimated_seconds_remaining)
71
+ return OOB_UNKNOWN_TIME_TEXT unless memo_estimated_seconds_remaining
72
+
73
+ hours, minutes, seconds = timer.divide_seconds(memo_estimated_seconds_remaining)
69
74
 
70
75
  if hours > OOB_LIMIT_IN_HOURS && out_of_bounds_time_format
71
- out_of_bounds_time
76
+ OOB_TEXT_TO_FORMAT[out_of_bounds_time_format]
72
77
  else
73
78
  TIME_FORMAT % [hours, minutes, seconds]
74
79
  end
@@ -87,16 +92,9 @@ class Time
87
92
  end
88
93
 
89
94
  def estimated_seconds_remaining
90
- (timer.elapsed_seconds * (progress.total / progress.running_average - 1)).round
91
- end
95
+ return if progress.unknown? || progress.none? || timer.stopped? || timer.reset?
92
96
 
93
- def out_of_bounds_time
94
- case out_of_bounds_time_format
95
- when :unknown
96
- OOB_UNKNOWN_TIME_TEXT
97
- when :friendly
98
- OOB_FRIENDLY_TIME_TEXT
99
- end
97
+ (timer.elapsed_seconds * (progress.total / progress.running_average - 1)).round
100
98
  end
101
99
  end
102
100
  end
@@ -13,7 +13,7 @@ class Formatter
13
13
  bar_length = max_length -
14
14
  processed_string.displayable_length +
15
15
  format_string.bar_molecule_placeholder_length
16
- bar_length = bar_length.negative? ? 0 : bar_length
16
+ bar_length = (bar_length < 0) ? 0 : bar_length
17
17
 
18
18
  format_string.bar_molecules.each do |molecule|
19
19
  processed_string.gsub!(molecule.full_key,
@@ -6,6 +6,7 @@ class Molecule
6
6
  :T => [:title_comp, :title],
7
7
  :c => [:progressable, :progress],
8
8
  :C => [:progressable, :total],
9
+ :u => [:progressable, :total_with_unknown_indicator],
9
10
  :p => [:percentage, :percentage],
10
11
  :P => [:percentage, :percentage_with_precision],
11
12
  :j => [:percentage, :justified_percentage],
@@ -16,13 +17,14 @@ class Molecule
16
17
  :f => [:time, :estimated_with_no_oob],
17
18
  :B => [:bar, :complete_bar],
18
19
  :b => [:bar, :bar],
20
+ :W => [:bar, :complete_bar_with_percentage],
19
21
  :w => [:bar, :bar_with_percentage],
20
22
  :i => [:bar, :incomplete_space],
21
23
  :r => [:rate, :rate_of_change],
22
- :R => [:rate, :rate_of_change_with_precision],
24
+ :R => [:rate, :rate_of_change_with_precision]
23
25
  }.freeze
24
26
 
25
- BAR_MOLECULES = %w{w B b i}.freeze
27
+ BAR_MOLECULES = %w{W w B b i}.freeze
26
28
 
27
29
  attr_accessor :key,
28
30
  :method_name
@@ -1,8 +1,8 @@
1
1
  class ProgressBar
2
2
  module Format
3
3
  class String < ::String
4
- MOLECULE_PATTERN = /%[a-zA-Z]/
5
- ANSI_SGR_PATTERN = /\e\[[\d;]+m/
4
+ MOLECULE_PATTERN = /%[a-zA-Z]/.freeze
5
+ ANSI_SGR_PATTERN = /\e\[[\d;]+m/.freeze
6
6
 
7
7
  def displayable_length
8
8
  gsub(ANSI_SGR_PATTERN, '').length
@@ -29,7 +29,7 @@ class String < ::String
29
29
  end
30
30
 
31
31
  molecules
32
- end
32
+ end
33
33
  end
34
34
  end
35
35
  end
@@ -7,12 +7,17 @@ class Output
7
7
  def initialize(options = {})
8
8
  self.bar = options[:bar]
9
9
  self.stream = options[:output] || DEFAULT_OUTPUT_STREAM
10
- self.length_calculator = Calculators::Length.new(options)
11
10
  self.throttle = Throttle.new(options)
11
+ self.length_calculator = Calculators::Length.new(
12
+ :length => options[:length],
13
+ :output => stream
14
+ )
12
15
  end
13
16
 
14
17
  def self.detect(options = {})
15
- if (options[:output] || DEFAULT_OUTPUT_STREAM).tty?
18
+ if options[:output].is_a?(Class) && options[:output] <= ProgressBar::Output
19
+ options[:output].new(options)
20
+ elsif (options[:output] || DEFAULT_OUTPUT_STREAM).tty?
16
21
  Outputs::Tty.new(options)
17
22
  else
18
23
  Outputs::NonTty.new(options)
@@ -47,15 +52,17 @@ class Output
47
52
  end
48
53
  end
49
54
 
50
- def print_and_flush
51
- stream.print bar_update_string + eol
52
- stream.flush
53
- end
54
-
55
55
  protected
56
56
 
57
57
  attr_accessor :length_calculator,
58
58
  :throttle,
59
59
  :bar
60
+
61
+ private
62
+
63
+ def print_and_flush
64
+ stream.print bar_update_string + eol
65
+ stream.flush
66
+ end
60
67
  end
61
68
  end