|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* User: alec |
|
4
|
|
|
* Date: 24.12.18 |
|
5
|
|
|
* Time: 15:17 |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace AlecRabbit\Tools\Internal; |
|
10
|
|
|
|
|
11
|
|
|
use AlecRabbit\ConsoleColour; |
|
12
|
|
|
|
|
13
|
|
|
class Theme extends ConsoleColour implements ThemesInterface |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var bool */ |
|
16
|
|
|
private $do; |
|
17
|
|
|
|
|
18
|
1 |
|
public function __construct(bool $color = false) |
|
19
|
|
|
{ |
|
20
|
1 |
|
$this->do = $color; |
|
21
|
1 |
|
parent::__construct(); |
|
22
|
1 |
|
$this->setDefaultThemes(); |
|
23
|
1 |
|
} |
|
24
|
|
|
|
|
25
|
1 |
|
protected function setDefaultThemes(): void |
|
26
|
|
|
{ |
|
27
|
1 |
|
$this->addTheme(static::DARK, 'dark'); |
|
28
|
1 |
|
$this->addTheme(static::COMMENT, 'yellow'); |
|
29
|
1 |
|
$this->addTheme(static::INFO, 'green'); |
|
30
|
1 |
|
$this->addTheme(static::RED, 'red'); |
|
31
|
1 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param string $text |
|
35
|
|
|
* @return string |
|
36
|
|
|
* @throws \Throwable |
|
37
|
|
|
*/ |
|
38
|
4 |
|
public function comment(string $text): string |
|
39
|
|
|
{ |
|
40
|
|
|
return |
|
41
|
4 |
|
$this->apply(static::COMMENT, $text); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param string $text |
|
46
|
|
|
* @return string |
|
47
|
|
|
* @throws \Throwable |
|
48
|
|
|
*/ |
|
49
|
2 |
|
public function yellow(string $text): string |
|
50
|
|
|
{ |
|
51
|
|
|
return |
|
52
|
2 |
|
$this->apply(static::COMMENT, $text); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param array|string $style |
|
57
|
|
|
* @param string $text |
|
58
|
|
|
* @return string |
|
59
|
|
|
* @throws \Throwable |
|
60
|
|
|
*/ |
|
61
|
4 |
|
public function apply($style, $text): string |
|
62
|
|
|
{ |
|
63
|
4 |
|
return $this->do ? parent::apply($style, $text) : $text; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string $text |
|
68
|
|
|
* @return string |
|
69
|
|
|
* @throws \Throwable |
|
70
|
|
|
*/ |
|
71
|
1 |
|
public function red(string $text): string |
|
72
|
|
|
{ |
|
73
|
|
|
return |
|
74
|
1 |
|
$this->apply(static::RED, $text); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param string $text |
|
79
|
|
|
* @return string |
|
80
|
|
|
* @throws \Throwable |
|
81
|
|
|
*/ |
|
82
|
2 |
|
public function info(string $text): string |
|
83
|
|
|
{ |
|
84
|
|
|
return |
|
85
|
2 |
|
$this->apply(static::INFO, $text); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param string $text |
|
90
|
|
|
* @return string |
|
91
|
|
|
* @throws \Throwable |
|
92
|
|
|
*/ |
|
93
|
2 |
|
public function green(string $text): string |
|
94
|
|
|
{ |
|
95
|
|
|
return |
|
96
|
2 |
|
$this->apply(static::INFO, $text); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param string $text |
|
101
|
|
|
* @return string |
|
102
|
|
|
* @throws \Throwable |
|
103
|
|
|
*/ |
|
104
|
3 |
|
public function dark(string $text): string |
|
105
|
|
|
{ |
|
106
|
|
|
return |
|
107
|
3 |
|
$this->apply(static::DARK, $text); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|