Skip to content

Instantly share code, notes, and snippets.

@uberbuilder
Created March 31, 2013 04:49
Show Gist options
  • Save uberbuilder/5279590 to your computer and use it in GitHub Desktop.
Save uberbuilder/5279590 to your computer and use it in GitHub Desktop.
Terminal/Command Line Color Sampler
#!/usr/bin/perl
# Author: Jeremy Iglehart <jeremy@uberbuilder.com>
# --- Modified Terminal/Command Line Color Sampler :: v1.0 2013-03-30 23:59:02 ---
# Here's The Original Author Info:
#
# Original Author: Todd Larason <jtl@molehill.org>
# $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.1 1999/07/11 08:49:54 dawes Exp $
$colorBlockTextForegroundIsNowDark = 0;
print "256 Color Mode Test and Color Code Sampler\n\n";
# display back ground colors
for ($fgbg = 38; $fgbg <= 48; $fgbg +=10) {
# first the system ones:
print "\033[48;5;13m\033[38;5;0mSystem colors:\033[0m\n";
print "\033[38;5;5m\033[48;5;0mNormal Weight:\033[0m\n";
for ($color = 0; $color < 8; $color++) {
print "\x1b[${fgbg};5;${color}m";
print " \\033[${fgbg};5;${color}m ";
# If the color number is two digits instead of one add a space
if ($color < 10) {
print " ";
}
}
print "\x1b[0m\n";
print "\033[38;5;13m\033[48;5;0mHeavy Weight:\033[0m\n";
for ($color = 8; $color < 16; $color++) {
print "\x1b[${fgbg};5;${color}m";
print " \\033[${fgbg};5;${color}m ";
# If the color number is two digits instead of one add a space
if ($color < 10) {
print " ";
}
}
print "\x1b[0m\n\n";
# now the color cube
print "\033[48;5;13m\033[38;5;0mColor cube, 6x6x6:\033[48;5;0m\n";
for ($green = 0; $green < 6; $green++) {
for ($red = 0; $red < 6; $red++) {
for ($blue = 0; $blue < 6; $blue++) {
$color = 16 + ($red * 36) + ($green * 6) + $blue;
print "\x1b[${fgbg};5;${color}m";
if ($fgbg == 38) {
print "::";
} else {
# after the background texts becomes too light to read the foreground text,
# switch over to black foreground
if ($color == 34) {
$colorBlockTextForegroundIsNowDark = 1;
}
if ($colorBlockTextForegroundIsNowDark) {
print "\x1b[38;5;0m";
}
print " \\033[${fgbg};5;${color}m ";
# If the color number is three digits instead of two add a space
if ($color < 100) {
print " ";
}
}
}
print "\x1b[0m";
if ($fgbg == 38) {
print " "
} else {
print "\n";
}
}
if ($fgbg == 38) {
print "\n"
}
}
print "\n";
# now the grayscale ramp
print "\033[48;5;13m\033[38;5;0mGrayscale ramp:\033[48;5;0m\n";
for ($color = 232; $color < 256; $color++) {
print "\x1b[${fgbg};5;${color}m";
if ($fgbg == 38) {
print "::";
} else {
print " ";
}
}
# now the grayscale ramp with copyable text
if ($fgbg == 48) {
print "\033[48;5;0m\n\n\033[48;5;13m\033[38;5;0mGrayscale ramp with copyable text:\033[48;5;0m\n";
$colorBlockTextForegroundIsNowDark = 0;
}
for ($color = 232; $color < 256; $color++) {
if ($color == 238 || $color == 244 || $color == 250) {
# after the background texts becomes too light to read the foreground text,
# switch over to black foreground
if ($color == 244) {
$colorBlockTextForegroundIsNowDark = 1;
}
if ($colorBlockTextForegroundIsNowDark) {
print "\x1b[38;5;0m";
}
print "\033[48;5;0m\n";
}
print "\x1b[${fgbg};5;${color}m";
if ($fgbg == 48) {
print " \\033[${fgbg};5;${color}m ";
}
}
}
print "\x1b[0m\n\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment