問題1
使用\n
是正確的,只要\n
沒有逃脫或單引號的字符串。例如:
/** @var ProgressBar $bar */
$bar->setFormat("Current: %current%\nMax: %max%");
問題2
用於該被引用例的代碼單元測試的一部分。該代碼可在870cc23a/Tests/Helper/ProgressBarTest.php#L654
我除去單元測試代碼和創建的工作實例(具有symfony/console ^3.3
測試):
代碼
<?php
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\ConsoleOutput;
require 'vendor/autoload.php';
$bar = new ProgressBar(new ConsoleOutput(), 15);
ProgressBar::setPlaceholderFormatterDefinition('memory', function (ProgressBar $bar) {
static $i = 0;
$mem = 100000 * $i;
$colors = $i++ ? '41;37' : '44;37';
return "\033[" . $colors . 'm ' . Helper::formatMemory($mem) . " \033[0m";
});
$bar->setFormat(" \033[44;37m %title:-37s% \033[0m\n %current%/%max% %bar% %percent:3s%%\n %remaining:-10s% %memory:37s%");
$bar->setBarCharacter($done = "\033[32m●\033[0m");
$bar->setEmptyBarCharacter($empty = "\033[31m●\033[0m");
$bar->setProgressCharacter($progress = "\033[32m➤ \033[0m");
$bar->setMessage('Starting the demo... fingers crossed', 'title');
$bar->start();
for ($i = 0; $i < 15; ++$i) {
usleep(250000);
$bar->advance();
}
$bar->finish();
echo "\n";
作曲
{
"require": {
"symfony/console": "^3.3"
}
}
謝謝!我沒有測試代碼,但我會繼續信任! :) – Aerendir