Skip to content

Instantly share code, notes, and snippets.

@manewitz
Created July 24, 2012 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manewitz/3172179 to your computer and use it in GitHub Desktop.
Save manewitz/3172179 to your computer and use it in GitHub Desktop.
Formatador Progress Bar Example
# This is an example of using the progress bar feature of Formatador.
require "rubygems"
require "formatador"
require "rake"
current = 0
total = 100
# get terminal width
columns = Rake.application.terminal_width * 0.5
options = {:started_at => Time.now,
:width => columns,
:label => "Performing Operation...",
:color => "yellow"} #color defaults to white
puts
# Dummy task to simulate a batch process
total.times do |n|
sleep 0.1
current +=1
# change appearance when 75% complete
if (current.to_f / total.to_f) >= 0.75
options.merge!(:color => 'green', :label => "Finishing up... ")
end
Formatador.redisplay_progressbar(current, total, options)
end
puts "\nOperation complete.\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment