Skip to content

Commit f805673

Browse files
committed
Progress block fixes for multiline text
1 parent f418447 commit f805673

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/app/Console/Commands/Traits/PrettyCommandOutput.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,15 @@ public function progressBlock(string $text, string $progress = 'running', string
187187
$width = min($this->terminal->getWidth(), $this->maxWidth);
188188
$dotLength = $width - 5 - strlen(strip_tags($text.$progress));
189189

190+
// In case it doesn't fit the screen, add enough lines with dots
191+
$textLength = strlen(strip_tags($text)) + 20;
192+
$dotLength += floor($textLength / $width) * $width;
193+
194+
$this->consoleProgress = $progress;
195+
190196
$this->output->write(sprintf(
191197
" $text <fg=gray>%s</> <fg=$color>%s</>",
192-
str_repeat('.', ($dotLength < 1) ? 1 : $dotLength),
198+
str_repeat('.', max(1, $dotLength)),
193199
strtoupper($progress)
194200
));
195201
}
@@ -199,14 +205,17 @@ public function progressBlock(string $text, string $progress = 'running', string
199205
*
200206
* @return void
201207
*/
202-
public function closeProgressBlock(string $text = 'done', string $color = 'green')
208+
public function closeProgressBlock(string $progress = 'done', string $color = 'green')
203209
{
204-
$this->deleteChars(20);
210+
$deleteSize = max(strlen($this->consoleProgress ?? ''), strlen($progress)) + 1;
211+
$newDotSize = $deleteSize - strlen($progress) - 1;
212+
213+
$this->deleteChars($deleteSize);
205214

206215
$this->output->write(sprintf(
207216
"<fg=gray>%s</> <fg=$color>%s</>",
208-
str_repeat('.', 19 - strlen($text)),
209-
strtoupper($text),
217+
$newDotSize > 0 ? str_repeat('.', $newDotSize) : '',
218+
strtoupper($progress),
210219
));
211220
$this->newLine();
212221
}

0 commit comments

Comments
 (0)