Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/grasmash/symfony-console-checklist
A utility for creating animated spinners via Symfony Console.
https://github.com/grasmash/symfony-console-checklist
Last synced: 2 months ago
JSON representation
A utility for creating animated spinners via Symfony Console.
- Host: GitHub
- URL: https://github.com/grasmash/symfony-console-checklist
- Owner: grasmash
- Created: 2023-01-18T16:09:20.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-19T23:34:11.000Z (almost 2 years ago)
- Last Synced: 2024-10-03T22:41:00.765Z (3 months ago)
- Language: PHP
- Size: 42 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Symfony Console Spinner
This utility provides two tools for use with Symfony Console:
1. An animated spinner class. This is a wrapper around Symfony's built-in Progress Bar which will show a colored, animated spinner. It requires advance() to be called in order for the spinner to spin.
2. A checklist class. This is a wrapper around the Spinner. It allows you to emit a checklist item, display a spinner next to it to indicate that it is in progress, and write a "message detail" under the item.![image](https://user-images.githubusercontent.com/539205/213492499-014d79f3-7b8b-4362-9f31-72f9dcaaa37b.png)
## Usage
### Simple Spinner
```php
$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();
```### Simple Checklist
```php
$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');
```### Advanced Checklist Example
```php
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();
}
```