Skip to content

Instantly share code, notes, and snippets.

@skaji
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skaji/9728280 to your computer and use it in GitHub Desktop.
Save skaji/9728280 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
{
no strict 'refs';
my @color = qw(black red green yellow blue magenta cyan white);
for (0..$#color) {
my ($c, $n) = ($color[$_], 30 + $_);
*$c = sub { -t *STDOUT ? "\e[1;${n}m@_\e[m" : "@_" };
}
}
print black("black"), "\n";
print green("success"), "\n";
print red("error"), "\n";
print yellow("yellow"), "\n";
print blue("blue"), "\n";
print magenta("magenta"), "\n";
print cyan("cyan"), "\n";
print white("white"), "\n";
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use constant INTERACTIVE => -t *STDOUT;
sub green { INTERACTIVE ? "\e[1;32m@_\e[m" : "@_" }
sub red { INTERACTIVE ? "\e[1;31m@_\e[m" : "@_" }
sub white { INTERACTIVE ? "\e[1;37m@_\e[m" : "@_" }
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
sub red { -t *STDOUT ? "\e[1;31m@_\e[m" : "@_" }
sub green { -t *STDOUT ? "\e[1;32m@_\e[m" : "@_" }
sub white { -t *STDOUT ? "\e[1;37m@_\e[m" : "@_" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment