Class: Kafo::ProgressBar
- Inherits:
-
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
Returns a new instance of ProgressBar.
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/kafo/progress_bar.rb', line 19
def initialize
@lines = 0
@all_lines = 0
@total = :unknown
@resources = Set.new
@term_width = terminal_width
@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
#close ⇒ Object
72
73
74
75
76
77
|
# File 'lib/kafo/progress_bar.rb', line 72
def close
@bar.show({ :msg => done_message,
:done => (@total == :unknown) ? @bar.done + 1 : @total,
:total => @total }, true)
@bar.close
end
|
#print(line) ⇒ Object
79
80
81
|
# File 'lib/kafo/progress_bar.rb', line 79
def print(line)
@bar.print line
end
|
#print_error(line) ⇒ Object
83
84
85
|
# File 'lib/kafo/progress_bar.rb', line 83
def print_error(line)
print line
end
|
#update(line) ⇒ Object
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
70
|
# File 'lib/kafo/progress_bar.rb', line 33
def update(line)
@all_lines += 1
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)) && @total != :unknown && @lines < @total
if (known_resource = find_known_resource(line_end[1]))
@resources.delete(known_resource) @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
|