Last active
October 6, 2015 12:08
-
-
Save b1nary/2991673 to your computer and use it in GitHub Desktop.
NixColor - Yet another 255 Ansi colors for ruby gem
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
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 |
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
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