Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use spinner in output #11

Merged
merged 2 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
build:
environment:
php: 7.1.12
php: 7.2

nodes:
analysis:
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 7.1
- 7.2
- 7.3

Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
}
],
"require": {
"php": "^7.1",
"php": "^7.2",
"yosymfony/resource-watcher": "^2.0",
"symfony/process": "^4.3",
"symfony/console": "^4.3",
"react/event-loop": "^1.1",
"symfony/yaml": "^4.3",
"react/child-process": "^0.6.1",
"ext-json": "*"
"ext-json": "*",
"alecrabbit/php-console-spinner": "^0.51.1"
},
"autoload": {
"psr-4": {
Expand All @@ -34,6 +35,6 @@
"php-watcher"
],
"require-dev": {
"phpunit/phpunit": "^7.5"
"phpunit/phpunit": "^8.0"
}
}
14 changes: 14 additions & 0 deletions src/Screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace seregazhuk\PhpWatcher;

use React\ChildProcess\Process;
use AlecRabbit\Spinner\SnakeSpinner;
use React\EventLoop\LoopInterface;
use seregazhuk\PhpWatcher\Config\WatchList;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Style\SymfonyStyle;
Expand All @@ -15,11 +17,14 @@ final class Screen

private $appVersion;

private $spinner;

public function __construct(SymfonyStyle $output, Application $application)
{
$this->output = $output;
$this->appName = $application->getName();
$this->appVersion = $application->getVersion();
$this->spinner = new SnakeSpinner();
}

public function showOptions(WatchList $watchList): void
Expand Down Expand Up @@ -62,6 +67,7 @@ public function start(string $command): void

public function restarting(string $command): void
{
$this->spinner->erase();
$this->output->writeln('');
$this->info('restarting due to changes...');
$this->start($command);
Expand All @@ -74,6 +80,14 @@ public function subscribeToProcessOutput(Process $process): void
});
}

public function showSpinner(LoopInterface $loop): void
{
$loop->addPeriodicTimer($this->spinner->interval(), function () {
$this->spinner->spin();
});
$this->spinner->begin();
}

private function message(string $text): string
{
return sprintf('[%s] %s', $this->appName, $text);
Expand Down
2 changes: 1 addition & 1 deletion src/Watcher/Watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(LoopInterface $loop, Screen $screen, ChangesListener
public function startWatching(Process $process, float $delayToRestart): void
{
$this->screen->start($process->getCommand());

$this->screen->showSpinner($this->loop);
$this->startProcess($process);

$this->filesystemListener->start(function () use ($process, $delayToRestart) {
Expand Down
3 changes: 1 addition & 2 deletions src/WatcherCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output)
{
$config = (new Builder())->build($input);
$screen = new Screen(new SymfonyStyle($input, $output), $this->getApplication());

$loop = Factory::create();

$screen = new Screen(new SymfonyStyle($input, $output), $this->getApplication());
$filesystem = new ChangesListener($loop, $config->watchList());
$watcher = new Watcher($loop, $screen, $filesystem);

Expand Down