Created
October 18, 2013 18:35
-
-
Save scottchiefbaker/7046044 to your computer and use it in GitHub Desktop.
Test terminal color detection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $depth = terminal_color_depth(); | |
print "My terminal has " . $depth . " colors\n"; | |
sub terminal_color_depth { | |
# If we're not attached to an STDOUT don't go any further | |
if (!-t STDOUT) { | |
return 8; | |
} | |
# This is only good on Linux/Mac right now | |
# Windows will always return 8 colors... | |
my $cmd = "tput colors"; # FIXME | |
my $out = int(`$cmd`); | |
my $exit = $? >> 8; | |
# If we don't get anything from tput, assume 8 colors | |
if ($exit != 0 || !$out) { | |
return 8; | |
} | |
return $out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment