Skip to content

Instantly share code, notes, and snippets.

@KarelWintersky
Last active December 16, 2016 18:28
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 KarelWintersky/796c8a213923dd947ff760764ee852a1 to your computer and use it in GitHub Desktop.
Save KarelWintersky/796c8a213923dd947ff760764ee852a1 to your computer and use it in GitHub Desktop.
Echo_status_cli() - раскраска вывода в консоли
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;
}
@KarelWintersky
Copy link
Author

Use:

echo_status_cli("<font color='white'>[{$status_code}]</font> <font color='yellow'>{$url}</font> retrieved. Stored to file <font color='yellow'>{$filename}</font>");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment