FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
phalcon-devtools/src/Script/Color.php at master · phalcon/phalcon-devtools · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
phalcon
/
phalcon-devtools
Public
Notifications
You must be signed in to change notification settings
Fork
610
Star
1.3k
Code
Issues
24
Pull requests
10
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
phalcon-devtools
/
src
/
Script
/
Color.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
220 lines (196 loc) · 6.21 KB
Breadcrumbs
phalcon-devtools
/
src
/
Script
/
Color.php
Copy path
File metadata and controls
220 lines (196 loc) · 6.21 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
declare
(strict_types=
1
);
/**
* This file is part of the Phalcon Developer Tools.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace
Phalcon
\
DevTools
\
Script
;
/**
* Allows to generate messages using colors on xterm, ddterm, linux, etc.
*/
final
class
Color
{
const
FG_BLACK
=
1
;
const
FG_DARK_GRAY
=
2
;
const
FG_BLUE
=
3
;
const
FG_LIGHT_BLUE
=
4
;
const
FG_GREEN
=
5
;
const
FG_LIGHT_GREEN
=
6
;
const
FG_CYAN
=
7
;
const
FG_LIGHT_CYAN
=
8
;
const
FG_RED
=
9
;
const
FG_LIGHT_RED
=
10
;
const
FG_PURPLE
=
11
;
const
FG_LIGHT_PURPLE
=
12
;
const
FG_BROWN
=
13
;
const
FG_YELLOW
=
14
;
const
FG_LIGHT_GRAY
=
15
;
const
FG_WHITE
=
16
;
const
BG_BLACK
=
1
;
const
BG_RED
=
2
;
const
BG_GREEN
=
3
;
const
BG_YELLOW
=
4
;
const
BG_BLUE
=
5
;
const
BG_MAGENTA
=
6
;
const
BG_CYAN
=
7
;
const
BG_LIGHT_GRAY
=
8
;
const
AT_NORMAL
=
1
;
const
AT_BOLD
=
2
;
const
AT_ITALIC
=
3
;
const
AT_UNDERLINE
=
4
;
const
AT_BLINK
=
5
;
const
AT_OUTLINE
=
6
;
const
AT_REVERSE
=
7
;
const
AT_NONDISP
=
8
;
const
AT_STRIKE
=
9
;
/**
* @var array Map of supported foreground colors
*/
private
static
$
fg
=
array
(
self
::
FG_BLACK
=>
'
0;30
'
,
self
::
FG_DARK_GRAY
=>
'
1;30
'
,
self
::
FG_RED
=>
'
0;31
'
,
self
::
FG_LIGHT_RED
=>
'
1;31
'
,
self
::
FG_GREEN
=>
'
0;32
'
,
self
::
FG_LIGHT_GREEN
=>
'
1;32
'
,
self
::
FG_BROWN
=>
'
0;33
'
,
self
::
FG_YELLOW
=>
'
1;33
'
,
self
::
FG_BLUE
=>
'
0;34
'
,
self
::
FG_LIGHT_BLUE
=>
'
1;34
'
,
self
::
FG_PURPLE
=>
'
0;35
'
,
self
::
FG_LIGHT_PURPLE
=>
'
1;35
'
,
self
::
FG_CYAN
=>
'
0;36
'
,
self
::
FG_LIGHT_CYAN
=>
'
1;36
'
,
self
::
FG_LIGHT_GRAY
=>
'
0;37
'
,
self
::
FG_WHITE
=>
'
1;37
'
,
);
/**
* @var array Map of supported background colors
*/
private
static
$
bg
=
array
(
self
::
BG_BLACK
=>
'
40
'
,
self
::
BG_RED
=>
'
41
'
,
self
::
BG_GREEN
=>
'
42
'
,
self
::
BG_YELLOW
=>
'
43
'
,
self
::
BG_BLUE
=>
'
44
'
,
self
::
BG_MAGENTA
=>
'
45
'
,
self
::
BG_CYAN
=>
'
46
'
,
self
::
BG_LIGHT_GRAY
=>
'
47
'
,
);
/**
* @var array Map of supported attributes
*/
private
static
$
at
=
array
(
self
::
AT_NORMAL
=>
'
0
'
,
self
::
AT_BOLD
=>
'
1
'
,
self
::
AT_ITALIC
=>
'
3
'
,
self
::
AT_UNDERLINE
=>
'
4
'
,
self
::
AT_BLINK
=>
'
5
'
,
self
::
AT_OUTLINE
=>
'
6
'
,
self
::
AT_REVERSE
=>
'
7
'
,
self
::
AT_NONDISP
=>
'
8
'
,
self
::
AT_STRIKE
=>
'
9
'
,
);
/**
* Identify if console supports colors
*
* @return bool
*/
public
static
function
isSupportedShell
():
bool
{
if
(
strtoupper
(
substr
(
PHP_OS
,
0
,
3
)) ===
'
WIN
'
) {
return
false
!==
getenv
(
'
ANSICON
'
) ||
'
ON
'
===
getenv
(
'
ConEmuANSI
'
) ||
'
xterm
'
===
getenv
(
'
TERM
'
);
}
return
defined
(
'
STDOUT
'
) &&
function_exists
(
'
posix_isatty
'
) &&
posix_isatty
(
STDOUT
);
}
/**
* Colorizes the string using provided colors.
*
* @static
* @param string $string
* @param null|integer $fg
* @param null|integer $at
* @param null|integer $bg
*
* @return string
*/
public
static
function
colorize
(
string
$
string
,
$
fg
=
null
,
$
at
=
null
,
$
bg
=
null
):
string
{
// Shell not supported, exit early
if
(!
static
::
isSupportedShell
()) {
return
$
string
;
}
$
colored
=
''
;
// Check if given foreground color is supported
if
(
isset
(
static
::
$
fg
[
$
fg
])) {
$
colored
.=
"\033
[
"
.
static
::
$
fg
[
$
fg
] .
"
m
"
;
}
// Check if given background color is supported
if
(
isset
(
static
::
$
bg
[
$
bg
])) {
$
colored
.=
"\033
[
"
.
static
::
$
bg
[
$
bg
] .
"
m
"
;
}
// Check if given attribute is supported
if
(
isset
(
static
::
$
at
[
$
at
])) {
$
colored
.=
"\033
[
"
.
static
::
$
at
[
$
at
] .
"
m
"
;
}
// Add string and end coloring
$
colored
.=
$
string
.
"\033
[0m
"
;
return
$
colored
;
}
public
static
function
head
(
string
$
msg
):
string
{
return
static
::
colorize
(
$
msg
, Color::
FG_BROWN
);
}
/**
* Color style for error messages.
*
* @static
* @param string $msg
* @return string
*/
public
static
function
error
(
string
$
msg
):
string
{
$
msg
=
'
Error:
'
.
$
msg
;
$
space
=
strlen
(
$
msg
) +
4
;
$
out
=
static
::
colorize
(
str_pad
(
'
'
,
$
space
), Color::
FG_WHITE
, Color::
AT_BOLD
, Color::
BG_RED
) .
PHP_EOL
;
$
out
.=
static
::
colorize
(
'
'
.
$
msg
.
'
'
, Color::
FG_WHITE
, Color::
AT_BOLD
, Color::
BG_RED
) .
PHP_EOL
;
$
out
.=
static
::
colorize
(
str_pad
(
'
'
,
$
space
), Color::
FG_WHITE
, Color::
AT_BOLD
, Color::
BG_RED
) .
PHP_EOL
;
return
$
out
;
}
/**
* Color style for success messages.
*
* @static
* @param string $msg
* @return string
*/
public
static
function
success
(
string
$
msg
):
string
{
$
msg
=
'
Success:
'
.
$
msg
;
$
space
=
strlen
(
$
msg
) +
4
;
$
out
=
static
::
colorize
(
str_pad
(
'
'
,
$
space
), Color::
FG_WHITE
, Color::
AT_BOLD
, Color::
BG_GREEN
) .
PHP_EOL
;
$
out
.=
static
::
colorize
(
'
'
.
$
msg
.
'
'
, Color::
FG_WHITE
, Color::
AT_BOLD
, Color::
BG_GREEN
) .
PHP_EOL
;
$
out
.=
static
::
colorize
(
str_pad
(
'
'
,
$
space
), Color::
FG_WHITE
, Color::
AT_BOLD
, Color::
BG_GREEN
) .
PHP_EOL
;
return
$
out
;
}
/**
* Color style for info messages.
*
* @static
* @param string $msg
* @return string
*/
public
static
function
info
(
string
$
msg
):
string
{
$
msg
=
'
Info:
'
.
$
msg
;
$
space
=
strlen
(
$
msg
) +
4
;
$
out
=
static
::
colorize
(
str_pad
(
'
'
,
$
space
), Color::
FG_WHITE
, Color::
AT_BOLD
, Color::
BG_BLUE
) .
PHP_EOL
;
$
out
.=
static
::
colorize
(
'
'
.
$
msg
.
'
'
, Color::
FG_WHITE
, Color::
AT_BOLD
, Color::
BG_BLUE
) .
PHP_EOL
;
$
out
.=
static
::
colorize
(
str_pad
(
'
'
,
$
space
), Color::
FG_WHITE
, Color::
AT_BOLD
, Color::
BG_BLUE
) .
PHP_EOL
;
return
$
out
;
}
}
Back
|
FazBrowse Home
|
New Git URL