### Home Classes Methods

### In Files

- lib/mcollective/rpc/progress.rb

### Parent

Object

### Methods

- ::new
- #twirl

### Files

- COPYING
- README
- Rakefile
- PLACEHOLDER
- PLACEHOLDER

### Class/Module Index

Quicksearch

- MCollective
- MCollective::Agent
- MCollective::Agents
- MCollective::Aggregate
- MCollective::Aggregate::Base
- MCollective::Aggregate::Result
- MCollective::Aggregate::Result::Base
- MCollective::Aggregate::Result::CollectionResult
- MCollective::Aggregate::Result::NumericResult
- MCollective::Application
- MCollective::Applications
- MCollective::Client
- MCollective::Config
- MCollective::Connector
- MCollective::Connector::Base
- MCollective::DDL
- MCollective::DDLValidationError
- MCollective::Data
- MCollective::Data::Base
- MCollective::Data::Result
- MCollective::Discovery
- MCollective::Facts
- MCollective::Facts::Base
- MCollective::Generators
- MCollective::Generators::AgentGenerator
- MCollective::Generators::Base
- MCollective::Generators::DataGenerator
- MCollective::InvalidRPCData
- MCollective::Log
- MCollective::Logger
- MCollective::Logger::Base
- MCollective::Logger::Console_logger
- MCollective::Logger::File_logger
- MCollective::Logger::Syslog_logger
- MCollective::Matcher
- MCollective::Matcher::Parser
- MCollective::Matcher::Scanner
- MCollective::Message
- MCollective::MissingRPCData
- MCollective::MsgDoesNotMatchRequestID
- MCollective::MsgTTLExpired
- MCollective::NotTargettedAtUs
- MCollective::Optionparser
- MCollective::PluginManager
- MCollective::PluginPackager
- MCollective::PluginPackager::AgentDefinition
- MCollective::PluginPackager::StandardDefinition
- MCollective::RPC
- MCollective::RPC::ActionRunner
- MCollective::RPC::Agent
- MCollective::RPC::Audit
- MCollective::RPC::Client
- MCollective::RPC::Helpers
- MCollective::RPC::Progress
- MCollective::RPC::Reply
- MCollective::RPC::Request
- MCollective::RPC::Result
- MCollective::RPC::Stats
- MCollective::RPCAborted
- MCollective::RPCError
- MCollective::Registration
- MCollective::Registration::Base
- MCollective::Runner
- MCollective::RunnerStats
- MCollective::SSL
- MCollective::Security
- MCollective::Security::Base
- MCollective::SecurityValidationFailed
- MCollective::Shell
- MCollective::UnixDaemon
- MCollective::UnknownRPCAction
- MCollective::UnknownRPCError
- MCollective::Util
- MCollective::WindowsDaemon
- Array
- Dir
- Object
- String
- Symbol

No matching classes.

# MCollective::RPC::Progress

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

### Public Instance Methods

twirl(current, total) click to toggle source

    # File lib/mcollective/rpc/progress.rb, line 37
    def twirl(current, total)
      # if the size is negative there is just not enough
      # space on the terminal, return a simpler version
      return "\r#{current} / #{total}" if @size == 0

      if current == total
        txt = "\r %s [" % Util.colorize(:green, "*")
      else
        txt = "\r %s [" % Util.colorize(:red, @twirl[@twirldex])
      end

      dashes = ((current.to_f / total) * @size).round

      dashes.times { txt << "=" }
      txt << ">"

      (@size - dashes).times { txt << " " }

      txt << " ] #{current} / #{total}"

      @twirldex == 7 ? @twirldex = 0 : @twirldex += 1

      return txt
    end

### Public Class Methods

new(size=nil) click to toggle source

    # File lib/mcollective/rpc/progress.rb, line 15
    def initialize(size=nil)
      @twirl = ['|', '/', '-', "\\", '|', '/', '-', "\\"]
      @twirldex = 0

      if size
        @size = size
      else
        cols = Helpers.terminal_dimensions[0] - 22

        # Defaults back to old behavior if it
        # couldn't figure out the size or if
        # its more than 60 wide
        if cols <= 0
          @size = 0
        elsif cols > 60
          @size = 60
        else
          @size = cols
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.