Symfony 进度条正在新行上重新创建
Symfony Progress Bar is being recreated on new lines
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();
我哪里做错了??
如果进度不是自主的,它将始终在新的一行上,除非您在写入 io 之前将其清除。 [sic]
If you want to output something while the progress bar is running,
call clear() first. After you're done, call display() to show the
progress bar again.
因此,要么在启动进度条之前写入您的 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();
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();
我哪里做错了??
如果进度不是自主的,它将始终在新的一行上,除非您在写入 io 之前将其清除。 [sic]
If you want to output something while the progress bar is running, call clear() first. After you're done, call display() to show the progress bar again.
因此,要么在启动进度条之前写入您的 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();