Sta*_*umo 3 php symfony symfony-console
Symfony 控制台进度条不是在同一行上前进,而是在新行上创建
1/2 [==============>-------------] 50%
! [NOTE] No changes made to Categories/CategoriesSchema
2/2 [============================] 100%
2/2 [============================] 100%
Run Code Online (Sandbox Code Playgroud)
我假设进度条只会在同一行上移动,直到操作完成。这是我的代码
$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();
Run Code Online (Sandbox Code Playgroud)
我做错了什么??
如果进度不是自主的,则进度进度将始终换行,除非您在写入 io 之前清除它。[原文如此]
因此,要么在启动进度条之前写入您的 io。
$io->note('No changes made to ' . ucfirst($name));
$io->newLine();
$progressbar->start();
foreach ($elements as $element) {
$progressbar->advance();
sleep(1);
}
$progressbar->finish();
Run Code Online (Sandbox Code Playgroud)
或者clear()在写入 io 之前调用进度条并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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4120 次 |
| 最近记录: |