class Kafo::ProgressBar

Progress bar base class

To define new progress bar you can inherit from this class and implement finite_template and infinite_template methods. Also you may find useful to change more methods like done_message or print_error

Public Class Methods

new() click to toggle source
# File lib/kafo/progress_bar.rb, line 11
def initialize
  @lines                                    = 0
  @all_lines                                = 0
  @total                                    = :unknown
  @bar                                      = PowerBar.new
  @bar.settings.tty.infinite.template.main  = infinite_template
  @bar.settings.tty.finite.template.main    = finite_template
  @bar.settings.tty.finite.template.padchar = ' '
  @bar.settings.tty.finite.template.barchar = '.'
  @bar.settings.tty.finite.output           = Proc.new { |s| $stderr.print s }
end

Public Instance Methods

close() click to toggle source
# File lib/kafo/progress_bar.rb, line 36
def close
  @bar.show({ :msg   => done_message,
              :done  => @total == :unknown ? @bar.done + 1 : @total,
              :total => @total }, true)
  @bar.close
end
print(line) click to toggle source
print_error(line) click to toggle source
update(line) click to toggle source
# File lib/kafo/progress_bar.rb, line 23
def update(line)
  @total     = $1.to_i if line =~ /\w*START (\d+)/
  @lines     += 1 if line.include?('RESOURCE') && @lines < @total - 1
  @all_lines += 1

  # we print every 20th line during installation preparing otherwise we update every line
  if @all_lines % 20 == 0 || @total != :unknown
    @bar.show({ :msg   => format(line),
                :done  => @lines,
                :total => @total })
  end
end

Private Instance Methods

done_message() click to toggle source
# File lib/kafo/progress_bar.rb, line 53
def done_message
  text = 'Done'
  text + (' ' * (50 - text.length))
end
finite_template() click to toggle source
# File lib/kafo/progress_bar.rb, line 62
def finite_template
  'Installing... [${<percent>%}]'
end
format(line) click to toggle source
# File lib/kafo/progress_bar.rb, line 58
def format(line)
  (line.tr("\r\n", '') + (' ' * 50))[0..49]
end
infinite_template() click to toggle source
# File lib/kafo/progress_bar.rb, line 66
def infinite_template
  'Installing...'
end