|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Cycle\Schema\Renderer\ConsoleRenderer\Formatter; |
|
6
|
|
|
|
|
7
|
|
|
use Cycle\Schema\Renderer\ConsoleRenderer\Formatter; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Colored text for console output |
|
11
|
|
|
*/ |
|
12
|
|
|
final class StyledFormatter implements Formatter |
|
13
|
|
|
{ |
|
14
|
|
|
private const COLORS_MAP = [ |
|
15
|
|
|
'</>' => "\033[39m", |
|
16
|
|
|
'<fg=red>' => "\033[31m", |
|
17
|
|
|
'<fg=green>' => "\033[32m", |
|
18
|
|
|
'<fg=yellow>' => "\033[33m", |
|
19
|
|
|
'<fg=blue>' => "\033[34m", |
|
20
|
|
|
'<fg=magenta>' => "\033[35m", |
|
21
|
|
|
'<fg=cyan>' => "\033[36m", |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
|
|
public function title(string $title): string |
|
25
|
|
|
{ |
|
26
|
|
|
return str_pad($title, self::TITLE_LENGTH, ' ', STR_PAD_LEFT); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function property(string $string): string |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->colorize("<fg=cyan>{$string}</>"); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function column(string $string): string |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->colorize("<fg=green>{$string}</>"); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function info(string $string): string |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->colorize("<fg=yellow>{$string}</>"); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function typecast(string $string): string |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->colorize("<fg=blue>{$string}</>"); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function entity(string $string): string |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->colorize("<fg=magenta>{$string}</>"); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function error(string $string): string |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->colorize("<fg=red>{$string}</>"); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
private function colorize(string $string): string |
|
60
|
|
|
{ |
|
61
|
|
|
return str_replace( |
|
62
|
|
|
array_keys(self::COLORS_MAP), |
|
63
|
|
|
array_values(self::COLORS_MAP), |
|
64
|
|
|
$string |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|