@@ -61,7 +61,7 @@ public function success(string $message): void
6161 public function error (string $ message ): void
6262 {
6363 [$ formattedMessage , $ lineLength , $ color ] = $ this ->formatMessage ('ERROR ' , $ message , 'red ' );
64- $ this ->outputMessage ($ formattedMessage , $ lineLength , $ color );
64+ $ this ->outputMessage ($ formattedMessage , $ lineLength , $ color, true );
6565 }
6666
6767 public function warning (string $ message ): void
@@ -76,6 +76,16 @@ public function info(string $message): void
7676 $ this ->outputMessage ($ formattedMessage , $ lineLength , $ color );
7777 }
7878
79+ public function debug (string $ message ): void
80+ {
81+ if (!$ this ->output ->isVerbose ()) {
82+ return ;
83+ }
84+ [$ formattedMessage , $ lineLength , $ color ] = $ this ->formatMessage ('DEBUG ' , $ message , 'cyan ' );
85+ $ this ->outputMessage ($ formattedMessage , $ lineLength , $ color );
86+ }
87+
88+
7989 public function title (string $ message ): void
8090 {
8191 $ consoleWidth = $ this ->geTerminalWidth ();
@@ -92,6 +102,7 @@ public function title(string $message): void
92102 public function list (array $ items ): void
93103 {
94104 foreach ($ items as $ item ) {
105+ $ item = $ this ->variableToString ($ item );
95106 $ this ->write ('- ' . $ item );
96107 $ this ->write (PHP_EOL );
97108 }
@@ -298,7 +309,7 @@ public function boxed(string $message, string $borderChar = '*', int $padding =
298309 $ this ->write (PHP_EOL );
299310 }
300311
301- public function writeColor (string $ message , ?string $ color = null , ?string $ background = null ): void
312+ public function writeColor (string $ message , ?string $ color = null , ?string $ background = null , bool $ isError = false ): void
302313 {
303314
304315 $ formattedMessage = '' ;
@@ -312,11 +323,15 @@ public function writeColor(string $message, ?string $color = null, ?string $back
312323
313324 $ formattedMessage .= $ message . "\033[0m " ;
314325
315- $ this ->write ($ formattedMessage );
326+ $ this ->write ($ formattedMessage, $ isError );
316327 }
317328
318- public function write (string $ message ): void
329+ public function write (string $ message, bool $ isError = false ): void
319330 {
331+ if ($ isError ) {
332+ fwrite (STDERR , $ message );
333+ return ;
334+ }
320335 $ this ->output ->write ($ message );
321336 }
322337
@@ -325,24 +340,24 @@ public function writeln(string $message): void
325340 $ this ->output ->writeln ($ message );
326341 }
327342
328- private function outputMessage ($ formattedMessage , int $ lineLength , string $ color ): void
343+ private function outputMessage ($ formattedMessage , int $ lineLength , string $ color, bool $ isError = false ): void
329344 {
330- $ this ->write (PHP_EOL );
331- $ this ->writeColor (str_repeat (' ' , $ lineLength ), 'white ' , $ color );
332- $ this ->write (PHP_EOL );
345+ $ this ->write (PHP_EOL , $ isError );
346+ $ this ->writeColor (str_repeat (' ' , $ lineLength ), 'white ' , $ color, $ isError );
347+ $ this ->write (PHP_EOL , $ isError );
333348
334349 if (is_string ($ formattedMessage )) {
335350 $ formattedMessage = [$ formattedMessage ];
336351 }
337352
338353 foreach ($ formattedMessage as $ line ) {
339- $ this ->writeColor ($ line , 'white ' , $ color );
354+ $ this ->writeColor ($ line , 'white ' , $ color, $ isError );
340355 }
341356
342- $ this ->write (PHP_EOL );
343- $ this ->writeColor (str_repeat (' ' , $ lineLength ), 'white ' , $ color );
344- $ this ->write (PHP_EOL );
345- $ this ->write (PHP_EOL );
357+ $ this ->write (PHP_EOL , $ isError );
358+ $ this ->writeColor (str_repeat (' ' , $ lineLength ), 'white ' , $ color, $ isError );
359+ $ this ->write (PHP_EOL , $ isError );
360+ $ this ->write (PHP_EOL , $ isError );
346361 }
347362
348363 private function formatMessage (string $ prefix , string $ message , string $ color ): array
@@ -390,4 +405,14 @@ private function variableToString($variable): string
390405
391406 return var_export ($ variable , true );
392407 }
408+
409+ public function setVerbose (bool $ verbose ): void
410+ {
411+ $ this ->output ->setVerbose ($ verbose );
412+ }
413+
414+ public function isVerbose (): bool
415+ {
416+ return $ this ->output ->isVerbose ();
417+ }
393418}
0 commit comments