Created
July 24, 2012 19:42
-
-
Save manewitz/3172179 to your computer and use it in GitHub Desktop.
Formatador Progress Bar Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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