|
1 | 1 | <?php |
| 2 | + |
2 | 3 | declare(strict_types=1); |
3 | 4 |
|
4 | 5 | namespace seregazhuk\PhpWatcher; |
|
9 | 10 | use seregazhuk\PhpWatcher\Config\Builder; |
10 | 11 | use seregazhuk\PhpWatcher\Config\Config; |
11 | 12 | use seregazhuk\PhpWatcher\Config\InputExtractor; |
12 | | -use seregazhuk\PhpWatcher\Filesystem\ResourceWatcherBased\ChangesListener; |
| 13 | +use seregazhuk\PhpWatcher\Filesystem\Factory as ChangesListenerFactory; |
| 14 | +use seregazhuk\PhpWatcher\Filesystem\ChangesListener; |
13 | 15 | use seregazhuk\PhpWatcher\Screen\Screen; |
14 | 16 | use seregazhuk\PhpWatcher\Screen\SpinnerFactory; |
15 | 17 | use Symfony\Component\Console\Command\Command as BaseCommand; |
@@ -60,32 +62,36 @@ protected function execute(InputInterface $input, OutputInterface $output) |
60 | 62 | $config = $this->buildConfig(new InputExtractor($input)); |
61 | 63 | $spinner = SpinnerFactory::create($output, $config->spinnerDisabled()); |
62 | 64 |
|
63 | | - $this->addTerminationListeners($loop, $spinner); |
64 | 65 |
|
65 | 66 | $screen = new Screen(new SymfonyStyle($input, $output), $spinner); |
66 | | - $filesystem = new ChangesListener($loop); |
| 67 | + $filesystem = ChangesListenerFactory::create($config->watchList(), $loop); |
67 | 68 |
|
68 | 69 | $screen->showOptions($config->watchList()); |
69 | 70 | $processRunner = new ProcessRunner($loop, $screen, $config->command()); |
70 | 71 |
|
71 | 72 | $watcher = new Watcher($loop, $filesystem); |
72 | 73 | $watcher->startWatching( |
73 | 74 | $processRunner, |
74 | | - $config->watchList(), |
75 | 75 | $config->signalToReload(), |
76 | 76 | $config->delay() |
77 | 77 | ); |
78 | 78 |
|
| 79 | + $this->addTerminationListeners($loop, $spinner, $filesystem); |
| 80 | + |
79 | 81 | return 0; |
80 | 82 | } |
81 | 83 |
|
82 | 84 | /** |
83 | 85 | * When terminating the watcher we need to manually restore the cursor after the spinner. |
84 | 86 | */ |
85 | | - private function addTerminationListeners(LoopInterface $loop, SpinnerInterface $spinner): void |
86 | | - { |
87 | | - $func = static function (int $signal) use ($spinner): void { |
| 87 | + private function addTerminationListeners( |
| 88 | + LoopInterface $loop, |
| 89 | + SpinnerInterface $spinner, |
| 90 | + ChangesListener $changesListener |
| 91 | + ): void { |
| 92 | + $func = static function (int $signal) use ($spinner, $changesListener): void { |
88 | 93 | $spinner->end(); |
| 94 | + $changesListener->stop(); |
89 | 95 | exit($signal); |
90 | 96 | }; |
91 | 97 |
|
|
0 commit comments