-
Notifications
You must be signed in to change notification settings - Fork 1
/
FileColor.php
68 lines (58 loc) · 1.58 KB
/
FileColor.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
<?php
/**
* Created by PhpStorm.
* User: gio
* Date: 10/13/17
* Time: 3:17 PM
*/
namespace apollo11\fileLogger;
class FileColor
{
// Text color options for log text
const F_BLACK = '0;30';
const F_DARK_GREY = '1;30';
const F_BLUE = '0;34';
const F_LIGHT_BLUE = '1;34';
const F_GREEN = '0;32';
const F_LIGHT_GREEN = '1;32';
const F_CYAN = '0;36';
const F_LIGHT_CYAN = '1;36';
const F_RED = '0;31';
const F_LIGHT_RED = '1;31';
const F_PURPLE = '0;35';
const F_LIGHT_PURPLE = '1;35';
const F_BROWN = '0;33';
const F_YELLOW = '1;33';
const F_LIGHT_GRAY = '0;37';
const F_WHITE = '1;37';
const B_BlACK = '40';
const B_RED = '41';
const B_GREEN = '42';
const B_YELLOW = '43';
const B_BLUE = '44';
const B_MAGENTA = '45';
const B_CYAN = '46';
const B_LIGHT_GRAY = '47';
/**
* Get colored string
*
* Returns colored string with chosen configuration for log text
* @param $string
* @param null $foregroundColor
* @param null $backgroundColor
* @return string
*/
public static function getColoredString($string, $foregroundColor = null, $backgroundColor = null)
{
// Set foreground color and background color
$coloredString = "";
if ($foregroundColor !== null) {
$coloredString .= "\033[" . $foregroundColor . "m";
}
if ($backgroundColor !== null) {
$coloredString .= "\033[" . $backgroundColor . "m";
}
$coloredString .= $string . "\033[0m";
return $coloredString;
}
}