@@ -40,7 +40,6 @@ class ProgressBar
40
40
private $ startTime ;
41
41
private $ stepWidth ;
42
42
private $ percent = 0.0 ;
43
- private $ lastMessagesLength = 0 ;
44
43
private $ formatLineCount ;
45
44
private $ messages ;
46
45
private $ overwrite = true ;
@@ -472,7 +471,7 @@ public function clear()
472
471
$ this ->setRealFormat ($ this ->internalFormat ?: $ this ->determineBestFormat ());
473
472
}
474
473
475
- $ this ->overwrite (str_repeat ( "\n" , $ this -> formatLineCount ) );
474
+ $ this ->overwrite ('' );
476
475
}
477
476
478
477
/**
@@ -512,37 +511,22 @@ private function setMaxSteps($max)
512
511
*/
513
512
private function overwrite ($ message )
514
513
{
515
- $ lines = explode ("\n" , $ message );
516
-
517
- // append whitespace to match the line's length
518
- if (null !== $ this ->lastMessagesLength ) {
519
- foreach ($ lines as $ i => $ line ) {
520
- if ($ this ->lastMessagesLength > Helper::strlenWithoutDecoration ($ this ->output ->getFormatter (), $ line )) {
521
- $ lines [$ i ] = str_pad ($ line , $ this ->lastMessagesLength , "\x20" , STR_PAD_RIGHT );
522
- }
523
- }
524
- }
525
-
526
514
if ($ this ->overwrite ) {
527
- // move back to the beginning of the progress bar before redrawing it
515
+ // Move the cursor to the beginning of the line
528
516
$ this ->output ->write ("\x0D" );
529
- } elseif ($ this ->step > 0 ) {
530
- // move to new line
531
- $ this ->output ->writeln ('' );
532
- }
533
517
534
- if ($ this ->formatLineCount ) {
535
- $ this ->output ->write (sprintf ("\033[%dA " , $ this ->formatLineCount ));
536
- }
537
- $ this ->output ->write (implode ("\n" , $ lines ));
518
+ // Erase the line
519
+ $ this ->output ->write ("\x1B[2K " );
538
520
539
- $ this ->lastMessagesLength = 0 ;
540
- foreach ($ lines as $ line ) {
541
- $ len = Helper::strlenWithoutDecoration ($ this ->output ->getFormatter (), $ line );
542
- if ($ len > $ this ->lastMessagesLength ) {
543
- $ this ->lastMessagesLength = $ len ;
521
+ // Erase previous lines
522
+ if ($ this ->formatLineCount > 0 ) {
523
+ $ this ->output ->write (str_repeat ("\x1B[1A \x1B[2K " , $ this ->formatLineCount ));
544
524
}
525
+ } elseif ($ this ->step > 0 ) {
526
+ $ this ->output ->writeln ('' );
545
527
}
528
+
529
+ $ this ->output ->write ($ message );
546
530
}
547
531
548
532
private function determineBestFormat ()
0 commit comments