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
39 changes: 24 additions & 15 deletions .vortex/installer/src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,26 +349,35 @@ protected function handleDemo(): array|string {
}

protected function header(): void {
$logo = <<<EOT
────────────────────────────────────────────────────────────────────────────────
$logo_large = <<<EOT

██╗ ██╗ ██████╗ ██████╗ ████████╗ ███████╗ ██╗ ██╗
██║ ██║ ██╔═══██╗ ██╔══██╗ ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝
██║ ██║ ██║ ██║ ██████╔╝ ██║ █████╗ ╚███╔╝
╚██╗ ██╔╝ ██║ ██║ ██╔══██╗ ██║ ██╔══╝ ██╔██╗
╚████╔╝ ╚██████╔╝ ██║ ██║ ██║ ███████╗ ██╔╝ ██╗
╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚═╝ ╚═╝
██╗ ██╗ ██████╗ ██████╗ ████████╗ ███████╗ ██╗ ██╗
██║ ██║ ██╔═══██╗ ██╔══██╗ ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝
██║ ██║ ██║ ██║ ██████╔╝ ██║ █████╗ ╚███╔╝
╚██╗ ██╔╝ ██║ ██║ ██╔══██╗ ██║ ██╔══╝ ██╔██╗
╚████╔╝ ╚██████╔╝ ██║ ██║ ██║ ███████╗ ██╔╝ ██╗
╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚═╝ ╚═╝

Drupal project template
Drupal project template

by DrevOps

by DrevOps
────────────────────────────────────────────────────────────────────────────────
EOT;

// Print the logo only if the terminal is wide enough.
if (Tui::terminalWidth() >= 80) {
Tui::note($logo);
}
$logo_small = <<<EOT
▗▖ ▗▖ ▗▄▖ ▗▄▄▖▗▄▄▄▖▗▄▄▄▖▗▖ ▗▖
▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌ █ ▐▌ ▝▚▞▘
▐▌ ▐▌▐▌ ▐▌▐▛▀▚▖ █ ▐▛▀▀▘ ▐▌
▝▚▞▘ ▝▚▄▞▘▐▌ ▐▌ █ ▐▙▄▄▖▗▞▘▝▚▖

Drupal project template

by DrevOps
EOT;

$logo = Tui::terminalWidth() >= 80 ? $logo_large : $logo_small;
$logo = Tui::center($logo, Tui::terminalWidth(), '─');
Tui::note($logo);

$title = 'Welcome to Vortex interactive installer';
$content = '';
Expand Down
29 changes: 29 additions & 0 deletions .vortex/installer/src/Utils/Tui.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,35 @@ public static function box(string $content, ?string $title = NULL, int $width =
table([], $rows);
}

public static function center(string $text, int $width = 80, ?string $border = NULL): string {
$lines = explode(PHP_EOL, $text);
$centered_lines = [];

// Find the maximum line length.
$max_length = 0;
foreach ($lines as $line) {
$line_length = Strings::strlenPlain($line);
if ($line_length > $max_length) {
$max_length = $line_length;
}
}

foreach ($lines as $line) {
$padding = empty($line) ? '' : str_repeat(' ', (int) (($width - $max_length) / 2));
$centered_lines[] = $padding . $line;
}

if ($border) {
$border = str_repeat($border, $width - 2);
array_unshift($centered_lines, '');
array_unshift($centered_lines, $border);
$centered_lines[] = '';
$centered_lines[] = $border;
}

return implode(PHP_EOL, $centered_lines);
}

public static function ok(string $text = 'OK'): void {
$ok = static::green(static::normalizeText("✅ " . $text));
static::note($ok);
Expand Down
169 changes: 169 additions & 0 deletions .vortex/installer/tests/Unit/TuiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,173 @@ public static function dataProviderAction(): array {
];
}

#[DataProvider('dataProviderCenter')]
public function testCenter(
string $text,
int $width,
?string $border,
string $expected,
): void {
$actual = Tui::center($text, $width, $border);
$this->assertSame($expected, $actual);
}

/**
* Data provider for testCenter.
*/
public static function dataProviderCenter(): array {
return [

'single line text with default width' => [
'text' => 'Hello',
'width' => 80,
'border' => NULL,
'expected' => <<<'EXPECTED'
Hello
EXPECTED,
],

'single line text with custom width' => [
'text' => 'Test',
'width' => 20,
'border' => NULL,
'expected' => <<<'EXPECTED'
Test
EXPECTED,
],

'multiline text without border' => [
'text' => <<<'TEXT'
Line 1
Line 2
TEXT,
'width' => 20,
'border' => NULL,
'expected' => <<<'EXPECTED'
Line 1
Line 2
EXPECTED,
],

'multiline text with different line lengths' => [
'text' => <<<'TEXT'
Short
Longer line
X
TEXT,
'width' => 30,
'border' => NULL,
'expected' => <<<'EXPECTED'
Short
Longer line
X
EXPECTED,
],

'empty line in multiline text' => [
'text' => <<<'TEXT'
Line 1

Line 3
TEXT,
'width' => 20,
'border' => NULL,
'expected' => <<<'EXPECTED'
Line 1

Line 3
EXPECTED,
],

'single line text with border' => [
'text' => 'Hello',
'width' => 20,
'border' => '=',
'expected' => <<<'EXPECTED'
==================

Hello

==================
EXPECTED,
],

'multiline text with border' => [
'text' => <<<'TEXT'
Line 1
Line 2
TEXT,
'width' => 25,
'border' => '-',
'expected' => <<<'EXPECTED'
-----------------------

Line 1
Line 2

-----------------------
EXPECTED,
],

'text with exact width match' => [
'text' => 'Exact',
'width' => 5,
'border' => NULL,
'expected' => <<<'EXPECTED'
Exact
EXPECTED,
],

'text wider than available width' => [
'text' => 'Very long text',
'width' => 20,
'border' => NULL,
'expected' => <<<'EXPECTED'
Very long text
EXPECTED,
],

'single character text' => [
'text' => 'X',
'width' => 10,
'border' => NULL,
'expected' => <<<'EXPECTED'
X
EXPECTED,
],

'empty text' => [
'text' => '',
'width' => 10,
'border' => NULL,
'expected' => <<<'EXPECTED'

EXPECTED,
],

'whitespace only text' => [
'text' => ' ',
'width' => 15,
'border' => NULL,
'expected' => <<<'EXPECTED'

EXPECTED,
],

'text with border using different character' => [
'text' => 'Bordered',
'width' => 16,
'border' => '*',
'expected' => <<<'EXPECTED'
**************

Bordered

**************
EXPECTED,
],

];
}

}