Skip to content

Commit 0183da0

Browse files
committed
Merge branch 'master' into output-script-stderr
2 parents 1b9d32c + 5191941 commit 0183da0

File tree

7 files changed

+19
-172
lines changed

7 files changed

+19
-172
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"symfony/yaml": "^4.3",
3232
"react/child-process": "^0.6.1",
3333
"ext-json": "*",
34-
"ext-pcntl": "*"
34+
"ext-pcntl": "*",
35+
"alecrabbit/php-cli-snake": "^0.3.0"
3536
},
3637
"autoload": {
3738
"psr-4": {

php-watcher

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
<?php
44

5-
declare(ticks = 1);
6-
7-
pcntl_signal(SIGTERM, "restore_cursor");
8-
pcntl_signal(SIGINT, "restore_cursor");
9-
105
use seregazhuk\PhpWatcher\WatcherCommand;
116

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

2217
$application->setDefaultCommand($command->getName(), true);
2318
$application->run();
24-
25-
function restore_cursor() {
26-
echo "\033[?25h";
27-
exit;
28-
}

src/Screen/Screen.php renamed to src/Screen.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php declare(strict_types=1);
22

3-
namespace seregazhuk\PhpWatcher\Screen;
3+
namespace seregazhuk\PhpWatcher;
44

5+
use AlecRabbit\Snake\Spinner;
56
use React\ChildProcess\Process;
67
use React\EventLoop\LoopInterface;
78
use seregazhuk\PhpWatcher\Config\WatchList;
8-
use seregazhuk\PhpWatcher\ConsoleApplication;
99
use Symfony\Component\Console\Style\SymfonyStyle;
1010

1111
final class Screen
@@ -14,10 +14,10 @@ final class Screen
1414

1515
private $spinner;
1616

17-
public function __construct(SymfonyStyle $output)
17+
public function __construct(SymfonyStyle $output, Spinner $spinner)
1818
{
1919
$this->output = $output;
20-
$this->spinner = new Spinner();
20+
$this->spinner = $spinner;
2121
}
2222

2323
public function showOptions(WatchList $watchList): void
@@ -82,6 +82,7 @@ public function subscribeToProcessOutput(Process $process): void
8282

8383
public function showSpinner(LoopInterface $loop): void
8484
{
85+
$this->spinner->begin();
8586
$loop->addPeriodicTimer($this->spinner->interval(), function () {
8687
$this->spinner->spin();
8788
});

src/Screen/Cursor.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/Screen/Spinner.php

Lines changed: 0 additions & 127 deletions
This file was deleted.

src/Watcher/Watcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use React\ChildProcess\Process;
66
use React\EventLoop\LoopInterface;
77
use seregazhuk\PhpWatcher\Filesystem\ChangesListener;
8-
use seregazhuk\PhpWatcher\Screen\Screen;
8+
use seregazhuk\PhpWatcher\Screen;
99

1010
final class Watcher
1111
{

src/WatcherCommand.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace seregazhuk\PhpWatcher;
44

5+
use AlecRabbit\Snake\Spinner;
56
use React\ChildProcess\Process;
67
use React\EventLoop\Factory;
78
use seregazhuk\PhpWatcher\Config\Builder;
89
use seregazhuk\PhpWatcher\Filesystem\ChangesListener;
9-
use seregazhuk\PhpWatcher\Screen\Screen;
1010
use seregazhuk\PhpWatcher\Watcher\Watcher;
1111
use Symfony\Component\Console\Command\Command as BaseCommand;
1212
use Symfony\Component\Console\Input\InputArgument;
@@ -34,15 +34,23 @@ protected function configure(): void
3434

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

40-
$screen = new Screen(new SymfonyStyle($input, $output));
41+
$config = (new Builder())->build($input);
42+
$screen = new Screen(new SymfonyStyle($input, $output), new Spinner());
4143
$filesystem = new ChangesListener($loop, $config->watchList());
4244
$watcher = new Watcher($loop, $screen, $filesystem);
4345

4446
$screen->showOptions($config->watchList());
4547
$process = new Process($config->command());
4648
$watcher->startWatching($process, $config->signal(), $config->delay());
4749
}
50+
51+
public function stop(): void
52+
{
53+
(new Spinner())->end();
54+
exit();
55+
}
4856
}

0 commit comments

Comments
 (0)