File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed
src/Symfony/Component/Console Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -603,13 +603,19 @@ private function buildLine()
603
603
};
604
604
$ line = preg_replace_callback ($ regex , $ callback , $ this ->format );
605
605
606
- $ lineLength = Helper::strlenWithoutDecoration ($ this ->output ->getFormatter (), $ line );
606
+ // gets string length for each sub line with multiline format
607
+ $ linesLength = array_map (function ($ subLine ) {
608
+ return Helper::strlenWithoutDecoration ($ this ->output ->getFormatter (), rtrim ($ subLine , "\r" ));
609
+ }, explode ("\n" , $ line ));
610
+
611
+ $ linesWidth = max ($ linesLength );
612
+
607
613
$ terminalWidth = $ this ->terminal ->getWidth ();
608
- if ($ lineLength <= $ terminalWidth ) {
614
+ if ($ linesWidth <= $ terminalWidth ) {
609
615
return $ line ;
610
616
}
611
617
612
- $ this ->setBarWidth ($ this ->barWidth - $ lineLength + $ terminalWidth );
618
+ $ this ->setBarWidth ($ this ->barWidth - $ linesWidth + $ terminalWidth );
613
619
614
620
return preg_replace_callback ($ regex , $ callback , $ this ->format );
615
621
}
Original file line number Diff line number Diff line change @@ -754,4 +754,22 @@ protected function generateOutput($expected)
754
754
755
755
return "\x0D\x1B[2K " .($ count ? str_repeat ("\x1B[1A \x1B[2K " , $ count ) : '' ).$ expected ;
756
756
}
757
+
758
+ public function testBarWidthWithMultilineFormat ()
759
+ {
760
+ putenv ('COLUMNS=10 ' );
761
+
762
+ $ bar = new ProgressBar ($ output = $ this ->getOutputStream ());
763
+ $ bar ->setFormat ("%bar% \n0123456789 " );
764
+
765
+ // before starting
766
+ $ bar ->setBarWidth (5 );
767
+ $ this ->assertEquals (5 , $ bar ->getBarWidth ());
768
+
769
+ // after starting
770
+ $ bar ->start ();
771
+ rewind ($ output ->getStream ());
772
+ $ this ->assertEquals (5 , $ bar ->getBarWidth (), stream_get_contents ($ output ->getStream ()));
773
+ putenv ('COLUMNS=120 ' );
774
+ }
757
775
}
You can’t perform that action at this time.
0 commit comments