Skip to content

Commit 401c78b

Browse files
committed
Refactor to handle start message dynamically
1 parent 3b8f093 commit 401c78b

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

packages/realtime-compiler/src/ConsoleOutput.php

+23-19
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,32 @@ public function __construct(bool $verbose = false, ?SymfonyOutput $output = null
2626
public function printStartMessage(string $host, int $port): void
2727
{
2828
$title = 'HydePHP Realtime Compiler';
29-
$version = ' v'.Hyde::version();
29+
$version = 'v'.Hyde::version();
3030

3131
$url = sprintf('%s://%s:%d', $port === 443 ? 'https' : 'http', $host, $port);
3232

33-
$width = max(strlen("$title $version"), strlen("Listening on $url") + 1) + 1;
34-
$spacing = str_repeat(' ', $width);
35-
$lines = str_repeat('', $width);
36-
37-
$line1 = '&nbsp;'.sprintf('<span class="text-blue-500">%s</span>&nbsp;<span class="text-gray">%s</span>', $title, $version).str_repeat('&nbsp;', $width - strlen("$title $version"));
38-
$line2 = '&nbsp;'.sprintf('<span class="text-white">Listening on </span>&nbsp;<a href="%s" class="text-yellow-500">%s</a>', $url, $url).str_repeat('&nbsp;', $width - strlen("Listening on $url") - 1);
39-
render(<<<HTML
40-
<div class="text-green-500">
41-
<br>
42-
&nbsp;╭{$lines}╮<br>
43-
&nbsp;│{$spacing}│<br>
44-
&nbsp;│{$line1}│<br>
45-
&nbsp;│{$spacing}│<br>
46-
&nbsp;│{$line2}│<br>
47-
&nbsp;│{$spacing}│<br>
48-
&nbsp;╰{$lines}╯<br>
49-
</div>
50-
HTML);
33+
$lines = [
34+
sprintf('<span class="text-blue-500">%s</span> <span class="text-gray">%s</span>', $title, $version),
35+
'',
36+
sprintf('<span class="text-white">Listening on</span> <a href="%s" class="text-yellow-500">%s</a>', $url, $url),
37+
];
38+
39+
$lineLength = max(array_map('strlen', array_map('strip_tags', $lines)));
40+
41+
$lines = array_map(function (string $line) use ($lineLength): string {
42+
return sprintf('&nbsp;│&nbsp;<span class="text-white">%s</span>%s│',
43+
$line, str_repeat('&nbsp;', ($lineLength - strlen(strip_tags($line))) + 1)
44+
);
45+
}, array_merge([''], $lines, ['']));
46+
47+
$topLine = sprintf('&nbsp;╭%s╮', str_repeat('', $lineLength + 2));
48+
$bottomLine = sprintf('&nbsp;╰%s╯', str_repeat('', $lineLength + 2));
49+
50+
$lines = array_merge([$topLine], $lines, [$bottomLine]);
51+
52+
$body = implode('<br>', array_merge([''], $lines, ['']));
53+
54+
render("<div class=\"text-green-500\">$body</div>");
5155
}
5256

5357
public function getFormatter(): Closure

0 commit comments

Comments
 (0)