Skip to content

Instantly share code, notes, and snippets.

@manewitz manewitz/color_demo.rb
Last active Oct 12, 2015

Embed
What would you like to do?
Formatador Presentation
#! /usr/bin/env ruby
require "rubygems"
require "formatador"
styles = [
:bold,
:underline,
:blink_slow,
:blink_fast,
:negative,
:normal,
:underline_none,
:blink_off,
:positive,
:black,
:red,
:green,
:yellow,
:blue,
:magenta,
:purple,
:cyan,
:white,
:_black_,
:_red_,
:_green_,
:_yellow_,
:_blue_,
:_magenta_,
:_purple_,
:_cyan_,
:_white_,
:light_black,
:light_red,
:light_green,
:light_yellow,
:light_blue,
:light_magenta,
:light_purple,
:light_cyan,
:_light_black_,
:_light_red_,
:_light_green_,
:_light_yellow_,
:_light_blue_,
:_light_magenta_,
:_light_purple_,
:_light_cyan_,
]
styles.each do |tag|
puts Formatador.display_line("[#{tag}]This is the \"#{tag}\" tag. [/]")
end
puts
puts
puts Formatador.display_line("[green]Are you [/][bold]SURE[/][green] you want to[/] [red]DESTROY ALL THE THINGS?[/]")
#! /usr/bin/env ruby
require "rubygems"
require "rake"
require "formatador"
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
}
# 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
puts "Operation complete."
puts
#! /usr/bin/env ruby
require "rubygems"
require "formatador"
# take a bunch of objects
# bunch_of_hashes = objects.map(&:attributes)
bunch_of_hashes =
[{:server_id=>nil, :tags=>{}, :id=>"vol-2de35c50", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1c", :state=>"available", :created_at=>"2012-10-22 14:32:53 UTC"}, {:server_id=>nil, :tags=>{}, :id=>"vol-2ee35c53", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1c", :state=>"available", :created_at=>"2012-10-22 14:32:54 UTC"}, {:server_id=>nil, :tags=>{}, :id=>"vol-2be35c56", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1d", :state=>"available", :created_at=>"2012-10-22 14:32:54 UTC"}, {:server_id=>nil, :tags=>{}, :id=>"vol-24e35c59", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1c", :state=>"available", :created_at=>"2012-10-22 14:32:54 UTC"}, {:server_id=>nil, :tags=>{}, :id=>"vol-21e35c5c", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1c", :state=>"available", :created_at=>"2012-10-22 14:32:54 UTC"}, {:server_id=>nil, :tags=>{}, :id=>"vol-22e35c5f", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1d", :state=>"available", :created_at=>"2012-10-22 14:32:54 UTC"}, {:server_id=>nil, :tags=>{}, :id=>"vol-1fe35c62", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1c", :state=>"available", :created_at=>"2012-10-22 14:32:54 UTC"}, {:server_id=>nil, :tags=>{}, :id=>"vol-18e35c65", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1c", :state=>"available", :created_at=>"2012-10-22 14:32:54 UTC"}, {:server_id=>nil, :tags=>{}, :id=>"vol-15e35c68", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1c", :state=>"available", :created_at=>"2012-10-22 14:32:54 UTC"}, {:server_id=>nil, :tags=>{}, :id=>"vol-16e35c6b", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1c", :state=>"available", :created_at=>"2012-10-22 14:32:54 UTC"}, {:server_id=>nil, :tags=>{}, :id=>"vol-13e35c6e", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1c", :state=>"available", :created_at=>"2012-10-22 14:32:54 UTC"}, {:server_id=>nil, :tags=>{}, :id=>"vol-07e35c7a", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1c", :state=>"available", :created_at=>"2012-10-22 14:32:54 UTC"}, {:server_id=>nil, :tags=>{}, :id=>"vol-fee35c83", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1c", :state=>"available", :created_at=>"2012-10-22 14:32:55 UTC"}, {:server_id=>nil, :tags=>{}, :id=>"vol-fbe35c86", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1c", :state=>"available", :created_at=>"2012-10-22 14:32:55 UTC"}, {:server_id=>nil, :tags=>{}, :id=>"vol-f4e35c89", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1c", :state=>"available", :created_at=>"2012-10-22 14:32:55 UTC"}, {:server_id=>nil, :tags=>{}, :id=>"vol-f2e35c8f", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1c", :state=>"available", :created_at=>"2012-10-22 14:32:55 UTC"}, {:server_id=>nil, :tags=>{}, :id=>"vol-c4e35cb9", :size=>15, :snapshot_id=>"oh-snap-42-omfg", :availability_zone=>"us-east-1c", :state=>"available", :created_at=>"2012-10-22 14:32:59 UTC"}]
p bunch_of_hashes
gets
puts
Formatador.display_table(bunch_of_hashes)
gets
puts
Formatador.display_compact_table(bunch_of_hashes)
puts
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.