Symfony Console Progress Bar在同一行上没有前进,而是在新行上创建
1/2 [==============>-------------] 50%
! [NOTE] No changes made to Categories/CategoriesSchema
2/2 [============================] 100%
2/2 [============================] 100%
i在假设下,进度条将仅在同一条线上移动,直到操作完成为止。这是我的代码
$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();
我做错了什么?
如果不自主,进度的进步将始终在新行上,除非您在写入IO之前将其清除。[sic]
如果您想在进度栏运行时输出某些内容, 首先致电Clear((。完成后,请致电Display((显示 再次进度栏。
所以要么在开始进度栏之前写信给您的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();