Created
April 8, 2017 14:54
-
-
Save uuf6429/b6df80e2aedd80dd9e5af4cf5575795a to your computer and use it in GitHub Desktop.
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
<?php | |
if ($argc !== 2) { | |
die('File to highlight was expected as first argument.'); | |
} | |
$replace = [ | |
// base styles | |
'EMER' => ["\e[45;30m", " \e[0m "], | |
'ALRT' => ["\e[43;30m", " \e[0m "], | |
'CRIT' => ["\e[41;30m", " \e[0m "], | |
'ERRR' => ["\e[40;31m", " \e[0m "], | |
'WARN' => ["\e[40;33m", " \e[0m "], | |
'NOTE' => ["\e[40;36m", " \e[0m "], | |
'INFO' => ["\e[40;34m", " \e[0m "], | |
'DBUG' => ["\e[40;37m", " \e[0m "], | |
// aliases | |
'EMERGENCY' => 'EMER', | |
'ALERT' => 'ALRT', | |
'CRITICAL' => 'CRIT', | |
'ERROR' => 'ERRR', | |
'WARNING' => 'WARN', | |
'NOTICE' => 'NOTE', | |
'INFORMATION' => 'INFO', | |
'DEBUG' => 'DBUG', | |
]; | |
echo preg_replace_callback( | |
sprintf( | |
'/^(.*?)\\s(%s)\\s-\\s/m', | |
implode('|', array_keys($replace)) | |
), | |
function ($matches) use ($replace) { | |
$style = $replace[$matches[2]]; | |
if(is_string($style)){ | |
$style = $replace[$style]; | |
} | |
return sprintf( | |
'%s%s %s%s ', | |
$style[0], | |
$matches[1], | |
$matches[2], | |
$style[1] | |
); | |
}, | |
file_get_contents($argv[1]) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment