Created
May 8, 2014 02:33
-
-
Save st44100/95b15cce2c74ef25ac15 to your computer and use it in GitHub Desktop.
Print terminal color using coffee-script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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" |
Author
st44100
commented
May 8, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment