Console_color2 helper.
If $console_color isn't instantiated, remove the color directives and print.
This commit is contained in:
Tony Murray
2016-08-16 19:52:36 -05:00
parent 4a152dab7b
commit aa8294bfce
6 changed files with 30 additions and 27 deletions

View File

@@ -95,28 +95,18 @@ function isCli() {
}
}
function print_error($text, $quiet = false) {
if ($quiet) {
return;
}
function print_error($text) {
if (isCli()) {
global $console_color;
print $console_color->convert("%r".$text."%n\n", false);
c_echo("%r".$text."%n\n");
}
else {
echo('<div class="alert alert-danger"><img src="images/16/exclamation.png" align="absmiddle"> '.$text.'</div>');
}
}
function print_message($text, $quiet = false) {
if ($quiet) {
return;
}
function print_message($text) {
if (isCli()) {
global $console_color;
print $console_color->convert("%g".$text."%n\n", false);
c_echo("%g".$text."%n\n");
}
else {
echo('<div class="alert alert-success"><img src="images/16/tick.png" align="absmiddle"> '.$text.'</div>');
@@ -124,8 +114,6 @@ function print_message($text, $quiet = false) {
}
function delete_port($int_id) {
global $config;
$interface = dbFetchRow("SELECT * FROM `ports` AS P, `devices` AS D WHERE P.port_id = ? AND D.device_id = P.device_id", array($int_id));
$interface_tables = array('adjacencies', 'ipaddr', 'ip6adjacencies', 'ip6addr', 'mac_accounting', 'bill_ports', 'pseudowires', 'ports');
@@ -635,6 +623,22 @@ function d_echo($text, $no_debug_text = null) {
}
} // d_echo
/**
* Output using console color if possible
* https://github.com/pear/Console_Color2/blob/master/examples/documentation
*
* @param string $string the string to print with console color
*/
function c_echo($string)
{
global $console_color;
if($console_color) {
echo $console_color->convert($string);
} else {
echo preg_replace('/%((%)|.)/', '', $string);
}
}
/*
* convenience function - please use this instead of 'if ($debug) { print_r ...; }'