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 14
def self.detect(options = {})
  if (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.length_calculator = Calculators::Length.new(options)
  self.throttle          = Throttle.new(options)
end

Public Instance Methods

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

  refresh(:force => true) unless bar.stopped?
end
print_and_flush() click to toggle source
refresh(options = {}) click to toggle source
# File lib/ruby-progressbar/output.rb, line 42
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 37
def with_refresh
  yield
  refresh
end