Palette
ansi = ->(fg, bg) { "\e[38;5;#{fg};48;5;#{bg}m" }
col = ->(i=nil) {
case i
when 7,8,10,11,14,15,
41..51, 68..87, 101..123, 133..159,
167..195, 202..231, 244..255
ansi[0, i]
when nil then "\e[0m"
else ansi[15, i]
end
}
range = ->(r) { r.each {|i| print '%s%02x' % [col[i], i] }; puts col[] }
range[(0..15)]; range[(232..255)]
6.times {|i| st = i*36+16; range[i*36+16..st+35] }
puts
Working on a palette generator for terminal and needed to see the 256 color palette. This presents it with the basic 16 + grays + the 6x6.
Found no way to get the full hex out of a 256 color number.. to determine if the color is ’light’ or ‘dark’ (I set foreground by this).. so the light colors are hard-coded in.
The palette generator will use ncurses (because I want to use the mousewheel to set R, G, B) before chroma calculates the palette based on that color.