class ProgressBar::Output

Constants

DEFAULT_OUTPUT_STREAM

Attributes

bar[RW]
length_calculator[RW]
stream[RW]
throttle[RW]

Public Class Methods

detect(options = {}) click to toggle source
# File lib/ruby-progressbar/output.rb, line 17
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
new(options = {}) click to toggle source
# File lib/ruby-progressbar/output.rb, line 7
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

Public Instance Methods

clear_string() click to toggle source
# File lib/ruby-progressbar/output.rb, line 34
def clear_string
  ' ' * length_calculator.length
end
length() click to toggle source
# File lib/ruby-progressbar/output.rb, line 38
def length
  length_calculator.length
end
log(string) click to toggle source
# File lib/ruby-progressbar/output.rb, line 27
def log(string)
  clear
  stream.puts string

  refresh(:force => true) unless bar.stopped?
end
refresh(options = {}) click to toggle source
# File lib/ruby-progressbar/output.rb, line 47
def refresh(options = {})
  throttle.choke(:force_update_if => (bar.stopped? || options[:force])) do
    clear if length_calculator.length_changed?

    print_and_flush
  end
end
with_refresh() { || ... } click to toggle source
# File lib/ruby-progressbar/output.rb, line 42
def with_refresh
  yield
  refresh
end

Private Instance Methods

print_and_flush() click to toggle source