1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Forked version that is simplified to work without Composer. |
7
|
|
|
* |
8
|
|
|
* @link https://github.com/caendesilva/php-console |
9
|
|
|
* @license MIT |
10
|
|
|
* @internal |
11
|
|
|
*/ |
12
|
|
|
class Console |
13
|
|
|
{ |
14
|
|
|
public function write(string $string): self |
15
|
|
|
{ |
16
|
|
|
file_put_contents('php://stdout', $string); |
17
|
|
|
|
18
|
|
|
return $this; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function line(string $message = ''): self |
22
|
|
|
{ |
23
|
|
|
return $this->write($message . PHP_EOL); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function newline(int $count = 1): self |
27
|
|
|
{ |
28
|
|
|
return $this->line(str_repeat(PHP_EOL, $count - 1)); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function info(string $message): self |
32
|
|
|
{ |
33
|
|
|
return $this->line(sprintf('%s%s%s: %s', $this->gray('['), $this->green('Info'), $this->gray(']'), $message)); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function warn(string $message): self |
37
|
|
|
{ |
38
|
|
|
return $this->line(sprintf('%s%s%s: %s', $this->gray('['), $this->yellow('Warning'), $this->gray(']'), $message)); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function error(string $message): self |
42
|
|
|
{ |
43
|
|
|
return $this->line(sprintf('%s%s%s: %s', $this->gray('['), $this->red('Error'), $this->gray(']'), $message)); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function debug(string $message): self |
47
|
|
|
{ |
48
|
|
|
return $this->line(sprintf('%s%s%s: %s', $this->gray('['), $this->lightGray('Debug'), $this->gray(']'), $message)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function debugComment(string $message): self |
52
|
|
|
{ |
53
|
|
|
return $this->line(sprintf('%s%s', $this->gray(' > '), $this->lightGray($message))); |
54
|
|
|
} |
55
|
|
|
protected function ansi(string $string, string $color): string |
56
|
|
|
{ |
57
|
|
|
return "\033[" . $color . 'm' . $string . "\033[0m"; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function black(string $string): string |
61
|
|
|
{ |
62
|
|
|
return $this->ansi($string, '30'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function red(string $string): string |
66
|
|
|
{ |
67
|
|
|
return $this->ansi($string, '31'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
protected function green(string $string): string |
71
|
|
|
{ |
72
|
|
|
return $this->ansi($string, '32'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
protected function yellow(string $string): string |
76
|
|
|
{ |
77
|
|
|
return $this->ansi($string, '33'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
protected function blue(string $string): string |
81
|
|
|
{ |
82
|
|
|
return $this->ansi($string, '34'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
protected function magenta(string $string): string |
86
|
|
|
{ |
87
|
|
|
return $this->ansi($string, '35'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
protected function cyan(string $string): string |
91
|
|
|
{ |
92
|
|
|
return $this->ansi($string, '36'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
protected function white(string $string): string |
96
|
|
|
{ |
97
|
|
|
return $this->ansi($string, '37'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
protected function gray(string $string): string |
101
|
|
|
{ |
102
|
|
|
return $this->ansi($string, '90'); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
protected function lightGray(string $string): string |
106
|
|
|
{ |
107
|
|
|
return $this->ansi($string, '37'); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|