-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cli.php
129 lines (117 loc) · 3.39 KB
/
Cli.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
* php command lind interface helper
*
* @author Mohamad Mehdi Habibi ([email protected])
* @license MIT License
* @link http://github.com/mm-habibi/php-cli/
*
*/
class Cli {
private static $foregroundColors = array(
# Regular Colors
'Black'=>'0;30', # Black
'Red'=>'0;31', # Red
'Green'=>'0;32', # Green
'Yellow'=>'0;33', # Yellow
'Blue'=>'0;34', # Blue
'Purple'=>'0;35', # Purple
'Cyan'=>'0;36', # Cyan
'White'=>'0;37', # White
# Bold
'BBlack'=>'1;30', # Black
'BRed'=>'1;31', # Red
'BGreen'=>'1;32', # Green
'BYellow'=>'1;33', # Yellow
'BBlue'=>'1;34', # Blue
'BPurple'=>'1;35', # Purple
'BCyan'=>'1;36', # Cyan
'BWhite'=>'1;37', # White
# Underline
'UBlack'=>'4;30', # Black
'URed'=>'4;31', # Red
'UGreen'=>'4;32', # Green
'UYellow'=>'4;33', # Yellow
'UBlue'=>'4;34', # Blue
'UPurple'=>'4;35', # Purple
'UCyan'=>'4;36', # Cyan
'UWhite'=>'4;37', # White
# High Intensity
'IBlack'=>'0;90', # Black
'IRed'=>'0;91', # Red
'IGreen'=>'0;92', # Green
'IYellow'=>'0;93', # Yellow
'IBlue'=>'0;94', # Blue
'IPurple'=>'0;95', # Purple
'ICyan'=>'0;96', # Cyan
'IWhite'=>'0;97', # White
# Bold High Intensity
'BIBlack'=>'1;90', # Black
'BIRed'=>'1;91', # Red
'BIGreen'=>'1;92', # Green
'BIYellow'=>'1;93', # Yellow
'BIBlue'=>'1;94', # Blue
'BIPurple'=>'1;95', # Purple
'BICyan'=>'1;96', # Cyan
'BIWhite'=>'1;97', # White
# High Intensity backgrounds
'On_IBlack'=>'0;100', # Black
'On_IRed'=>'0;101', # Red
'On_IGreen'=>'0;102', # Green
'On_IYellow'=>'0;103', # Yellow
'On_IBlue'=>'0;104', # Blue
'On_IPurple'=>'0;105', # Purple
'On_ICyan'=>'0;106', # Cyan
'On_IWhite'=>'0;107', # White
);
private static $backgroundColors = array(
'Black' => '40',
'Red' => '41',
'Green' => '42',
'Yellow' => '43',
'Blue' => '44',
'Magenta' => '45',
'Cyan' => '46',
'LightGray' => '47',
);
public static function log($string, $fColor = null, $bColor = null, $break=true)
{
echo self::getColoredString($string, ucfirst($fColor), ucfirst($bColor)).($break ? "\n" : "");
}
public static function getColoredString($string, $fColor = null, $bColor = null)
{
$coloredString = "";
if (isset(self::$foregroundColors[$fColor])) {
$coloredString .= "\033[" . self::$foregroundColors[$fColor] . "m";
}
if (isset(self::$backgroundColors[$bColor])) {
$coloredString .= "\033[" . self::$backgroundColors[$bColor] . "m";
}
$coloredString .= $string . "\033[0m";
return $coloredString;
}
public static function get($message, $fColor = null, $bColor = null)
{
$fColor = ucfirst($fColor);
$bColor = ucfirst($bColor);
if (PHP_OS == 'WINNT') {
echo $message.' ';
$line = stream_get_line(STDIN, 1024, PHP_EOL);
} else {
$closeColor = false;
if (isset(self::$foregroundColors[$fColor])) {
echo "\033[" . self::$foregroundColors[$fColor] . "m";
$closeColor = true;
}
if (isset(self::$backgroundColors[$bColor])) {
echo "\033[" . self::$backgroundColors[$bColor] . "m";
$closeColor = true;
}
$line = readline($message.' ');
if ($closeColor) {
echo "\033[0m";
}
}
return $line;
}
}