Sha256: c476cbfd0adc3a0cbce5a55eda12506d16f8abca4b65abef468c291340831164

Contents?: true

Size: 1.49 KB

Versions: 20

Compression:

Stored size: 1.49 KB

Contents

= ANSI::Progressbar

Pretty progress bars are easy to construct.

  require 'ansi/progressbar'

  pbar = ANSI::Progressbar.new("Test Bar", 100)

Running the bar simply requires calling the #inc method during
a loop and calling #finish when done.

  100.times do |i|
    sleep 0.01
    pbar.inc
  end
  pbar.finish

We will use this same rountine in all the examples below, so lets
make a quick macro for it. Notice we have to use #reset first
before reusing the same progress bar.

  def run(pbar)
    pbar.reset
    100.times do |i|
      sleep 0.01
      pbar.inc
    end
    pbar.finish
    puts
  end

The progress bar can be stylized in almost any way.
The #format setter provides control over the parts
that appear on the line. For example, by default the
format is:

  pbar.format("%-14s %3d%% %s %s", :title, :percentage, :bar, :stat)

So lets vary it up to demonstrate the case.

  pbar.format("%-14s %3d%% %s %s", :title, :percentage, :stat, :bar)
  run(pbar)

The progress bar has an extra build in format intended for use with
file downloads called #transer_mode.

  pbar.transfer_mode
  run(pbar)

Calling this methods is the same as calling:

  pbar.format("%-14s %3d%% %s %s",:title, :percentage, :bar, :stat_for_file_transfer)
  run(pbar)

The #style setter allows each part of the line be modified with ANSI codes. And the
#bar_mark writer can be used to change the character used to make the bar.

  pbar.standard_mode
  pbar.style(:title => [:red], :bar=>[:blue])
  pbar.bar_mark = "="
  run(pbar)

QED.

Version data entries

20 entries across 20 versions & 5 rubygems

Version Path
arcabouco-0.2.13 vendor/bundle/gems/ansi-1.4.3/demo/04_progressbar.rdoc
challah-1.0.0 vendor/bundle/gems/ansi-1.4.3/demo/04_progressbar.rdoc
swipe-rails-0.0.5 vendor/bundle/gems/ansi-1.4.3/demo/04_progressbar.rdoc
challah-1.0.0.beta3 vendor/bundle/gems/ansi-1.4.3/demo/04_progressbar.rdoc
challah-1.0.0.beta2 vendor/bundle/gems/ansi-1.4.3/demo/04_progressbar.rdoc
challah-1.0.0.beta vendor/bundle/gems/ansi-1.4.3/demo/04_progressbar.rdoc
challah-0.9.1.beta.3 vendor/bundle/gems/ansi-1.4.3/demo/04_progressbar.rdoc
challah-0.9.1.beta vendor/bundle/gems/ansi-1.4.3/demo/04_progressbar.rdoc
challah-0.9.0 vendor/bundle/gems/ansi-1.4.3/demo/04_progressbar.rdoc
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/ansi-1.4.3/demo/04_progressbar.rdoc
challah-0.8.3 vendor/bundle/gems/ansi-1.4.3/demo/04_progressbar.rdoc
ansi-1.4.3 demo/04_progressbar.rdoc
challah-0.6.1 vendor/bundle/gems/ansi-1.4.2/qed/04_progressbar.rdoc
challah-0.6.0 vendor/bundle/gems/ansi-1.4.2/qed/04_progressbar.rdoc
ansi-1.4.2 qed/04_progressbar.rdoc
ansi-1.4.1 qed/04_progressbar.rdoc
ansi-1.4.0 qed/04_progressbar.rdoc
ansi-1.3.0 qed/04_progressbar.rdoc
ansi-1.2.5 qed/04_progressbar.rdoc
ansi-1.2.4 qed/04_progressbar.rdoc