@@ -141,31 +141,32 @@ public function row( array $row ) {
141141 if ( count ( $ row ) > 0 ) {
142142 $ extra_rows = array_fill ( 0 , count ( $ row ), array () );
143143
144- foreach ( $ row as $ col => $ value ) {
145-
146- $ value = str_replace ( array ( "\r\n" , "\n" ), ' ' , $ value );
147-
148- $ col_width = $ this ->_widths [ $ col ];
149- $ encoding = function_exists ( 'mb_detect_encoding ' ) ? mb_detect_encoding ( $ value , null , true /*strict*/ ) : false ;
144+ foreach ( $ row as $ col => $ value ) {
145+ $ value = $ value ?: '' ;
146+ $ col_width = $ this ->_widths [ $ col ];
147+ $ encoding = function_exists ( 'mb_detect_encoding ' ) ? mb_detect_encoding ( $ value , null , true /*strict*/ ) : false ;
150148 $ original_val_width = Colors::width ( $ value , self ::isPreColorized ( $ col ), $ encoding );
151- if ( $ col_width && $ original_val_width > $ col_width ) {
152- $ row [ $ col ] = \cli \safe_substr ( $ value , 0 , $ col_width , true /*is_width*/ , $ encoding );
153- $ value = \cli \safe_substr ( $ value , \cli \safe_strlen ( $ row [ $ col ], $ encoding ), null /*length*/ , false /*is_width*/ , $ encoding );
154- $ i = 0 ;
155- do {
156- $ extra_value = \cli \safe_substr ( $ value , 0 , $ col_width , true /*is_width*/ , $ encoding );
157- $ val_width = Colors::width ( $ extra_value , self ::isPreColorized ( $ col ), $ encoding );
158- if ( $ val_width ) {
159- $ extra_rows [ $ col ][] = $ extra_value ;
160- $ value = \cli \safe_substr ( $ value , \cli \safe_strlen ( $ extra_value , $ encoding ), null /*length*/ , false /*is_width*/ , $ encoding );
161- $ i ++;
162- if ( $ i > $ extra_row_count ) {
163- $ extra_row_count = $ i ;
149+ if ( $ col_width && ( $ original_val_width > $ col_width || strpos ( $ value , "\n" ) !== false ) ) {
150+ $ split_lines = preg_split ( '/\r\n|\n/ ' , $ value );
151+
152+ $ wrapped_lines = [];
153+ foreach ( $ split_lines as $ line ) {
154+ do {
155+ $ wrapped_value = \cli \safe_substr ( $ line , 0 , $ col_width , true /*is_width*/ , $ encoding );
156+ $ val_width = Colors::width ( $ wrapped_value , self ::isPreColorized ( $ col ), $ encoding );
157+ if ( $ val_width ) {
158+ $ wrapped_lines [] = $ wrapped_value ;
159+ $ line = \cli \safe_substr ( $ line , \cli \safe_strlen ( $ wrapped_value , $ encoding ), null /*length*/ , false /*is_width*/ , $ encoding );
164160 }
165- }
166- } while ( $ value );
167- }
161+ } while ( $ line );
162+ }
168163
164+ $ row [ $ col ] = array_shift ( $ wrapped_lines );
165+ foreach ( $ wrapped_lines as $ wrapped_line ) {
166+ $ extra_rows [ $ col ][] = $ wrapped_line ;
167+ ++$ extra_row_count ;
168+ }
169+ }
169170 }
170171 }
171172
@@ -204,7 +205,7 @@ public function row( array $row ) {
204205 private function padColumn ($ content , $ column ) {
205206 $ column_name = $ this ->_headers [$ column ];
206207 $ alignment = array_key_exists ($ column_name , $ this ->_alignments ) ? $ this ->_alignments [$ column_name ] : Column::ALIGN_LEFT ;
207-
208+ $ content = str_replace ( "\t" , ' ' , ( string ) $ content );
208209 return $ this ->_characters ['padding ' ] . Colors::pad ( $ content , $ this ->_widths [ $ column ], $ this ->isPreColorized ( $ column ), false , $ alignment ) . $ this ->_characters ['padding ' ];
209210 }
210211
0 commit comments