Skip to content

Instantly share code, notes, and snippets.

@st44100
Created May 8, 2014 02:33
Show Gist options
  • Save st44100/95b15cce2c74ef25ac15 to your computer and use it in GitHub Desktop.
Save st44100/95b15cce2c74ef25ac15 to your computer and use it in GitHub Desktop.
Print terminal color using coffee-script
#
# termcolor.pl : http://h2plus.biz/hiromitsu/entry/674
#
# Usage:
# > coffee termcolor.coffee
#
sys = require "sys"
fg = "\x1b[38;5;"
bg = "\x1b[48;5;"
rs = "\x1b[0m"
color = 0
pad = (str) ->
len = "#{str}".length
base = "000"
if len > 3 then "" else base.substr(0, 3 - len) + str
getColor = (color)->
number = pad(color)
"#{bg}#{color}m #{number}#{rs}#{fg}#{color}m #{number}#{rs}"
for row in [0..32]
for col in [0..8]
sys.print getColor(color)
color++
sys.print "\n"
@st44100
Copy link
Author

st44100 commented May 8, 2014

termcolor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment