Class Commander::UI::ProgressBar
In: lib/commander/user_interaction.rb
Parent: Object

Progress Bar

Terminal progress bar utility. In its most basic form requires that the developer specifies when the bar should be incremented. Note that a hash of tokens may be passed to increment, (or returned when using Object#progress).

  uris = %w(
    http://vision-media.ca
    http://yahoo.com
    http://google.com
    )

  bar = Commander::UI::ProgressBar.new uris.length, options
  threads = []
  uris.each do |uri|
    threads << Thread.new do
      begin
        res = open uri
        bar.increment :uri => uri
      rescue Exception => e
        bar.increment :uri => "#{uri} failed"
      end
    end
  end
  threads.each { |t| t.join }

The Object method progress is also available:

  progress uris, :width => 10 do |uri|
    res = open uri
    { :uri => uri } # Can now use :uri within :format option
  end

Methods

Public Class methods

Creates a new progress bar.

Options

  :title              Title, defaults to "Progress"
  :width              Width of :progress_bar
  :progress_str       Progress string, defaults to "="
  :incomplete_str     Incomplete bar string, defaults to '.'
  :format             Defaults to ":title |:progress_bar| :percent_complete% complete "
  :tokens             Additional tokens replaced within the format string
  :complete_message   Defaults to "Process complete"

Tokens

  :title
  :percent_complete
  :progress_bar
  :step
  :steps_remaining
  :total_steps
  :time_elapsed
  :time_remaining

Public Instance methods

Whether or not the operation has completed.

Erase previous terminal line.

Whether or not the operation is complete, and we have finished.

Generates tokens for this step.

Increment progress. Optionally pass tokens which can be displayed in the output format.

Completion percentage.

Formatted progress bar.

Output the progress bar.

Number of steps left.

Time that has elapsed since the operation started.

Estimated time remaining.

[Validate]