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: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 2 additions & 4 deletions src/Screen.php → src/Screen/Screen.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php declare(strict_types=1);

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

use React\ChildProcess\Process;
use AlecRabbit\Spinner\SnakeSpinner;
use React\EventLoop\LoopInterface;
use seregazhuk\PhpWatcher\Config\WatchList;
use Symfony\Component\Console\Application;
Expand All @@ -24,7 +23,7 @@ public function __construct(SymfonyStyle $output, Application $application)
$this->output = $output;
$this->appName = $application->getName();
$this->appVersion = $application->getVersion();
$this->spinner = new SnakeSpinner();
$this->spinner = new Spinner();
}

public function showOptions(WatchList $watchList): void
Expand Down Expand Up @@ -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
Expand Down
123 changes: 123 additions & 0 deletions src/Screen/Spinner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php declare(strict_types=1);

namespace seregazhuk\PhpWatcher\Screen;

final class Spinner
{
private const FRAMES = ['⠏', '⠛', '⠹', '⢸', '⣰', '⣤', '⣆', '⡇'];
private const COLORS = [
196,
196,
202,
202,
208,
208,
214,
214,
220,
220,
226,
226,
190,
190,
154,
154,
118,
118,
82,
82,
46,
46,
47,
47,
48,
48,
49,
49,
50,
50,
51,
51,
45,
45,
39,
39,
33,
33,
27,
27,
56,
56,
57,
57,
93,
93,
129,
129,
165,
165,
201,
201,
200,
200,
199,
199,
198,
198,
197,
197
];

private $currentFrameIndex = 0;
private $currentColorIndex = 0;

public function spin(): void
{
$this->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;
}
}
}
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;
use seregazhuk\PhpWatcher\Screen\Screen;

final class Watcher
{
Expand Down
1 change: 1 addition & 0 deletions src/WatcherCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down