Symfony控制台进度条没有在同一行上前进,而是在新行上创建
1/2 [==============>-------------] 50%
! [NOTE] No changes made to Categories/CategoriesSchema
2/2 [============================] 100%
2/2 [============================] 100%
我假设进度条只是移动到同一行,直到操作完成。这是我的代码
$io = new SymfonyStyle($input, $output);
$progressbar = new ProgressBar($output, count($elements));
$progressbar->start();
foreach ($elements as $element) {
//work on element
io->note("No changes made to ".ucfirst($name));
$progressbar->advance();
$io->newLine();
}
$progressbar->finish();
我做错了什么?
答案 0 :(得分:2)
如果不是自主的话,进度推进将始终在新的一行,除非你在写入io之前清除它。 [sic]
所以要么在开始进度条之前写入你的io。
$io->note('No changes made to ' . ucfirst($name));
$io->newLine();
$progressbar->start();
foreach ($elements as $element) {
$progressbar->advance();
sleep(1);
}
$progressbar->finish();
或在写入io之前在进度条上调用clear()
,并在完成后致电display()
。
$progressbar->start();
foreach ($elements as $element) {
if (true /* put conditional here */) {
$progressbar->clear(); //remove progress bar from display
$io->note('No changes made to ' . ucfirst($name));
$io->newLine();
$progressbar->display(); //redraw progress bar in display
}
$progressbar->advance(); //move up a step
sleep(1);
}
$progressbar->finish();