Sha256: a542f83acc5f1bb77f91f6524091e2680ccfa5b286dce9ff796d86f3a79f22e4

Contents?: true

Size: 1.5 KB

Versions: 4017

Compression:

Stored size: 1.5 KB

Contents

require 'ruby-progressbar/calculators/length'
require 'ruby-progressbar/throttle'

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

4,017 entries across 4,017 versions & 27 rubygems

Version Path
cybrid_api_organization_ruby-0.122.57 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_id_ruby-0.122.54 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_bank_ruby-0.122.54 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_organization_ruby-0.122.54 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_bank_ruby-0.122.53 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_organization_ruby-0.122.53 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_id_ruby-0.122.53 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_id_ruby-0.122.52 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_bank_ruby-0.122.52 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_organization_ruby-0.122.52 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_bank_ruby-0.122.51 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_organization_ruby-0.122.51 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_id_ruby-0.122.51 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_bank_ruby-0.122.49 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_id_ruby-0.122.49 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_organization_ruby-0.122.49 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_bank_ruby-0.122.48 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_id_ruby-0.122.48 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_organization_ruby-0.122.48 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb
cybrid_api_bank_ruby-0.122.47 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/output.rb