class ProgressBar::Output

def self.detect(options = {})

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 clear_string

def clear_string
  ' ' * length_calculator.length
end

def initialize(options = {})

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 length

def length
  length_calculator.length
end

def log(string)

def log(string)
  clear
  stream.puts string
  refresh(:force => true) unless bar.stopped?
end

def print_and_flush

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

def refresh(options = {})

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

def with_refresh

def with_refresh
  yield
  refresh
end