Convert nice html color codes into terminal colors
e.g. to make ruco colorful ๐
COLOR_SOURCE_VALUES = 256
COLOR_TARGET_VALUES = 5
COLOR_DIVIDE = COLOR_SOURCE_VALUES / COLOR_TARGET_VALUES
TERM_COLOR_BASE = 16
# '#ff0000' => 196
def self.html_to_terminal_color(html_color)
return unless html_color
r = (html_color[1..2].to_i(16) / COLOR_DIVIDE) * 36
g = (html_color[3..4].to_i(16) / COLOR_DIVIDE) * 6
b = (html_color[5..6].to_i(16) / COLOR_DIVIDE) * 1
TERM_COLOR_BASE + r + g + b
end
Hi Michael,
in paint, I am using a version that also calculates gray scales:
https://github.com/janlelis/paint/blob/master/lib/paint.rb#L222
However, the basic principle is the same ๐
btw: ruco with colors – yeah ๐
Damn, google did not find it ๐