Skip to content

Instantly share code, notes, and snippets.

@babarot
Created May 31, 2014 12:31
Show Gist options
  • Save babarot/4a38d74693087a1ed4b6 to your computer and use it in GitHub Desktop.
Save babarot/4a38d74693087a1ed4b6 to your computer and use it in GitHub Desktop.
Shows 256 colors can be displayed on the console
#!/usr/bin/env perl
use strict;
use warnings;
my $fg = "\x1b[38;5;";
my $bg = "\x1b[48;5;";
my $rs = "\x1b[0m";
my $color = 0;
for (my $row = 0; $row < 32; ++$row) {
for (my $col = 0; $col < 8; ++$col) {
print get_color($color);
$color++;
}
print "\n";
}
sub get_color {
my ($color) = @_;
my $number = sprintf '%3d', $color;
return qq/${bg}${color}m ${number} ${rs} ${fg}${color}m${number}${rs} /;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment