Sha256: e05f1185529af8b403e54a2050e02e433d77e7d5ca971c3a9cd6c00830128bfb

Contents?: true

Size: 1.06 KB

Versions: 10

Compression:

Stored size: 1.06 KB

Contents

module Vagrant
  module Util
    # A mixin which allows any class to be able to show a "progress meter"
    # to standard out. The progress meter shows the progress of an operation
    # with console-animated text in stdout.
    module ProgressMeter
      # Updates the progress meter with the given progress amount and total.
      # This method will do the math to figure out a percentage and show it
      # within stdout.
      #
      # @param [Float] progress Progress
      # @param [Float] total Total
      def update_progress(progress, total, show_parts=true)
        percent = (progress.to_f / total.to_f) * 100
        print "#{cl_reset}Progress: #{percent.to_i}%"
        print " (#{progress} / #{total})" if show_parts
        $stdout.flush
      end

      # Completes the progress meter by resetting it off of the screen.
      def complete_progress
        # Just clear the line back out
        print "#{cl_reset}"
      end

      def cl_reset
        reset = "\r"
        reset += "\e[0K" unless Mario::Platform.windows?
        reset
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
vagrantup-0.3.4 lib/vagrant/util/progress_meter.rb
vagrantup-0.3.3 lib/vagrant/util/progress_meter.rb
vagrantup-0.3.2 lib/vagrant/util/progress_meter.rb
vagrantup-0.3.1 lib/vagrant/util/progress_meter.rb
vagrantup-0.3.0 lib/vagrant/util/progress_meter.rb
vagrant-0.3.4 lib/vagrant/util/progress_meter.rb
vagrant-0.3.3 lib/vagrant/util/progress_meter.rb
vagrant-0.3.2 lib/vagrant/util/progress_meter.rb
vagrant-0.3.1 lib/vagrant/util/progress_meter.rb
vagrant-0.3.0 lib/vagrant/util/progress_meter.rb