@@ -66,53 +66,10 @@ public function __construct(InputInterface $input, OutputInterface $output)
66
66
*/
67
67
public function block ($ messages , $ type = null , $ style = null , $ prefix = ' ' , $ padding = false )
68
68
{
69
- $ this ->autoPrependBlock ();
70
69
$ messages = is_array ($ messages ) ? array_values ($ messages ) : array ($ messages );
71
- $ indentLength = 0 ;
72
- $ lines = array ();
73
-
74
- if (null !== $ type ) {
75
- $ typePrefix = sprintf ('[%s] ' , $ type );
76
- $ indentLength = strlen ($ typePrefix );
77
- $ lineIndentation = str_repeat (' ' , $ indentLength );
78
- }
79
-
80
- // wrap and add newlines for each element
81
- foreach ($ messages as $ key => $ message ) {
82
- $ message = OutputFormatter::escape ($ message );
83
- $ lines = array_merge ($ lines , explode (PHP_EOL , wordwrap ($ message , $ this ->lineLength - Helper::strlen ($ prefix ) - $ indentLength , PHP_EOL , true )));
84
-
85
- // prefix each line with a number of spaces equivalent to the type length
86
- if (null !== $ type ) {
87
- foreach ($ lines as &$ line ) {
88
- $ line = $ lineIndentation === substr ($ line , 0 , $ indentLength ) ? $ line : $ lineIndentation .$ line ;
89
- }
90
- }
91
-
92
- if (count ($ messages ) > 1 && $ key < count ($ messages ) - 1 ) {
93
- $ lines [] = '' ;
94
- }
95
- }
96
70
97
- if (null !== $ type ) {
98
- $ lines [0 ] = substr_replace ($ lines [0 ], $ typePrefix , 0 , $ indentLength );
99
- }
100
-
101
- if ($ padding && $ this ->isDecorated ()) {
102
- array_unshift ($ lines , '' );
103
- $ lines [] = '' ;
104
- }
105
-
106
- foreach ($ lines as &$ line ) {
107
- $ line = sprintf ('%s%s ' , $ prefix , $ line );
108
- $ line .= str_repeat (' ' , $ this ->lineLength - Helper::strlenWithoutDecoration ($ this ->getFormatter (), $ line ));
109
-
110
- if ($ style ) {
111
- $ line = sprintf ('<%s>%s</> ' , $ style , $ line );
112
- }
113
- }
114
-
115
- $ this ->writeln ($ lines );
71
+ $ this ->autoPrependBlock ();
72
+ $ this ->writeln ($ this ->createBlock ($ messages , $ type , $ style , $ prefix , $ padding , true ));
116
73
$ this ->newLine ();
117
74
}
118
75
@@ -177,11 +134,10 @@ public function text($message)
177
134
public function comment ($ message )
178
135
{
179
136
$ messages = is_array ($ message ) ? array_values ($ message ) : array ($ message );
180
- foreach ($ messages as &$ message ) {
181
- $ message = $ this ->getFormatter ()->format ($ message );
182
- }
183
137
184
- $ this ->block ($ messages , null , null , ' // ' );
138
+ $ this ->autoPrependBlock ();
139
+ $ this ->writeln ($ this ->createBlock ($ messages , null , null , '<fg=default> // </> ' ));
140
+ $ this ->newLine ();
185
141
}
186
142
187
143
/**
@@ -437,4 +393,56 @@ private function reduceBuffer($messages)
437
393
return substr ($ value , -4 );
438
394
}, array_merge (array ($ this ->bufferedOutput ->fetch ()), (array ) $ messages ));
439
395
}
396
+
397
+ private function createBlock ($ messages , $ type = null , $ style = null , $ prefix = ' ' , $ padding = false , $ escape = false )
398
+ {
399
+ $ indentLength = 0 ;
400
+ $ lines = array ();
401
+
402
+ if (null !== $ type ) {
403
+ $ typePrefix = sprintf ('[%s] ' , $ type );
404
+ $ indentLength = strlen ($ typePrefix );
405
+ $ lineIndentation = str_repeat (' ' , $ indentLength );
406
+ }
407
+
408
+ // wrap and add newlines for each element
409
+ foreach ($ messages as $ key => $ message ) {
410
+ if ($ escape ) {
411
+ $ message = OutputFormatter::escape ($ message );
412
+ }
413
+
414
+ $ lines = array_merge ($ lines , explode (PHP_EOL , wordwrap ($ message , $ this ->lineLength - Helper::strlen (strip_tags ($ prefix )) - $ indentLength , PHP_EOL , true )));
415
+
416
+ // prefix each line with a number of spaces equivalent to the type length
417
+ if (null !== $ type ) {
418
+ foreach ($ lines as &$ line ) {
419
+ $ line = $ lineIndentation === substr ($ line , 0 , $ indentLength ) ? $ line : $ lineIndentation .$ line ;
420
+ }
421
+ }
422
+
423
+ if (count ($ messages ) > 1 && $ key < count ($ messages ) - 1 ) {
424
+ $ lines [] = '' ;
425
+ }
426
+ }
427
+
428
+ if (null !== $ type ) {
429
+ $ lines [0 ] = substr_replace ($ lines [0 ], $ typePrefix , 0 , $ indentLength );
430
+ }
431
+
432
+ if ($ padding && $ this ->isDecorated ()) {
433
+ array_unshift ($ lines , '' );
434
+ $ lines [] = '' ;
435
+ }
436
+
437
+ foreach ($ lines as &$ line ) {
438
+ $ line = sprintf ('%s%s ' , $ prefix , $ line );
439
+ $ line .= str_repeat (' ' , $ this ->lineLength - Helper::strlenWithoutDecoration ($ this ->getFormatter (), $ line ));
440
+
441
+ if ($ style ) {
442
+ $ line = sprintf ('<%s>%s</> ' , $ style , $ line );
443
+ }
444
+ }
445
+
446
+ return $ lines ;
447
+ }
440
448
}
0 commit comments