Skip to content

Instantly share code, notes, and snippets.

@vifon
Last active October 10, 2015 00:37
Show Gist options
  • Save vifon/3604077 to your computer and use it in GitHub Desktop.
Save vifon/3604077 to your computer and use it in GitHub Desktop.
colortest
#!/usr/bin/env perl
#########################################################################
# Copyright (C) 2012 Wojciech Siewierski #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
#########################################################################
use warnings;
use strict;
use Term::ANSIColor qw(:constants);
my $text = $ARGV[0] // " asdf";
my @colors = (
[ BLACK , ON_BLACK , 30 ],
[ BRIGHT_BLACK , ON_BRIGHT_BLACK , 90 ],
[ RED , ON_RED , 31 ],
[ BRIGHT_RED , ON_BRIGHT_RED , 91 ],
[ GREEN , ON_GREEN , 32 ],
[ BRIGHT_GREEN , ON_BRIGHT_GREEN , 92 ],
[ YELLOW , ON_YELLOW , 33 ],
[ BRIGHT_YELLOW , ON_BRIGHT_YELLOW , 93 ],
[ BLUE , ON_BLUE , 34 ],
[ BRIGHT_BLUE , ON_BRIGHT_BLUE , 94 ],
[ MAGENTA , ON_MAGENTA , 35 ],
[ BRIGHT_MAGENTA , ON_BRIGHT_MAGENTA , 95 ],
[ CYAN , ON_CYAN , 36 ],
[ BRIGHT_CYAN , ON_BRIGHT_CYAN , 96 ],
[ WHITE , ON_WHITE , 37 ],
[ BRIGHT_WHITE , ON_BRIGHT_WHITE , 97 ],
);
use constant FOREGROUND => 0;
use constant BACKGROUND => 10;
print " " x 6;
for my $bg ("", map {$_->[2] + BACKGROUND . "m"} @colors) {
printf("%*s ", length $text, $bg);
} print "\n" x 2;
for my $fg (map {{color => $_->[0],
n => $_->[2] + FOREGROUND . "m"}} @colors) {
for my $bold ("", "1;") {
printf("%5s ", $bold . $fg->{n});
for my $bg ({color => "", n => ""},
map {{ color => $_->[1],
n => $_->[2] + BACKGROUND . "m"}} @colors) {
print BOLD if $bold;
print $bg->{color}, $fg->{color};
printf("%s", $text);
print RESET, " ";
} print "\n";
} # print "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment