256colors2.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env ruby
  2. #
  3. # Translator (ruby): Noah K. Tilton <noah@downbe.at>
  4. # Author (perl>: Todd Larason <jtl@molehill.org>
  5. # use the resources for colors 0-15 - usually more-or-less a
  6. # reproduction of the standard ANSI colors, but possibly more
  7. # pleasing shades
  8. #
  9. # colors 16-231 are a 6x6x6 color cube
  10. 0.upto 6 do |red|
  11. 0.upto 6 do |green|
  12. 0.upto 6 do |blue|
  13. printf "\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\",
  14. 16 + (red * 36) + (green * 6) + blue,
  15. red ? (red * 40 + 55) : 0,
  16. green ? (green * 40 + 55) : 0,
  17. blue ? (blue * 40 + 55) : 0
  18. end
  19. end
  20. end
  21. # colors 232-255 are a grayscale ramp, intentionally leaving out
  22. # black and white
  23. 0.upto 23 do |gray|
  24. level = (gray * 10) + 8
  25. printf("\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\",
  26. 232 + gray, level, level, level);
  27. end
  28. # display the colors
  29. # first the system ones:
  30. print "System colors:\n";
  31. 0.upto 7 do |color|
  32. print "\x1b[48;5;#{color}m ";
  33. end
  34. print "\x1b[0m\n"
  35. 8.upto 15 do |color|
  36. print "\x1b[48;5;#{color}m ";
  37. end
  38. print "\x1b[0m\n\n";
  39. # now the color cube
  40. print "Color cube, 6x6x6:\n";
  41. 0.upto 5 do |green|
  42. 0.upto 5 do |red|
  43. 0.upto 5 do |blue|
  44. color = 16 + (red * 36) + (green * 6) + blue
  45. print "\x1b[48;5;#{color}m ";
  46. end
  47. print "\x1b[0m ";
  48. end
  49. print "\n";
  50. end
  51. # now the grayscale ramp
  52. print "Grayscale ramp:\n";
  53. 232.upto 255 do |color|
  54. print "\x1b[48;5;#{color}m ";
  55. end
  56. print "\x1b[0m\n";