Last active
December 16, 2016 18:28
-
-
Save KarelWintersky/796c8a213923dd947ff760764ee852a1 to your computer and use it in GitHub Desktop.
Echo_status_cli() - раскраска вывода в консоли
This file contains 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
function echo_status_cli($message = "", $breakline = TRUE) | |
{ | |
static $fgcolors = array( | |
'black' => '0;30', | |
'dark gray' => '1;30', | |
'blue' => '0;34', | |
'light blue' => '1;34', | |
'green' => '0;32', | |
'light green' => '1;32', | |
'cyan' => '0;36', | |
'light cyan' => '1;36', | |
'red' => '0;31', | |
'light red' => '1;31', | |
'purple' => '0;35', | |
'light purple' => '1;35', | |
'brown' => '0;33', | |
'yellow' => '1;33', | |
'light gray' => '0;37', | |
'white' => '1;37'); | |
static $bgcolors = array( | |
'black' => '40', | |
'red' => '41', | |
'green' => '42', | |
'yellow' => '43', | |
'blue' => '44', | |
'magenta' => '45', | |
'cyan' => '46', | |
'light gray' => '47'); | |
// replace <hr> tag | |
$pattern = '#(\<hr[\s]?[\/]?\>)#'; | |
$message = preg_replace($pattern, str_repeat('-', 80), $message); | |
// replace font color tag/attribute | |
$pattern = '#(?<Full>\<font[\s]+color=[\\\'\"](?<Color>[\D]+)[\\\'\"]\>(?<Content>.*)\<\/font\>)#U'; | |
$message = strip_tags(preg_replace_callback($pattern, function($matches) use ($fgcolors){ | |
$color = isset( $fgcolors[ $matches['Color'] ]) ? $fgcolors[ $matches['Color'] ] : $fgcolors[ 'white' ]; | |
return "\033[{$color}m{$matches['Content']}\033[0m"; | |
}, $message) ); | |
if ($breakline === TRUE) $message .= PHP_EOL; | |
echo $message; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use: