Sha256: d95b29a10b3f930eb2c14764af18770e852d2eccb875fce12fac169e149c0641

Contents?: true

Size: 1.42 KB

Versions: 2725

Compression:

Stored size: 1.42 KB

Contents

class   ProgressBar
class   Output
  DEFAULT_OUTPUT_STREAM = $stdout

  attr_accessor :stream

  def initialize(options = {})
    self.bar               = options[:bar]
    self.stream            = options[:output] || DEFAULT_OUTPUT_STREAM
    self.throttle          = Throttle.new(options)
    self.length_calculator = Calculators::Length.new(
                               :length => options[:length],
                               :output => stream
                             )
  end

  def self.detect(options = {})
    if options[:output].is_a?(Class) && options[:output] <= ProgressBar::Output
      options[:output].new(options)
    elsif (options[:output] || DEFAULT_OUTPUT_STREAM).tty?
      Outputs::Tty.new(options)
    else
      Outputs::NonTty.new(options)
    end
  end

  def log(string)
    clear
    stream.puts string

    refresh(:force => true) unless bar.stopped?
  end

  def clear_string
    ' ' * length_calculator.length
  end

  def length
    length_calculator.length
  end

  def with_refresh
    yield
    refresh
  end

  def refresh(options = {})
    throttle.choke(:force_update_if => (bar.stopped? || options[:force])) do
      clear if length_calculator.length_changed?

      print_and_flush
    end
  end

  protected

  attr_accessor :length_calculator,
                :throttle,
                :bar

  private

  def print_and_flush
    stream.print bar_update_string + eol
    stream.flush
  end
end
end

Version data entries

2,725 entries across 2,675 versions & 44 rubygems

Version Path
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/ruby-progressbar-1.10.1/lib/ruby-progressbar/output.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/ruby-progressbar-1.10.1/lib/ruby-progressbar/output.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/ruby-progressbar-1.10.1/lib/ruby-progressbar/output.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/ruby-progressbar-1.10.1/lib/ruby-progressbar/output.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/ruby-progressbar-1.10.1/lib/ruby-progressbar/output.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/ruby-progressbar-1.10.1/lib/ruby-progressbar/output.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/ruby-progressbar-1.10.1/lib/ruby-progressbar/output.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/ruby-progressbar-1.10.1/lib/ruby-progressbar/output.rb
kinetic_sdk-0.1.1 gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/output.rb
progressbar-1.10.1 lib/ruby-progressbar/output.rb
ruby-progressbar-1.10.1 lib/ruby-progressbar/output.rb
cspeezy_palindrome-0.3.0 path/ruby/2.6.0/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/output.rb
cspeezy_palindrome-0.2.0 path/ruby/2.6.0/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/output.rb
cspeezy_palindrome-0.1.0 path/ruby/2.6.0/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/output.rb
steenfest_palindrome-0.1.2 ruby/2.5/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/output.rb
steenfest_palindrome-0.1.1b ruby/2.5/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/output.rb
nullifyable-0.1.0 vendor/bundle/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/output.rb
dmurphy_palindrome-0.1.0 vendor/cache/ruby/2.3.0/gems/dmurphy_palindrome-0.1.0/vendor/cache/ruby/2.3.0/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/output.rb
dmurphy_palindrome-0.1.0 vendor/cache/ruby/2.3.0/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/output.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/output.rb