X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=doc%2Fclasses%2FMCollective%2FRPC%2FProgress.html;fp=doc%2Fclasses%2FMCollective%2FRPC%2FProgress.html;h=12910d0db58c199fb4e4a7fed5ec0c79d5b90088;hb=d1f1649ba43c5cbc43c4beb2380096ba051d646a;hp=0000000000000000000000000000000000000000;hpb=8a3fe7daeecccf43dd71c59371c5005400d35101;p=packages%2Fprecise%2Fmcollective.git diff --git a/doc/classes/MCollective/RPC/Progress.html b/doc/classes/MCollective/RPC/Progress.html new file mode 100644 index 0000000..12910d0 --- /dev/null +++ b/doc/classes/MCollective/RPC/Progress.html @@ -0,0 +1,230 @@ + + + + +
+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. +
++You can specify a size for the progress bar if you want if you dont it will +use the helper functions to figure out terminal dimensions and draw an +appropriately sized bar +
++p = Progress.new 100.times {|i| print +p.twirl(i+1, 100) + "\r"};puts +
++ * [ ==================================================> ] 100 / 100 ++ +
+ # File lib/mcollective/rpc/progress.rb, line 15 +15: def initialize(size=nil) +16: @twirl = ['|', '/', '-', "\\", '|', '/', '-', "\\"] +17: @twirldex = 0 +18: +19: if size +20: @size = size +21: else +22: cols = Util.terminal_dimensions[0] - 22 +23: +24: # Defaults back to old behavior if it +25: # couldn't figure out the size or if +26: # its more than 60 wide +27: if cols <= 0 +28: @size = 0 +29: elsif cols > 60 +30: @size = 60 +31: else +32: @size = cols +33: end +34: end +35: end ++
+ # File lib/mcollective/rpc/progress.rb, line 37 +37: def twirl(current, total) +38: # if the size is negative there is just not enough +39: # space on the terminal, return a simpler version +40: return "\r#{current} / #{total}" if @size == 0 +41: +42: if current == total +43: txt = "\r %s [ " % Util.colorize(:green, "*") +44: else +45: txt = "\r %s [ " % Util.colorize(:red, @twirl[@twirldex]) +46: end +47: +48: dashes = ((current.to_f / total) * @size).round +49: +50: dashes.times { txt << "=" } +51: txt << ">" +52: +53: (@size - dashes).times { txt << " " } +54: +55: txt << " ] #{current} / #{total}" +56: +57: @twirldex == 7 ? @twirldex = 0 : @twirldex += 1 +58: +59: return txt +60: end ++