Skip to content

Instantly share code, notes, and snippets.

@b1nary
Last active October 6, 2015 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b1nary/2991673 to your computer and use it in GitHub Desktop.
Save b1nary/2991673 to your computer and use it in GitHub Desktop.
NixColor - Yet another 255 Ansi colors for ruby gem
Gem::Specification.new do |s|
s.name = 'nixcolor'
s.version = '0.0.2'
s.date = '2012-05-30'
s.summary = "Unix (Ansi) color gem"
s.description = "Yet another 255 Ansi colors for ruby gem"
s.authors = ["Roman Pramberger"]
s.email = '*@gmail.com'
s.files = ["lib/nixcolor.rb"]
s.homepage = 'http://rubygems.org/gems/nixcolor'
end
class NixColor
##
# Generate rgb colors
def self.rgb(red, green, blue)
16 + (red * 36) + (green * 6) + blue
end
##
# set background to color
def self.bg color
"\x1b[48;5;#{color}m"
end
##
# set foreground to color
def self.fg color
"\x1b[38;5;#{color}m"
end
##
# lazy background "shortcut"
def self.background color
self.bg color
end
##
# lazy foreground "shortcut"
def self.foreground color
self.fg color
end
##
# Clear terminal from colors
def self.clear_color
"\x1b[0m"
end
##
# Clear screen and reset cursor
def self.clear
"\e[2J\e[1;1H"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment