Class: Kafo::ProgressBar

Inherits:
Object
  • Object
show all
Defined in:
lib/kafo/progress_bar.rb

Overview

change more methods like #done_message or #print_error

Instance Method Summary collapse

Constructor Details

#initializeProgressBar

Returns a new instance of ProgressBar.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/kafo/progress_bar.rb', line 12

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

Instance Method Details

#closeObject



37
38
39
40
41
42
# File 'lib/kafo/progress_bar.rb', line 37

def close
  @bar.show({ :msg   => done_message,
              :done  => @total == :unknown ? @bar.done + 1 : @total,
              :total => @total }, true)
  @bar.close
end


44
45
46
# File 'lib/kafo/progress_bar.rb', line 44

def print(line)
  @bar.print line
end


48
49
50
# File 'lib/kafo/progress_bar.rb', line 48

def print_error(line)
  print line
end

#update(line) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kafo/progress_bar.rb', line 24

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