Skip to content

Commit c4f797a

Browse files
committed
Added a smaller header to the installer.
1 parent 79b05ff commit c4f797a

3 files changed

Lines changed: 222 additions & 15 deletions

File tree

.vortex/installer/src/Command/InstallCommand.php

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -349,26 +349,35 @@ protected function handleDemo(): array|string {
349349
}
350350

351351
protected function header(): void {
352-
$logo = <<<EOT
353-
────────────────────────────────────────────────────────────────────────────────
352+
$logo_large = <<<EOT
354353
355-
██╗ ██╗ ██████╗ ██████╗ ████████╗ ███████╗ ██╗ ██╗
356-
██║ ██║ ██╔═══██╗ ██╔══██╗ ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝
357-
██║ ██║ ██║ ██║ ██████╔╝ ██║ █████╗ ╚███╔╝
358-
╚██╗ ██╔╝ ██║ ██║ ██╔══██╗ ██║ ██╔══╝ ██╔██╗
359-
╚████╔╝ ╚██████╔╝ ██║ ██║ ██║ ███████╗ ██╔╝ ██╗
360-
╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚═╝ ╚═╝
354+
██╗ ██╗ ██████╗ ██████╗ ████████╗ ███████╗ ██╗ ██╗
355+
██║ ██║ ██╔═══██╗ ██╔══██╗ ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝
356+
██║ ██║ ██║ ██║ ██████╔╝ ██║ █████╗ ╚███╔╝
357+
╚██╗ ██╔╝ ██║ ██║ ██╔══██╗ ██║ ██╔══╝ ██╔██╗
358+
╚████╔╝ ╚██████╔╝ ██║ ██║ ██║ ███████╗ ██╔╝ ██╗
359+
╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚═╝ ╚═╝
361360
362-
Drupal project template
361+
Drupal project template
362+
363+
by DrevOps
363364
364-
by DrevOps
365-
────────────────────────────────────────────────────────────────────────────────
366365
EOT;
367366

368-
// Print the logo only if the terminal is wide enough.
369-
if (Tui::terminalWidth() >= 80) {
370-
Tui::note($logo);
371-
}
367+
$logo_small = <<<EOT
368+
▗▖ ▗▖ ▗▄▖ ▗▄▄▖▗▄▄▄▖▗▄▄▄▖▗▖ ▗▖
369+
▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌ █ ▐▌ ▝▚▞▘
370+
▐▌ ▐▌▐▌ ▐▌▐▛▀▚▖ █ ▐▛▀▀▘ ▐▌
371+
▝▚▞▘ ▝▚▄▞▘▐▌ ▐▌ █ ▐▙▄▄▖▗▞▘▝▚▖
372+
373+
Drupal project template
374+
375+
by DrevOps
376+
EOT;
377+
378+
$logo = Tui::terminalWidth() >= 80 ? $logo_large : $logo_small;
379+
$logo = Tui::center($logo, Tui::terminalWidth(), '');
380+
Tui::note($logo);
372381

373382
$title = 'Welcome to Vortex interactive installer';
374383
$content = '';

.vortex/installer/src/Utils/Tui.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,35 @@ public static function box(string $content, ?string $title = NULL, int $width =
9797
table([], $rows);
9898
}
9999

100+
public static function center(string $text, int $width = 80, ?string $border = NULL): string {
101+
$lines = explode(PHP_EOL, $text);
102+
$centered_lines = [];
103+
104+
// Find the maximum line length.
105+
$max_length = 0;
106+
foreach ($lines as $line) {
107+
$line_length = Strings::strlenPlain($line);
108+
if ($line_length > $max_length) {
109+
$max_length = $line_length;
110+
}
111+
}
112+
113+
foreach ($lines as $line) {
114+
$padding = empty($line) ? '' : str_repeat(' ', (int) (($width - $max_length) / 2));
115+
$centered_lines[] = $padding . $line;
116+
}
117+
118+
if ($border) {
119+
$border = str_repeat($border, $width - 2);
120+
array_unshift($centered_lines, '');
121+
array_unshift($centered_lines, $border);
122+
$centered_lines[] = '';
123+
$centered_lines[] = $border;
124+
}
125+
126+
return implode(PHP_EOL, $centered_lines);
127+
}
128+
100129
public static function ok(string $text = 'OK'): void {
101130
$ok = static::green(static::normalizeText("" . $text));
102131
static::note($ok);

.vortex/installer/tests/Unit/TuiTest.php

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,173 @@ public static function dataProviderAction(): array {
120120
];
121121
}
122122

123+
#[DataProvider('dataProviderCenter')]
124+
public function testCenter(
125+
string $text,
126+
int $width,
127+
?string $border,
128+
string $expected,
129+
): void {
130+
$actual = Tui::center($text, $width, $border);
131+
$this->assertSame($expected, $actual);
132+
}
133+
134+
/**
135+
* Data provider for testCenter.
136+
*/
137+
public static function dataProviderCenter(): array {
138+
return [
139+
140+
'single line text with default width' => [
141+
'text' => 'Hello',
142+
'width' => 80,
143+
'border' => NULL,
144+
'expected' => <<<'EXPECTED'
145+
Hello
146+
EXPECTED,
147+
],
148+
149+
'single line text with custom width' => [
150+
'text' => 'Test',
151+
'width' => 20,
152+
'border' => NULL,
153+
'expected' => <<<'EXPECTED'
154+
Test
155+
EXPECTED,
156+
],
157+
158+
'multiline text without border' => [
159+
'text' => <<<'TEXT'
160+
Line 1
161+
Line 2
162+
TEXT,
163+
'width' => 20,
164+
'border' => NULL,
165+
'expected' => <<<'EXPECTED'
166+
Line 1
167+
Line 2
168+
EXPECTED,
169+
],
170+
171+
'multiline text with different line lengths' => [
172+
'text' => <<<'TEXT'
173+
Short
174+
Longer line
175+
X
176+
TEXT,
177+
'width' => 30,
178+
'border' => NULL,
179+
'expected' => <<<'EXPECTED'
180+
Short
181+
Longer line
182+
X
183+
EXPECTED,
184+
],
185+
186+
'empty line in multiline text' => [
187+
'text' => <<<'TEXT'
188+
Line 1
189+
190+
Line 3
191+
TEXT,
192+
'width' => 20,
193+
'border' => NULL,
194+
'expected' => <<<'EXPECTED'
195+
Line 1
196+
197+
Line 3
198+
EXPECTED,
199+
],
200+
201+
'single line text with border' => [
202+
'text' => 'Hello',
203+
'width' => 20,
204+
'border' => '=',
205+
'expected' => <<<'EXPECTED'
206+
==================
207+
208+
Hello
209+
210+
==================
211+
EXPECTED,
212+
],
213+
214+
'multiline text with border' => [
215+
'text' => <<<'TEXT'
216+
Line 1
217+
Line 2
218+
TEXT,
219+
'width' => 25,
220+
'border' => '-',
221+
'expected' => <<<'EXPECTED'
222+
-----------------------
223+
224+
Line 1
225+
Line 2
226+
227+
-----------------------
228+
EXPECTED,
229+
],
230+
231+
'text with exact width match' => [
232+
'text' => 'Exact',
233+
'width' => 5,
234+
'border' => NULL,
235+
'expected' => <<<'EXPECTED'
236+
Exact
237+
EXPECTED,
238+
],
239+
240+
'text wider than available width' => [
241+
'text' => 'Very long text',
242+
'width' => 20,
243+
'border' => NULL,
244+
'expected' => <<<'EXPECTED'
245+
Very long text
246+
EXPECTED,
247+
],
248+
249+
'single character text' => [
250+
'text' => 'X',
251+
'width' => 10,
252+
'border' => NULL,
253+
'expected' => <<<'EXPECTED'
254+
X
255+
EXPECTED,
256+
],
257+
258+
'empty text' => [
259+
'text' => '',
260+
'width' => 10,
261+
'border' => NULL,
262+
'expected' => <<<'EXPECTED'
263+
264+
EXPECTED,
265+
],
266+
267+
'whitespace only text' => [
268+
'text' => ' ',
269+
'width' => 15,
270+
'border' => NULL,
271+
'expected' => <<<'EXPECTED'
272+
273+
EXPECTED,
274+
],
275+
276+
'text with border using different character' => [
277+
'text' => 'Bordered',
278+
'width' => 16,
279+
'border' => '*',
280+
'expected' => <<<'EXPECTED'
281+
**************
282+
283+
Bordered
284+
285+
**************
286+
EXPECTED,
287+
],
288+
289+
];
290+
}
291+
123292
}

0 commit comments

Comments
 (0)