-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver-log-shared.php
69 lines (63 loc) · 1.31 KB
/
server-log-shared.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
function ansi_colors( $text ) {
$split = explode( "\x1B[", $text );
$text = $split[0];
$closing = '';
for ( $i = 1; $i < count( $split ); $i++ ) {
for ( $j = 0; $j < strlen( $split[$i] ); $j++ ) {
$char = substr( $split[$i], $j, 1 );
if ( $char == 'm' ) {
$text .= substr( $split[$i], $j + 1 );
continue 2;
}
if ( $char == ';' ) {
continue;
}
if ( $char == '0' ) {
$text .= $closing;
$closing = '';
continue;
}
if ( $char == '1' ) {
$text .= '<strong>';
$closing = '</strong>' . $closing;
continue;
}
if ( $char == '3' || $char == '4' ) {
$bg = $char == '4';
$char = substr( $split[$i], ++$j, 1 );
$color = 'inherit';
switch ( $char ) {
case '0':
$color = 'black';
break;
case '1':
$color = 'red';
break;
case '2':
$color = 'green';
break;
case '3':
$color = 'yellow';
break;
case '4':
$color = 'blue';
break;
case '5':
$color = 'magenta';
break;
case '6':
$color = 'cyan';
break;
case '7':
$color = 'white';
break;
}
$text .= '<span style="' . ( $bg ? 'background-' : '' ) . 'color: ' . $color . '">';
$closing = '</span>' . $closing;
continue;
}
}
}
return $text . $closing;
}