Skip to content

Commit

Permalink
Only show statuses when changed
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Nov 12, 2023
1 parent 2c2e710 commit b1b155e
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions packages/realtime-compiler/src/ConsoleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,41 @@ public function __construct(bool $verbose = false, ?SymfonyOutput $output = null
$this->output = $output ?? new SymfonyOutput();
}

public function printStartMessage(string $host, int $port, array $environment): void
public function printStartMessage(string $host, int $port, array $environment = []): void
{
$url = sprintf('%s://%s:%d', $port === 443 ? 'https' : 'http', $host, $port);

$statusOptions = [
'enabled' => 'green-500',
'disabled' => 'red-500',
'overridden' => 'yellow-500',
];

$dashboardStatusValue = config('hyde.server.dashboard.enabled');
$dashboardOverridden = Arr::has($environment, 'HYDE_SERVER_DASHBOARD');
$dashboardStatus = $dashboardOverridden ? 'overridden' : ($dashboardStatusValue ? 'enabled' : 'disabled');
$dashboardStatusMessage = sprintf('<span class="text-white">Dashboard:</span> <span class="text-%s">%s</span>', $statusOptions[$dashboardStatus], $dashboardStatusValue ? 'enabled' : 'disabled');

$lines = [
'',
sprintf('<span class="text-blue-500">%s</span> <span class="text-gray">%s</span>', 'HydePHP Realtime Compiler', 'v'.Hyde::getInstance()->version()),
'',
sprintf('<span class="text-white">Listening on</span> <a href="%s" class="text-yellow-500">%s</a>', $url, $url),
'',
$dashboardStatusMessage,
'',
];

if ($environment !== []) {
$statusOptions = [
'enabled' => 'green-500',
'disabled' => 'red-500',
];

if (Arr::has($environment, 'HYDE_SERVER_DASHBOARD')) {
$dashboardStatus = Arr::get($environment, 'HYDE_SERVER_DASHBOARD');
$dashboardStatusValue = $dashboardStatus === 'enabled';
$dashboardStatusMessage = sprintf('<span class="text-white">Dashboard:</span> <span class="text-%s">%s</span>', $statusOptions[$dashboardStatus], $dashboardStatusValue ? 'enabled' : 'disabled');
}

$optionLines = Arr::whereNotNull([
$dashboardStatusMessage ?? null,
]);

if ($optionLines !== []) {
$optionLines[] = '';
}

$lines = array_merge($lines, $optionLines);
}

$lineLength = max(array_map('strlen', array_map('strip_tags', $lines)));

$lines = array_map(function (string $line) use ($lineLength): string {
Expand Down

0 comments on commit b1b155e

Please sign in to comment.