@@ -39,12 +39,12 @@ public function __construct($verbosity, $supportColors, $width = null)
3939 {
4040 if (null === $ width ) {
4141 $ terminal = new Terminal ();
42- $ width = min ( $ terminal ->getWidth (), 80 );
42+ $ width = $ terminal ->getWidth ();
4343 }
4444
4545 $ this ->verbosity = $ verbosity ;
4646 $ this ->supportColors = $ supportColors ;
47- $ this ->width = $ width ;
47+ $ this ->width = $ width ?: 80 ;
4848 }
4949
5050 /**
@@ -112,24 +112,27 @@ public function getRequirementErrorMessage(Requirement $requirement)
112112 public function block ($ title , $ message , $ verbosity , $ style = null )
113113 {
114114 $ prefix = ' [ ' .$ title .'] ' ;
115+ $ lineLength = $ this ->width - strlen ($ prefix ) - 1 ;
116+ if ($ lineLength < 0 ) {
117+ $ lineLength = 0 ;
118+ }
115119 $ message = $ prefix .trim ($ message );
116120
117121 $ lines = array ();
118122
119123 $ remainingMessage = $ message ;
120124
121- while ($ remainingMessage !== '' ) {
122- $ wrapped = wordwrap ($ remainingMessage , $ this ->width - 3 , '¬ ' );
123- $ exploded = explode ('¬ ' , $ wrapped );
124- $ line = $ exploded [0 ];
125- $ remainingMessage = ltrim (substr ($ remainingMessage , \strlen ($ line )));
125+ $ wrapped = wordwrap ($ remainingMessage , $ lineLength , '¬ ' );
126+ $ wrapped = explode ('¬ ' , $ wrapped );
126127
127- if ($ remainingMessage !== '' ) {
128- $ remainingMessage = str_repeat (' ' , \strlen ($ prefix )).$ remainingMessage ;
128+ do {
129+ $ line = array_shift ($ wrapped );
130+ if ($ lines && $ lineLength > 0 ) {
131+ $ line = str_repeat (' ' , \strlen ($ prefix )).ltrim ($ line );
129132 }
130-
131133 $ lines [] = str_pad ($ line , $ this ->width , ' ' , STR_PAD_RIGHT );
132134 }
135+ while (count ($ wrapped ));
133136
134137 $ this ->printvln ('' , $ verbosity );
135138 $ this ->printvln (str_repeat (' ' , $ this ->width ), $ verbosity , $ style );
0 commit comments