| Class | MCollective::RPC::Progress |
| In: |
lib/mcollective/rpc/progress.rb
|
| Parent: | Object |
Class that shows a progress bar, currently only supports a twirling progress bar.
p = Progress.new(60) 100.times {|i| print p.twirl(i+1, 100) + "\r"};puts
* [ ==================================================> ] 100 / 100
# File lib/mcollective/rpc/progress.rb, line 11
11: def initialize(size)
12: @twirl = ['|', '/', '-', "\\", '|', '/', '-', "\\"]
13: @twirldex = 0
14: @size = size
15: end
# File lib/mcollective/rpc/progress.rb, line 17
17: def twirl(current, total)
18: if current == total
19: txt = "\r " + Helpers.colorize(:green, "*") + " [ "
20: else
21: txt = "\r #{@twirl[@twirldex]} [ "
22: end
23:
24: dashes = ((current.to_f / total) * @size).round
25:
26: dashes.times { txt << "=" }
27: txt << ">"
28:
29: (@size - dashes).times { txt << " " }
30:
31: txt << " ] #{current} / #{total}"
32:
33: @twirldex == 7 ? @twirldex = 0 : @twirldex += 1
34:
35: return txt
36: end