A utility for creating animated spinners via Symfony Console.
This utility provides two tools for use with Symfony Console:
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$spinner = new Spinner($output);
$spinner->setMessage('Fetching a really big file from far away');
$spinner->start();
while (getting_the_file()) {
$spinner->advance();
}
$spinner->finish();
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$checklist = new Checklist($output);
$checklist->addItem('Fetching a really big file from far away');
while (getting_the_file()) {
$checklist->updateProgressBar('Still getting the file');
}
$checklist->completePreviousItem();
$checklist->addItem('Doing the next thing');
use Symfony\Component\Process\Process;
use Symfony\Component\Console\Output\ConsoleOutput;
public function runMyCommand() {
$output = new ConsoleOutput();
$checklist = new Checklist($output);
$checklist->addItem('Running a command with lots of output');
$process = new Process([
'composer',
'run-script',
'my-script',
'--no-interaction',
]);
$process->start();
$process->wait(function ($type, $buffer) use ($checklist, $output) {
if (!$output->isVerbose() && $checklist->getItems()) {
$checklist->updateProgressBar($buffer);
}
$output->writeln($buffer, OutputInterface::VERBOSITY_VERY_VERBOSE);
});
if (!$process->isSuccessful()) {
throw new \Exception('Something went wrong! {message}' . $process->getErrorOutput());
}
$checklist->completePreviousItem();
}