Skip to content

Commit 43d07e2

Browse files
committed
Better installer's UI.
1 parent be95da9 commit 43d07e2

4 files changed

Lines changed: 41 additions & 8 deletions

File tree

.github/workflows/vortex-test-common.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ jobs:
114114
runs-on: ubuntu-latest
115115

116116
strategy:
117-
fail-fast: true
117+
fail-fast: false
118118
matrix:
119119
batch: [0, 1, 2, 3, 4]
120120

@@ -183,7 +183,7 @@ jobs:
183183
runs-on: ubuntu-latest
184184

185185
strategy:
186-
fail-fast: true
186+
fail-fast: false
187187
matrix:
188188
batch: [0, 1]
189189

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
110110
Tui::init($output, !$this->config->getNoInteraction());
111111
$this->promptManager = new PromptManager($this->config);
112112

113-
static::header();
113+
$this->header();
114114

115115
$this->promptManager->runPrompts();
116116

@@ -168,7 +168,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
168168
return Command::FAILURE;
169169
}
170170

171-
static::footer();
171+
$this->footer();
172172

173173
// Cleanup should take place only in case of the successful installation.
174174
// Otherwise, the user should be able to re-run the installer.
@@ -396,8 +396,10 @@ protected function header(): void {
396396
by DrevOps
397397
EOT;
398398

399+
$max_header_width = 200;
400+
399401
$logo = Tui::terminalWidth() >= 80 ? $logo_large : $logo_small;
400-
$logo = Tui::center($logo, Tui::terminalWidth(), '');
402+
$logo = Tui::center($logo, Tui::terminalWidth($max_header_width), '');
401403
$logo = Tui::cyan($logo);
402404

403405
$version = $this->getApplication()->getVersion();
@@ -410,7 +412,7 @@ protected function header(): void {
410412
$version = str_replace('@vortex-installer-version@', 'development', $version);
411413
}
412414

413-
$logo .= PHP_EOL . Tui::dim(str_pad(sprintf('Installer version: %s', $version), Tui::terminalWidth() - 2, ' ', STR_PAD_LEFT));
415+
$logo .= PHP_EOL . Tui::dim(str_pad(sprintf('Installer version: %s', $version), Tui::terminalWidth($max_header_width) - 2, ' ', STR_PAD_LEFT));
414416

415417
Tui::note($logo);
416418

@@ -457,6 +459,9 @@ protected function header(): void {
457459
}
458460

459461
Tui::box($content, $title);
462+
463+
Tui::line(Tui::dim('Press any key to continue...'));
464+
Tui::getChar();
460465
}
461466

462467
public function footer(): void {

.vortex/installer/src/Prompts/PromptManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class PromptManager {
6262
*
6363
* Used to display the progress of the prompts.
6464
*/
65-
const TOTAL_RESPONSES = 24;
65+
const TOTAL_RESPONSES = 25;
6666

6767
/**
6868
* Array of responses.
@@ -320,7 +320,7 @@ public function shouldProceed(): bool {
320320
$proceed = TRUE;
321321

322322
if (!$this->config->getNoInteraction()) {
323-
Tui::note(sprintf('Vortex will be installed into your project\'s directory "%s"', $this->config->getDst()));
323+
Tui::line(sprintf('Vortex will be installed into your project\'s directory "%s"', $this->config->getDst()));
324324
$proceed = confirm(
325325
label: 'Proceed with installing Vortex?',
326326
);

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ class Tui {
1818

1919
protected static OutputInterface $output;
2020

21+
protected static bool $isInteractive = TRUE;
22+
2123
public static function init(OutputInterface $output, bool $is_interactive = TRUE): void {
2224
static::$output = $output;
25+
static::$isInteractive = $is_interactive;
2326

2427
// We cannot use any Symfony console styles here, because Laravel Prompts
2528
// does not correctly calculate the length of strings with style tags, which
@@ -51,6 +54,10 @@ public static function error(string $message): void {
5154
error('' . $message);
5255
}
5356

57+
public static function line(string $message, int $padding = 1): void {
58+
static::$output->writeln(str_repeat(' ', max(0, $padding)) . $message);
59+
}
60+
5461
public static function green(string $text): string {
5562
return static::escapeMultiline($text, 32);
5663
}
@@ -87,6 +94,27 @@ public static function undim(string $text): string {
8794
return static::escapeMultiline($text, 22, 22);
8895
}
8996

97+
public static function getChar(): string {
98+
if (!static::$isInteractive) {
99+
return '';
100+
}
101+
102+
// Disable input buffering.
103+
system('stty cbreak -echo');
104+
105+
$res = fopen('php://stdin', 'r');
106+
if ($res === FALSE) {
107+
return '';
108+
}
109+
110+
$char = (string) fgetc($res);
111+
112+
// Restore terminal settings.
113+
system('stty -cbreak echo');
114+
115+
return $char;
116+
}
117+
90118
protected static function escapeMultiline(string $text, int $color_code, int $end_code = 39): string {
91119
$lines = explode("\n", $text);
92120
$colored_lines = array_map(function (string $line) use ($color_code, $end_code): string {

0 commit comments

Comments
 (0)