icanhazstring / symfony-console-spinner
自定义symfony进度条旋转器
1.1.1
2024-03-27 13:04 UTC
Requires
- php: ^7.3 || ^8.0
- symfony/console: ^4.3 || ^5.0 || ^6.0 || ^7.0
README
带有旋转器的自定义symfony进度条。
我想有一个进度条来显示长时间运行的任务,比如等待外部资源可用。这就是我发现了alecrabbit/php-cli-snake的地方。
我尝试使用symfony/console模仿这个动画,这是结果
安装
使用composer安装这个小包
composer require icanhazstring/symfony-console-spinner
用法
要使用旋转器,只需像symfony中的默认ProgressBar
一样实例化SpinnerProgress
,给它提供OutputInterface
和要处理的项目最大计数
public function execute(OutputInterface $output, InputInterface $input) { $spinner = new SpinnerProgress($output, 100); for($i = 0; $i < 100; $i++) { usleep(1000); $spinner->advance(); } $spinner->finish(); }
如果您想更改某些内容,例如将经过的时间添加到输出格式中,您也可以获取底层的ProgressBar
实例
$spinner = new SpinnerProgress($output, 100); $spinner->getProgressBar()->setFormat('%bar% (%elapsed:6s%) %message%');
许可证
本软件包在MIT许可证下发布。