-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCliColor.php
92 lines (83 loc) · 1.99 KB
/
CliColor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace CliColor;
class CliColor {
static private $statuses = array(
's'=> "\033[0;30m\033[42m",
'w'=> "\033[0;30m\033[41m",
'n'=> "\033[0;30m\033[43m",
'p'=> "\033[1;37m\033[44m",
'o'=> "\033[0;30m\033[47m",
);
static private $colorsDescr = array(
's'=> "success",
'w'=> "warning",
'n'=> "notify",
'p'=> "promt",
'o'=> "output",
);
static $waitSym_i=0;
static $waitSym_init=1;
static $waitSymbols=array('|','/','-','\\');
// Returns colored string
static private function __Output($string='',$status='d',$nl=0) {
$string = $nl ? "\n".$string : $string;
if(!isset(self::$statuses[$status]))
{
$status='d';
}
return self::$statuses[$status].$string."\033[0m";
}
// Returns all foreground color names
static public function Info() {
$str = "\nCLI_Color provide colored output to cli";
echo self::Notify($str);
}
static public function Success($string,$nl=0)
{
return self::__Output($string,'s',$nl);
}
static public function Warning($string,$nl=0)
{
return self::__Output($string,'w',$nl);
}
static public function Notify($string,$nl=0)
{
return self::__Output($string,'n',$nl);
}
static public function Promt($string,$nl=0)
{
return self::__Output($string,'p',$nl);
}
static public function Output($string,$nl=0)
{
return self::__Output($string,'o',$nl);
}
public function __call($name, $arguments)
{
if(empty($name) || empty($arguments) || !is_array($arguments))
{
foreach(self::$colorsDescr as $status=>$method)
{
if($method == strtolower($name))
{
return self::__Output($arguments[0],$status);
}
}
}
return self::__Output("\nUnknown method ".$name." or empty output string\n",'w');
}
static public function Wait()
{
if(self::$waitSym_init)
{
echo "\r";
}
self::$waitSym_i++;
if(!isset(self::$waitSymbols[self::$waitSym_i]))
{
self::$waitSym_i = 0;
}
echo self::Notify(self::$waitSymbols[self::$waitSym_i]);
}
}
?>