Skip to content
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"symfony/yaml": "^4.3",
"react/child-process": "^0.6.1",
"ext-json": "*",
"ext-pcntl": "*"
"ext-pcntl": "*",
"alecrabbit/php-cli-snake": "^0.3.0"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 0 additions & 10 deletions php-watcher
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

<?php

declare(ticks = 1);

pcntl_signal(SIGTERM, "restore_cursor");
pcntl_signal(SIGINT, "restore_cursor");

use seregazhuk\PhpWatcher\WatcherCommand;

if (file_exists(__DIR__.'/vendor/autoload.php')) {
Expand All @@ -21,8 +16,3 @@ $application->add($command);

$application->setDefaultCommand($command->getName(), true);
$application->run();

function restore_cursor() {
echo "\033[?25h";
exit;
}
9 changes: 5 additions & 4 deletions src/Screen/Screen.php → src/Screen.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php declare(strict_types=1);

namespace seregazhuk\PhpWatcher\Screen;
namespace seregazhuk\PhpWatcher;

use AlecRabbit\Snake\Spinner;
use React\ChildProcess\Process;
use React\EventLoop\LoopInterface;
use seregazhuk\PhpWatcher\Config\WatchList;
use seregazhuk\PhpWatcher\ConsoleApplication;
use Symfony\Component\Console\Style\SymfonyStyle;

final class Screen
Expand All @@ -14,10 +14,10 @@ final class Screen

private $spinner;

public function __construct(SymfonyStyle $output)
public function __construct(SymfonyStyle $output, Spinner $spinner)
{
$this->output = $output;
$this->spinner = new Spinner();
$this->spinner = $spinner;
}

public function showOptions(WatchList $watchList): void
Expand Down Expand Up @@ -79,6 +79,7 @@ public function subscribeToProcessOutput(Process $process): void

public function showSpinner(LoopInterface $loop): void
{
$this->spinner->begin();
$loop->addPeriodicTimer($this->spinner->interval(), function () {
$this->spinner->spin();
});
Expand Down
26 changes: 0 additions & 26 deletions src/Screen/Cursor.php

This file was deleted.

127 changes: 0 additions & 127 deletions src/Screen/Spinner.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Watcher/Watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use React\ChildProcess\Process;
use React\EventLoop\LoopInterface;
use seregazhuk\PhpWatcher\Filesystem\ChangesListener;
use seregazhuk\PhpWatcher\Screen\Screen;
use seregazhuk\PhpWatcher\Screen;

final class Watcher
{
Expand Down
14 changes: 11 additions & 3 deletions src/WatcherCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace seregazhuk\PhpWatcher;

use AlecRabbit\Snake\Spinner;
use React\ChildProcess\Process;
use React\EventLoop\Factory;
use seregazhuk\PhpWatcher\Config\Builder;
use seregazhuk\PhpWatcher\Filesystem\ChangesListener;
use seregazhuk\PhpWatcher\Screen\Screen;
use seregazhuk\PhpWatcher\Watcher\Watcher;
use Symfony\Component\Console\Command\Command as BaseCommand;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -34,15 +34,23 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output)
{
$config = (new Builder())->build($input);
$loop = Factory::create();
$loop->addSignal(SIGINT, [$this, 'stop']);
$loop->addSignal(SIGTERM, [$this, 'stop']);

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

$screen->showOptions($config->watchList());
$process = new Process($config->command());
$watcher->startWatching($process, $config->signal(), $config->delay());
}

public function stop(): void
{
(new Spinner())->end();
exit();
}
}