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

Constant Summary collapse

MONITOR_RESOURCE =
%r{\w*MONITOR_RESOURCE ([^\]]+\])}
EVALTRACE_START =
%r{/(.+\]): Starting to evaluate the resource}
EVALTRACE_END =
%r{/(.+\]): Evaluated in [\d\.]+ seconds}
PREFETCH =
%r{Prefetching .* resources for}

Instance Method Summary collapse

Constructor Details

#initializeProgressBar

Returns a new instance of ProgressBar.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kafo/progress_bar.rb', line 18

def initialize
  @lines                                    = 0
  @all_lines                                = 0
  @total                                    = :unknown
  @resources                                = Set.new
  @term_width                               = HighLine::SystemExtensions.terminal_size[0] || 0
  @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



71
72
73
74
75
76
# File 'lib/kafo/progress_bar.rb', line 71

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


78
79
80
# File 'lib/kafo/progress_bar.rb', line 78

def print(line)
  @bar.print line
end


82
83
84
# File 'lib/kafo/progress_bar.rb', line 82

def print_error(line)
  print line
end

#update(line) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/kafo/progress_bar.rb', line 32

def update(line)
  @all_lines += 1

  # we print every 20th line during installation preparing otherwise only update at EVALTRACE_START
  update_bar = (@total == :unknown && @all_lines % 20 == 0)
  force_update = false

  if (line_monitor = MONITOR_RESOURCE.match(line))
    @resources << line_monitor[1]
    @total = (@total == :unknown ? 1 : @total + 1)
  end

  if (line_start = EVALTRACE_START.match(line))
    if (known_resource = find_known_resource(line_start[1]))
      line = known_resource
      update_bar = true
      force_update = true
    end
  end

  if (line_end = EVALTRACE_END.match(line)) && @lines < @total
    if (known_resource = find_known_resource(line_end[1]))
      @resources.delete(known_resource)  # ensure it's only counted once
      @lines += 1
    end
  end

  if PREFETCH =~ line
    update_bar = true
    force_update = true
  end

  if update_bar
    @bar.show({ :msg   => format(line),
                :done  => @lines,
                :total => @total }, force_update)
  end
end