Skip to content

Instantly share code, notes, and snippets.

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 =>,
:width => columns,
:label => "Performing Operation...",
:color => "yellow"} #color defaults to white
# 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... ")
Formatador.redisplay_progressbar(current, total, options)
puts "\nOperation complete.\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.