term2html/test.rb

120 lines
2.6 KiB
Ruby

#!/usr/bin/ruby
puts "Printing truecolor table:"
def colors(r)
for i in r do
printf("\e[48;5;%dm%03d", i, i);
end
printf("\e[0m \n");
end
colors 0..15
for i in 0..5 do
colors (i*36+16)..(i*36+51)
end
colors 232..255
print "\n\n"
# -----------------------------------------------------------------------
def truecolor(i)
if (i >= 0 && i <= 7) then
return "4#{i}";
elsif (i >= 8 && i <= 15) then
i -= 8;
return "10#{i}";
elsif (i >= 16 && i <= 231) then
i -= 16;
r = g = b = 0
ri = (i / 36) % 6;
r = ri == 0 ? 0 : (0x37 + (ri*0x28));
gi = (i / 6) % 6;
g = gi == 0 ? 0 : (0x37 + (gi*0x28));
bi = i % 6;
b = bi==0 ? 0 : (0x37 + (bi*0x28));
return "48;2;#{r};#{g};#{b}"
elsif (i >= 232 && i <= 255) then
i -= 232;
c = i * 10;
return "48;2;#{c};#{c};#{c}";
end
end
def truecolor_old(i)
if (i >= 0 && i <= 7) then
return "4#{i}";
elsif (i >= 8 && i <= 15) then
i -= 8;
return "10#{i}";
elsif (i >= 16 && i <= 231) then
j = i - 16
r = (((j / 6) / 6) % 6) * 0x33
g = ((j / 6) % 6) * 0x33
b = (j % 6) * 0x33
return "48;2;#{r};#{g};#{b}"
elsif (i >= 232 && i <= 255) then
j = i - 232
c = j * (256 / 24)
return "48;2;#{c};#{c};#{c}";
end
end
def colors2(r, factory)
for i in r do
c = method(factory).call(i);
printf("\e[%sm%03d", c, i);
end
printf("\e[0m \n");
end
colors2 0..15, :truecolor
for i in 0..5 do
colors2 (i*36+16)..(i*36+51), :truecolor
end
colors2 232..255, :truecolor
print "\n\n"
#colors2 0..15, :truecolor_old
#for i in 0..5 do
# colors2 (i*36+16)..(i*36+51), :truecolor_old
#end
#colors2 232..255, :truecolor_old
#print "\n\n"
# -----------------------------------------------------------------------
=begin
puts "Printing truecolor table:"
for i in (0..255) do
print "\033[38;5;#{i}m" + i.to_s.rjust(3, ' ') + ' '
puts "" if (i % 21 == 20)
end
print "\n\n"
puts "Trying to simulate truecolor table:"
for i in (0..7) do
print "\033[3#{i}m" + i.to_s.rjust(3, ' ') + ' '
end
for i in (8..15) do
print "\033[9#{i - 8}m" + i.to_s.rjust(3, ' ') + ' '
end
for i in (16..231) do
j = i - 16
#r = (((j / 6) / 6) % 6) * 0xCC
#g = ((j / 6) % 6) * 0x3A
r = g = 0
b = (j % 6) * 0x5F
print "\033[38;2;#{r};#{g};#{b}m" + i.to_s.rjust(3, ' ') + ' '
puts "" if (i % 21 == 20)
end
for i in (232..255) do
j = i - 232
c = j * (256 / 24)
print "\033[38;2;#{c};#{c};#{c}m" + i.to_s.rjust(3, ' ') + ' '
puts "" if (i % 21 == 20)
end
=end