Instantly share code, notes, and snippets.

Embed
What would you like to do?
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