diff --git a/composer.json b/composer.json index c3b3c88..fb68cfc 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,7 @@ "react/event-loop": "^1.1", "symfony/yaml": "^4.3", "react/child-process": "^0.6.1", - "ext-json": "*", - "alecrabbit/php-console-spinner": "^0.51.1" + "ext-json": "*" }, "autoload": { "psr-4": { diff --git a/src/Screen.php b/src/Screen/Screen.php similarity index 94% rename from src/Screen.php rename to src/Screen/Screen.php index 450d4c1..556521a 100644 --- a/src/Screen.php +++ b/src/Screen/Screen.php @@ -1,9 +1,8 @@ output = $output; $this->appName = $application->getName(); $this->appVersion = $application->getVersion(); - $this->spinner = new SnakeSpinner(); + $this->spinner = new Spinner(); } public function showOptions(WatchList $watchList): void @@ -85,7 +84,6 @@ public function showSpinner(LoopInterface $loop): void $loop->addPeriodicTimer($this->spinner->interval(), function () { $this->spinner->spin(); }); - $this->spinner->begin(); } private function message(string $text): string diff --git a/src/Screen/Spinner.php b/src/Screen/Spinner.php new file mode 100644 index 0000000..f4464e4 --- /dev/null +++ b/src/Screen/Spinner.php @@ -0,0 +1,123 @@ +output(); + $this->increment(); + $this->hideCursor(); + } + + public function interval(): float + { + return 1/10; + } + + public function erase(): void + { + echo "\033[1K"; + } + + private function currentColor(): string + { + return '38;5;' . self::COLORS[$this->currentColorIndex]. 'm'; + } + + private function currentFrame(): string + { + return self::FRAMES[$this->currentFrameIndex]; + } + + private function output(): void + { + echo "\e[{$this->currentColor()}{$this->currentFrame()}\e[0m\r"; + } + + private function hideCursor(): void + { + echo "\033[?25l"; + } + + private function increment(): void + { + $this->currentFrameIndex ++; + if ($this->currentFrameIndex === count(self::FRAMES)) { + $this->currentFrameIndex = 0; + } + + $this->currentColorIndex ++; + if ($this->currentColorIndex === count(self::COLORS)) { + $this->currentColorIndex = 0; + } + } +} diff --git a/src/Watcher/Watcher.php b/src/Watcher/Watcher.php index 151210e..f75686d 100644 --- a/src/Watcher/Watcher.php +++ b/src/Watcher/Watcher.php @@ -5,7 +5,7 @@ use React\ChildProcess\Process; use React\EventLoop\LoopInterface; use seregazhuk\PhpWatcher\Filesystem\ChangesListener; -use seregazhuk\PhpWatcher\Screen; +use seregazhuk\PhpWatcher\Screen\Screen; final class Watcher { diff --git a/src/WatcherCommand.php b/src/WatcherCommand.php index 7b8a646..eb22fb4 100644 --- a/src/WatcherCommand.php +++ b/src/WatcherCommand.php @@ -6,6 +6,7 @@ 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;