Friday, December 17, 2010

Ansi color codes in Ruby


#!/usr/bin/ruby
esc="\e["
st=""
x=30
 while x < 38 do
   y=40
   while y < 48 do
     st +=  esc+"#{x};#{y}m #{x};#{y} "
     y+=1
   end
   puts st+esc+"0m\a"
   st=""
   x += 1
 end
puts esc+"0m"



This output's



With a little work I am sure this can be made in to a simple function or library.
or just something you can send with a puts.

No comments: