Skip to content

Instantly share code, notes, and snippets.

@ranaroussi
Created November 19, 2013 08:52
Show Gist options
  • Save ranaroussi/7542312 to your computer and use it in GitHub Desktop.
Save ranaroussi/7542312 to your computer and use it in GitHub Desktop.
PHP function to output colorful text via CLI
function outputCLI($text, $color=null) {
$colors = array(
'BLACK' => "0;30m",
'GRAY' => "1;30m",
'LIGHTGRAY' => "0;37m",
'BLUE' => "0;34m",
'LIGHTBLUE' => "1;34m",
'GREEN' => "0;32m",
'LIGHTGREEN' => "1;32m",
'CYAN' => "0;36m",
'LIGHTCYAN' => "1;36m",
'RED' => "0;31m",
'LIGHTRED' => "1;31m",
'PURPLE' => "0;35m",
'LIGHTPURPLE' => "1;35m",
'BROWN' => "0;33m",
'YELLOW' => "1;33m",
'WHITE' => "1;37m",
// background colors
'SUCCESS' => "42m",
'FAILURE' => "41m",
'WARNING' => "43;30m", // black yellow
'NOTE' => "44m",
'INVERT' => "47;30m", // black on white
);
if ($color != null && isset($colors[strtoupper($color)])) {
$output = $colors[strtoupper($color)];
$text = chr(27) . '[' . $output . $text . chr(27) . '[0m';
}
return $text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment