You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
65 lines
1.5 KiB
<?php
|
|
|
|
function getTermColors($input, $options) {
|
|
|
|
$colored_string = "";
|
|
|
|
$styles = [
|
|
'normal' => '0', // reset
|
|
'bold' => '1',
|
|
'dim' => '2',
|
|
'underlined' => '4',
|
|
'blinking' => '5'
|
|
];
|
|
|
|
$fg_colors = [
|
|
'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'
|
|
];
|
|
|
|
$bg_colors = [
|
|
'black' => '40',
|
|
'red' => '41',
|
|
'green' => '42',
|
|
'yellow' => '43',
|
|
'blue' => '44',
|
|
'magenta' => '45',
|
|
'cyan' => '46',
|
|
'light_gray' => '47'
|
|
];
|
|
|
|
$style = (isset($options['style'])) ? strtolower($options['style']) : '';
|
|
$color = (isset($options['color'])) ? strtolower($options['color']) : '';
|
|
$fg_color = (isset($options['fg_color'])) ? strtolower($options['fg_color']) : $color;
|
|
$bg_color = (isset($options['bg_color'])) ? strtolower($options['bg_color']) : '';
|
|
|
|
if ($style !== '' && isset($styles[$style])) {
|
|
$colored_string .= "\033[" . $styles[$style] . "m";
|
|
}
|
|
if ($fg_color !== '' && isset($fg_colors[$fg_color])) {
|
|
$colored_string .= "\033[" . $fg_colors[$fg_color] . "m";
|
|
}
|
|
if ($bg_color !== '' && isset($bg_colors[$bg_color])) {
|
|
$colored_string .= "\033[" . $bg_colors[$bg_color] . "m";
|
|
}
|
|
$colored_string .= $input . "\033[0m";
|
|
return $colored_string;
|
|
}
|
|
|
|
function ANSI($data, $a) {
|
|
getTermColors($data, $a);
|
|
}
|
|
|