|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Bash Tools |
|
5
|
|
|
* |
|
6
|
|
|
* @category lib |
|
7
|
|
|
* @author Judicaël Paquet <[email protected]> |
|
8
|
|
|
* @copyright Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93) |
|
9
|
|
|
* @license https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël |
|
10
|
|
|
* @version Release: 1.0.0 |
|
11
|
|
|
* @filesource https://github.com/las93/venus2 |
|
12
|
|
|
* @link https://github.com/las93 |
|
13
|
|
|
* @since 1.0 |
|
14
|
|
|
*/ |
|
15
|
|
|
namespace Venus\lib; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Bash Tools |
|
19
|
|
|
* |
|
20
|
|
|
* @category core |
|
21
|
|
|
* @author Judicaël Paquet <[email protected]> |
|
22
|
|
|
* @copyright Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93) |
|
23
|
|
|
* @license https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël |
|
24
|
|
|
* @version Release: 1.0.0 |
|
25
|
|
|
* @filesource https://github.com/las93/venus2 |
|
26
|
|
|
* @link https://github.com/las93 |
|
27
|
|
|
* @since 1.0 |
|
28
|
|
|
*/ |
|
29
|
|
|
class Bash |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* color of the text in the bash |
|
33
|
|
|
* |
|
34
|
|
|
* @access public |
|
35
|
|
|
* @var array |
|
36
|
|
|
*/ |
|
37
|
|
|
public static $_aColorCodes = array( |
|
38
|
|
|
'default' => 39, |
|
39
|
|
|
'black' => 30, |
|
40
|
|
|
'red' => 31, |
|
41
|
|
|
'green' => 32, |
|
42
|
|
|
'yellow' => 33, |
|
43
|
|
|
'blue' => 34, |
|
44
|
|
|
'magenta' => 35, |
|
45
|
|
|
'cyan' => 36, |
|
46
|
|
|
'light gray' => 37, |
|
47
|
|
|
'dark gray' => 90, |
|
48
|
|
|
'light red' => 91, |
|
49
|
|
|
'light green' => 92, |
|
50
|
|
|
'light yellow' => 93, |
|
51
|
|
|
'light blue' => 94, |
|
52
|
|
|
'light magenta' => 95, |
|
53
|
|
|
'light cyan' => 96, |
|
54
|
|
|
'white' => 97 |
|
55
|
|
|
); |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* color of the background in the bash |
|
59
|
|
|
* |
|
60
|
|
|
* @access public |
|
61
|
|
|
* @var array |
|
62
|
|
|
*/ |
|
63
|
|
|
public static $_aBackgroundCodes = array( |
|
64
|
|
|
'default' => 49, |
|
65
|
|
|
'black' => 40, |
|
66
|
|
|
'red' => 41, |
|
67
|
|
|
'green' => 42, |
|
68
|
|
|
'yellow' => 43, |
|
69
|
|
|
'blue' => 44, |
|
70
|
|
|
'magenta' => 45, |
|
71
|
|
|
'cyan' => 46, |
|
72
|
|
|
'light gray' => 47, |
|
73
|
|
|
'dark gray' => 100, |
|
74
|
|
|
'light red' => 101, |
|
75
|
|
|
'light green' => 102, |
|
76
|
|
|
'light yellow' => 103, |
|
77
|
|
|
'light blue' => 104, |
|
78
|
|
|
'light magenta' => 105, |
|
79
|
|
|
'light cyan' => 106, |
|
80
|
|
|
'white' => 107 |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* color of the decoration code in the bash |
|
85
|
|
|
* |
|
86
|
|
|
* @access public |
|
87
|
|
|
* @var array |
|
88
|
|
|
*/ |
|
89
|
|
|
public static $_aDecorationCodes = array( |
|
90
|
|
|
'bold' => '1', |
|
91
|
|
|
'dim' => '2', |
|
92
|
|
|
'underline' => '4', |
|
93
|
|
|
'blink' => '5', |
|
94
|
|
|
'reverse' => '7', |
|
95
|
|
|
'hidden' => '8' |
|
96
|
|
|
); |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* set a decoration of the text |
|
100
|
|
|
* |
|
101
|
|
|
* @access public |
|
102
|
|
|
* @param string $sContent content to around by the style |
|
103
|
|
|
* @param string $sStyleName the name of the style |
|
104
|
|
|
* @return string |
|
105
|
|
|
*/ |
|
106
|
|
|
public static function setDecoration(string $sContent, string $sStyleName) : string |
|
107
|
|
|
{ |
|
108
|
|
|
return self::_applyCode($sContent, self::$_aBackgroundCodes[$sStyleName]); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* set a color of the background |
|
113
|
|
|
* |
|
114
|
|
|
* @access public |
|
115
|
|
|
* @param string $sContent content to around by the style |
|
116
|
|
|
* @param string $sColorName the name of the color |
|
117
|
|
|
* @return string |
|
118
|
|
|
*/ |
|
119
|
|
|
public static function setBackground(string $sContent, string $sColorName) : string |
|
120
|
|
|
{ |
|
121
|
|
|
if (!isset(self::$_aBackgroundCodes[$sColorName])) { $sColorName = 'black'; } |
|
122
|
|
|
|
|
123
|
|
|
return self::_applyCode($sContent, self::$_aBackgroundCodes[$sColorName]); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* set a color of the text |
|
128
|
|
|
* |
|
129
|
|
|
* @access public |
|
130
|
|
|
* @param string $sContent content to around by the style |
|
131
|
|
|
* @param string $sColorName the name of the color |
|
132
|
|
|
* @return string |
|
133
|
|
|
*/ |
|
134
|
|
|
public static function setColor(string $sContent, string $sColorName) : string |
|
135
|
|
|
{ |
|
136
|
|
|
if (!isset(self::$_aBackgroundCodes[$sColorName])) { $sColorName = 'white'; } |
|
137
|
|
|
|
|
138
|
|
|
return self::_applyCode($sContent, self::$_aBackgroundCodes[$sColorName]); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* around the text by a color |
|
143
|
|
|
* |
|
144
|
|
|
* @access private |
|
145
|
|
|
* @param string $sContent content to around by the style |
|
146
|
|
|
* @param string $sCode the name of the code (color or decoration) |
|
147
|
|
|
* @return string |
|
148
|
|
|
*/ |
|
149
|
|
|
private static function _applyCode(string $sContent, string $sCode) : string |
|
150
|
|
|
{ |
|
151
|
|
|
return "\033[" . $sCode . "m" . $sContent . "\033[0m\n"; |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|