1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
namespace Watchmaker\lib; |
4
|
|
|
|
5
|
|
|
class Decorator |
6
|
|
|
{ |
7
|
|
|
private $color = null; |
8
|
|
|
private $collector = null; |
9
|
|
|
|
10
|
|
|
public function __construct(StringCollector $collector) |
11
|
|
|
{ |
12
|
|
|
$this->color = new Color(); |
13
|
|
|
$this->collector = $collector; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function simple($text) |
17
|
|
|
{ |
18
|
|
|
$this->collector->text($text); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function greenText($text) |
22
|
|
|
{ |
23
|
|
|
$d = $this->color->apply('color_82', $text); |
24
|
|
|
$this->collector->text($d); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function yellowText($text) |
28
|
|
|
{ |
29
|
|
|
$d = $this->color->apply('color_226', $text); |
30
|
|
|
$this->collector->text($d); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function redText($text) |
34
|
|
|
{ |
35
|
|
|
$d = $this->color->apply('color_196', $text); |
36
|
|
|
$this->collector->text($d); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function alert($text) |
40
|
|
|
{ |
41
|
|
|
$length = mb_strlen($text) + 12; |
42
|
|
|
|
43
|
|
|
$outText = ''; |
44
|
|
|
$outText .= $this->color->apply('color_130', str_repeat('*', $length)) . "\n"; |
45
|
|
|
$outText .= $this->color->apply('color_130', '* ' . $text . ' *') . "\n"; |
46
|
|
|
$outText .= $this->color->apply('color_130', str_repeat('*', $length)) . "\n"; |
47
|
|
|
|
48
|
|
|
$this->collector->text($outText); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function flashSuccess($message = ' All Installed') |
52
|
|
|
{ |
53
|
|
|
$width = intval(trim(`tput cols`)); |
54
|
|
|
$length = mb_strlen($message); |
55
|
|
|
|
56
|
|
|
$text = ''; |
57
|
|
|
$b = $this->color->apply('color_22', str_repeat('-', $width)); |
58
|
|
|
$text .= $this->color->apply('bg_color_22', $b) . "\n"; |
59
|
|
|
$b = $this->color->apply('color_22', str_repeat('-', $width - $length)); |
60
|
|
|
$text .= $this->color->apply('bg_color_22', $message . $b) . "\n"; |
61
|
|
|
$b = $this->color->apply('color_22', str_repeat('-', $width)); |
62
|
|
|
$text .= $this->color->apply('bg_color_22', $b) . "\n"; |
63
|
|
|
|
64
|
|
|
$this->collector->text($text); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function flashError($message = ' Please update crontab.') |
68
|
|
|
{ |
69
|
|
|
$width = intval(trim(`tput cols`)); |
70
|
|
|
$length = mb_strlen($message); |
71
|
|
|
|
72
|
|
|
$text = ''; |
73
|
|
|
$b = $this->color->apply('color_1', str_repeat('-', $width)); |
74
|
|
|
$text .= $this->color->apply('bg_color_1', $b) . "\n"; |
75
|
|
|
$b = $this->color->apply('color_1', str_repeat('-', $width - $length)); |
76
|
|
|
$text .= $this->color->apply('bg_color_1', $message . $b) . "\n"; |
77
|
|
|
$b = $this->color->apply('color_1', str_repeat('-', $width)); |
78
|
|
|
$text .= $this->color->apply('bg_color_1', $b) . "\n"; |
79
|
|
|
|
80
|
|
|
$this->collector->text($text); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function hr() |
84
|
|
|
{ |
85
|
|
|
$this->isInteractive(); |
86
|
|
|
|
87
|
|
|
$width = intval(trim(`tput cols`)); |
88
|
|
|
$d = str_repeat('-', $width) . "\n"; |
89
|
|
|
$this->collector->text($d); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function newLine($line = 1) |
93
|
|
|
{ |
94
|
|
|
for ($i = 0; $i < $line; $i++) { |
95
|
|
|
$this->collector->text("\n", false); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
private function isInteractive() |
100
|
|
|
{ |
101
|
|
|
if (posix_isatty(STDOUT) === false || getenv('CIRCLECI') !== false) { |
102
|
|
|
var_dump("非対話"); |
|
|
|
|
103
|
|
|
} else { |
104
|
|
|
var_dump("対話"); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|