Skip to content

Instantly share code, notes, and snippets.

@ytaniike
Created June 1, 2011 13:39
Show Gist options
  • Save ytaniike/1002305 to your computer and use it in GitHub Desktop.
Save ytaniike/1002305 to your computer and use it in GitHub Desktop.
Convenient for setting up tmux and other terminal software.
#!/usr/bin/perl
# displays the 256 colors specified in tmux's "colourNN" way.
# June, 1st 2011 by Yasunori Taniike (@ytaniike).
use strict;
use warnings;
my $prefix_bl = "\x1b[38;5;0;48;5;";
my $prefix_wl = "\x1b[38;5;15;48;5;";
my $suffix = "\x1b[0m";
sub _color_part {
my $color = shift;
return sprintf("m C%03d ", $color);
}
# for colors0 to colors7 (also known as "system colors": black, red, green, yellow,
# blue, magenta, cyan, white)
print "System colors: 8 colors x 2 rows:\n";
foreach my $color (0..7) {
print "$prefix_wl$color" . _color_part($color);
}
print "$suffix\n";
foreach my $color (8..15) {
print "$prefix_bl$color" . _color_part($color);
}
print "$suffix\n\n";
print "colour16 to colour231:\n";
my $index_offset = 15;
my $prefix = $prefix_wl;
foreach my $color (16..231) {
$prefix = $prefix_bl if ($color > 123);
print "$prefix$color" . _color_part($color);
print "$suffix\n"
if (($color - $index_offset) % (2*6) == 0);
}
print "\n";
# grayscale
print "colour232 to colour255: Gray scale\n";
$prefix = $prefix_wl;
foreach my $color (232..255) {
$prefix = $prefix_bl if ($color > 243);
print "$prefix$color" . _color_part($color);
print "$suffix\n"
if (($color - $index_offset) % (2*6) == 0);
}
exit (0);
@ytaniike
Copy link
Author

ytaniike commented Jun 1, 2011

How do you know which 'colour' numbers, when you've got to or tried to setup tmux?

I've got a lost with a perl script that only displays colors, and wrote this script.

Enjoy :)

@trapd00r
Copy link

trapd00r commented Jun 1, 2011

@ytaniike
Copy link
Author

ytaniike commented Jun 1, 2011 via email

@trapd00r
Copy link

trapd00r commented Jun 1, 2011

Right; you need my two color modules (also on the cpan); to install, just:

cpan Term::ExtendedColor Term::ExtendedColor::Xresources

this is so you can see the actual color values as well as their indexes (in color).

@ytaniike
Copy link
Author

ytaniike commented Jun 1, 2011 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment