From 3c5afcf58a14831f2f5db3b1c51bd200a0b3ca03 Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Mon, 25 Nov 2024 15:07:48 -0600 Subject: [PATCH 01/14] Make all written text built-in styles so that their styles can be customized --- README.md | 32 ++++++++ src/Helper/OutputHelper.php | 18 ++--- src/IO/Interactor.php | 153 ++---------------------------------- src/Input/Command.php | 8 +- src/Output/Color.php | 71 ++++++----------- tests/Output/ColorTest.php | 11 +-- 6 files changed, 81 insertions(+), 212 deletions(-) diff --git a/README.md b/README.md index 4976efc..26afffc 100644 --- a/README.md +++ b/README.md @@ -450,6 +450,38 @@ Ahc\Cli\Output\Color::style('mystyle', [ echo $color->mystyle('My text'); ``` +#### Built-in styles + +There are a number of pre-defined built-in styles that allows you granular customization to different output conditions such as help and prompts: + + - answer + - choice + - comment + - error + - help_category + - help_description + - help_example + - help_footer + - help_group + - help_header + - help_item + - help_summary + - help_text + - info + - ok + - question + - version + - warn + +Overriding a built-in style works the same way as defining a new style: + +```php +Ahc\Cli\Output\Color::style('error', [ + 'fg' => Ahc\Cli\Output\Color::RED, + 'bold' => 1, +]); +``` + ### Cursor Move cursor around, erase line up or down, clear screen. diff --git a/src/Helper/OutputHelper.php b/src/Helper/OutputHelper.php index 7cf9c5c..df518c8 100644 --- a/src/Helper/OutputHelper.php +++ b/src/Helper/OutputHelper.php @@ -182,13 +182,13 @@ public function showCommandsHelp(array $commands, string $header = '', string $f protected function showHelp(string $for, array $items, string $header = '', string $footer = ''): void { if ($header) { - $this->writer->bold($header, true); + $this->writer->help_header($header, true); } - $this->writer->eol()->boldGreen($for . ':', true); + $this->writer->eol()->help_category($for . ':', true); if (empty($items)) { - $this->writer->bold(' (n/a)', true); + $this->writer->help_text(' (n/a)', true); return; } @@ -200,17 +200,17 @@ protected function showHelp(string $for, array $items, string $header = '', stri foreach ($this->sortItems($items, $padLen, $for) as $item) { $name = $this->getName($item); if ($for === 'Commands' && $lastGroup !== $group = $item->group()) { - $this->writer->boldYellow($group ?: '*', true); + $this->writer->help_group($group ?: '*', true); $lastGroup = $group; } $desc = str_replace(["\r\n", "\n"], str_pad("\n", $padLen + $space + 3), $item->desc($withDefault)); - $this->writer->bold(' ' . str_pad($name, $padLen + $space)); - $this->writer->comment($desc, true); + $this->writer->help_item(' ' . str_pad($name, $padLen + $space)); + $this->writer->help_description($desc, true); } if ($footer) { - $this->writer->eol()->yellow($footer, true); + $this->writer->eol()->help_footer($footer, true); } } @@ -224,7 +224,7 @@ public function showUsage(string $usage): self $usage = str_replace('$0', $_SERVER['argv'][0] ?? '[cmd]', $usage); if (!str_contains($usage, ' ## ')) { - $this->writer->eol()->boldGreen('Usage Examples:', true)->colors($usage)->eol(); + $this->writer->eol()->help_category('Usage Examples:', true)->colors($usage)->eol(); return $this; } @@ -241,7 +241,7 @@ public function showUsage(string $usage): self return str_pad('# ', $maxlen - array_shift($lines), ' ', STR_PAD_LEFT); }, $usage); - $this->writer->eol()->boldGreen('Usage Examples:', true)->colors($usage)->eol(); + $this->writer->eol()->help_category('Usage Examples:', true)->colors($usage)->eol(); return $this; } diff --git a/src/IO/Interactor.php b/src/IO/Interactor.php index 37c5a78..e711097 100644 --- a/src/IO/Interactor.php +++ b/src/IO/Interactor.php @@ -37,145 +37,6 @@ * @license MIT * * @link https://github.com/adhocore/cli - * - * @method Writer bgBlack($text, $eol = false) - * @method Writer bgBlue($text, $eol = false) - * @method Writer bgCyan($text, $eol = false) - * @method Writer bgGreen($text, $eol = false) - * @method Writer bgPurple($text, $eol = false) - * @method Writer bgRed($text, $eol = false) - * @method Writer bgWhite($text, $eol = false) - * @method Writer bgYellow($text, $eol = false) - * @method Writer black($text, $eol = false) - * @method Writer blackBgBlue($text, $eol = false) - * @method Writer blackBgCyan($text, $eol = false) - * @method Writer blackBgGreen($text, $eol = false) - * @method Writer blackBgPurple($text, $eol = false) - * @method Writer blackBgRed($text, $eol = false) - * @method Writer blackBgWhite($text, $eol = false) - * @method Writer blackBgYellow($text, $eol = false) - * @method Writer blue($text, $eol = false) - * @method Writer blueBgBlack($text, $eol = false) - * @method Writer blueBgCyan($text, $eol = false) - * @method Writer blueBgGreen($text, $eol = false) - * @method Writer blueBgPurple($text, $eol = false) - * @method Writer blueBgRed($text, $eol = false) - * @method Writer blueBgWhite($text, $eol = false) - * @method Writer blueBgYellow($text, $eol = false) - * @method Writer bold($text, $eol = false) - * @method Writer boldBlack($text, $eol = false) - * @method Writer boldBlackBgBlue($text, $eol = false) - * @method Writer boldBlackBgCyan($text, $eol = false) - * @method Writer boldBlackBgGreen($text, $eol = false) - * @method Writer boldBlackBgPurple($text, $eol = false) - * @method Writer boldBlackBgRed($text, $eol = false) - * @method Writer boldBlackBgWhite($text, $eol = false) - * @method Writer boldBlackBgYellow($text, $eol = false) - * @method Writer boldBlue($text, $eol = false) - * @method Writer boldBlueBgBlack($text, $eol = false) - * @method Writer boldBlueBgCyan($text, $eol = false) - * @method Writer boldBlueBgGreen($text, $eol = false) - * @method Writer boldBlueBgPurple($text, $eol = false) - * @method Writer boldBlueBgRed($text, $eol = false) - * @method Writer boldBlueBgWhite($text, $eol = false) - * @method Writer boldBlueBgYellow($text, $eol = false) - * @method Writer boldCyan($text, $eol = false) - * @method Writer boldCyanBgBlack($text, $eol = false) - * @method Writer boldCyanBgBlue($text, $eol = false) - * @method Writer boldCyanBgGreen($text, $eol = false) - * @method Writer boldCyanBgPurple($text, $eol = false) - * @method Writer boldCyanBgRed($text, $eol = false) - * @method Writer boldCyanBgWhite($text, $eol = false) - * @method Writer boldCyanBgYellow($text, $eol = false) - * @method Writer boldGreen($text, $eol = false) - * @method Writer boldGreenBgBlack($text, $eol = false) - * @method Writer boldGreenBgBlue($text, $eol = false) - * @method Writer boldGreenBgCyan($text, $eol = false) - * @method Writer boldGreenBgPurple($text, $eol = false) - * @method Writer boldGreenBgRed($text, $eol = false) - * @method Writer boldGreenBgWhite($text, $eol = false) - * @method Writer boldGreenBgYellow($text, $eol = false) - * @method Writer boldPurple($text, $eol = false) - * @method Writer boldPurpleBgBlack($text, $eol = false) - * @method Writer boldPurpleBgBlue($text, $eol = false) - * @method Writer boldPurpleBgCyan($text, $eol = false) - * @method Writer boldPurpleBgGreen($text, $eol = false) - * @method Writer boldPurpleBgRed($text, $eol = false) - * @method Writer boldPurpleBgWhite($text, $eol = false) - * @method Writer boldPurpleBgYellow($text, $eol = false) - * @method Writer boldRed($text, $eol = false) - * @method Writer boldRedBgBlack($text, $eol = false) - * @method Writer boldRedBgBlue($text, $eol = false) - * @method Writer boldRedBgCyan($text, $eol = false) - * @method Writer boldRedBgGreen($text, $eol = false) - * @method Writer boldRedBgPurple($text, $eol = false) - * @method Writer boldRedBgWhite($text, $eol = false) - * @method Writer boldRedBgYellow($text, $eol = false) - * @method Writer boldWhite($text, $eol = false) - * @method Writer boldWhiteBgBlack($text, $eol = false) - * @method Writer boldWhiteBgBlue($text, $eol = false) - * @method Writer boldWhiteBgCyan($text, $eol = false) - * @method Writer boldWhiteBgGreen($text, $eol = false) - * @method Writer boldWhiteBgPurple($text, $eol = false) - * @method Writer boldWhiteBgRed($text, $eol = false) - * @method Writer boldWhiteBgYellow($text, $eol = false) - * @method Writer boldYellow($text, $eol = false) - * @method Writer boldYellowBgBlack($text, $eol = false) - * @method Writer boldYellowBgBlue($text, $eol = false) - * @method Writer boldYellowBgCyan($text, $eol = false) - * @method Writer boldYellowBgGreen($text, $eol = false) - * @method Writer boldYellowBgPurple($text, $eol = false) - * @method Writer boldYellowBgRed($text, $eol = false) - * @method Writer boldYellowBgWhite($text, $eol = false) - * @method Writer colors($text) - * @method Writer comment($text, $eol = false) - * @method Writer cyan($text, $eol = false) - * @method Writer cyanBgBlack($text, $eol = false) - * @method Writer cyanBgBlue($text, $eol = false) - * @method Writer cyanBgGreen($text, $eol = false) - * @method Writer cyanBgPurple($text, $eol = false) - * @method Writer cyanBgRed($text, $eol = false) - * @method Writer cyanBgWhite($text, $eol = false) - * @method Writer cyanBgYellow($text, $eol = false) - * @method Writer eol(int $n = 1) - * @method Writer error($text, $eol = false) - * @method Writer green($text, $eol = false) - * @method Writer greenBgBlack($text, $eol = false) - * @method Writer greenBgBlue($text, $eol = false) - * @method Writer greenBgCyan($text, $eol = false) - * @method Writer greenBgPurple($text, $eol = false) - * @method Writer greenBgRed($text, $eol = false) - * @method Writer greenBgWhite($text, $eol = false) - * @method Writer greenBgYellow($text, $eol = false) - * @method Writer info($text, $eol = false) - * @method Writer ok($text, $eol = false) - * @method Writer purple($text, $eol = false) - * @method Writer purpleBgBlack($text, $eol = false) - * @method Writer purpleBgBlue($text, $eol = false) - * @method Writer purpleBgCyan($text, $eol = false) - * @method Writer purpleBgGreen($text, $eol = false) - * @method Writer purpleBgRed($text, $eol = false) - * @method Writer purpleBgWhite($text, $eol = false) - * @method Writer purpleBgYellow($text, $eol = false) - * @method Writer red($text, $eol = false) - * @method Writer redBgBlack($text, $eol = false) - * @method Writer redBgBlue($text, $eol = false) - * @method Writer redBgCyan($text, $eol = false) - * @method Writer redBgGreen($text, $eol = false) - * @method Writer redBgPurple($text, $eol = false) - * @method Writer redBgWhite($text, $eol = false) - * @method Writer redBgYellow($text, $eol = false) - * @method Writer table(array $rows, array $styles = []) - * @method Writer warn($text, $eol = false) - * @method Writer white($text, $eol = false) - * @method Writer yellow($text, $eol = false) - * @method Writer yellowBgBlack($text, $eol = false) - * @method Writer yellowBgBlue($text, $eol = false) - * @method Writer yellowBgCyan($text, $eol = false) - * @method Writer yellowBgGreen($text, $eol = false) - * @method Writer yellowBgPurple($text, $eol = false) - * @method Writer yellowBgRed($text, $eol = false) - * @method Writer yellowBgWhite($text, $eol = false) */ class Interactor { @@ -241,7 +102,7 @@ public function confirm(string $text, string $default = 'y'): bool */ public function choice(string $text, array $choices, $default = null, bool $case = false): mixed { - $this->writer->yellow($text); + $this->writer->question($text); $this->listOptions($choices, $default, false); @@ -262,7 +123,7 @@ public function choice(string $text, array $choices, $default = null, bool $case */ public function choices(string $text, array $choices, $default = null, bool $case = false): mixed { - $this->writer->yellow($text); + $this->writer->question($text); $this->listOptions($choices, $default, true); @@ -300,7 +161,7 @@ public function prompt(string $text, $default = null, ?callable $fn = null, int $hidden = func_get_args()[4] ?? false; $readFn = ['read', 'readHidden'][(int) $hidden]; - $this->writer->yellow($text)->comment(null !== $default ? " [$default]: " : ': '); + $this->writer->question($text)->answer(null !== $default ? " [$default]: " : ': '); try { $input = $this->reader->{$readFn}($default, $fn); @@ -310,7 +171,7 @@ public function prompt(string $text, $default = null, ?callable $fn = null, int } if ($retry > 0 && $input === '') { - $this->writer->bgRed($error, true); + $this->writer->error($error, true); return $this->prompt($text, $default, $fn, $retry - 1, $hidden); } @@ -351,12 +212,12 @@ protected function listOptions(array $choices, $default = null, bool $multi = fa $maxLen = max(array_map('strlen', array_keys($choices))); foreach ($choices as $choice => $desc) { - $this->writer->eol()->cyan(str_pad(" [$choice]", $maxLen + 6))->comment($desc); + $this->writer->eol()->choice(str_pad(" [$choice]", $maxLen + 6))->answer($desc); } $label = $multi ? 'Choices (comma separated)' : 'Choice'; - $this->writer->eol()->yellow($label); + $this->writer->eol()->question($label); return $this->promptOptions(array_keys($choices), $default); } @@ -369,7 +230,7 @@ protected function promptOptions(array $choices, mixed $default): self $options = ''; foreach ($choices as $choice) { - $style = in_array($choice, (array) $default) ? 'boldCyan' : 'cyan'; + $style = in_array($choice, (array) $default) ? 'boldChoice' : 'choice'; $options .= "/<$style>$choice"; } diff --git a/src/Input/Command.php b/src/Input/Command.php index 5b999ee..49dbfb4 100644 --- a/src/Input/Command.php +++ b/src/Input/Command.php @@ -298,9 +298,9 @@ public function showHelp(): mixed $io = $this->io(); $helper = new OutputHelper($io->writer()); - $io->bold("Command {$this->_name}, version {$this->_version}", true)->eol(); - $io->comment($this->_desc, true)->eol(); - $io->bold('Usage: ')->yellow("{$this->_name} [OPTIONS...] [ARGUMENTS...]", true); + $io->help_header("Command {$this->_name}, version {$this->_version}", true)->eol(); + $io->help_summary($this->_desc, true)->eol(); + $io->help_text('Usage: ')->help_example("{$this->_name} [OPTIONS...] [ARGUMENTS...]", true); $helper ->showArgumentsHelp($this->allArguments()) @@ -318,7 +318,7 @@ public function showHelp(): mixed */ public function showVersion(): mixed { - $this->writer()->bold($this->_version, true); + $this->writer()->version($this->_version, true); return $this->emit('_exit', 0); } diff --git a/src/Output/Color.php b/src/Output/Color.php index d2be69a..d9187bb 100644 --- a/src/Output/Color.php +++ b/src/Output/Color.php @@ -53,47 +53,26 @@ class Color protected string $format = "\033[:mod:;:fg:;:bg:m:txt:\033[0m"; /** @var array Custom styles */ - protected static array $styles = []; - - /** - * Returns a line formatted as comment. - */ - public function comment(string $text, array $style = []): string - { - return $this->line($text, ['mod' => 2] + $style); - } - - /** - * Returns a line formatted as comment. - */ - public function error(string $text, array $style = []): string - { - return $this->line($text, ['fg' => static::RED] + $style); - } - - /** - * Returns a line formatted as ok msg. - */ - public function ok(string $text, array $style = []): string - { - return $this->line($text, ['fg' => static::GREEN] + $style); - } - - /** - * Returns a line formatted as warning. - */ - public function warn(string $text, array $style = []): string - { - return $this->line($text, ['fg' => static::YELLOW] + $style); - } - - /** - * Returns a line formatted as info. - */ - public function info(string $text, array $style = []): string - { - return $this->line($text, ['fg' => static::BLUE] + $style); - } + protected static array $styles = [ + 'answer' => ['fg' => 37, 'mod' => 2], + 'choice' => ['fg' => 36], + 'comment' => ['fg' => 37, 'mod' => 2], + 'error' => ['fg' => 31], + 'help_category' => ['fg' => 32, 'mod' => 1], + 'help_description' => ['fg' => 37, 'mod' => 2], + 'help_example' => ['fg' => 33], + 'help_footer' => ['fg' => 33], + 'help_group' => ['fg' => 33, 'mod' => 1], + 'help_header' => ['fg' => 37, 'mod' => 1], + 'help_item' => ['fg' => 37, 'mod' => 1], + 'help_summary' => ['fg' => 37, 'mod' => 2], + 'help_text' => ['fg' => 37, 'mod' => 1], + 'info' => ['fg' => 34], + 'ok' => ['fg' => 32], + 'question' => ['fg' => 33], + 'version' => ['fg' => 37, 'mod' => 1], + 'warn' => ['fg' => 33], + ]; /** * Returns a formatted/colored line. @@ -157,10 +136,6 @@ public static function style(string $name, array $style): void throw new InvalidArgumentException('Trying to set empty or invalid style'); } - if (isset(static::$styles[$name]) || method_exists(static::class, $name)) { - throw new InvalidArgumentException('Trying to define existing style'); - } - static::$styles[$name] = $style; } @@ -181,7 +156,7 @@ public function __call(string $name, array $arguments): string [$name, $text, $style] = $this->parseCall($name, $arguments); if (isset(static::$styles[$name])) { - return $this->line($text, $style + static::$styles[$name]); + return $this->line($text, static::$styles[$name] + $style); } if (defined($color = static::class . '::' . strtoupper($name))) { @@ -212,6 +187,10 @@ protected function parseCall(string $name, array $arguments): array } } + if (isset(static::$styles[strtolower($name)])) { + $name = strtolower($name); + } + if (!preg_match_all('/([b|B|f|F]g)?([A-Z][a-z]+)([^A-Z])?/', $name, $matches)) { return [lcfirst($name) ?: 'line', $text, $style]; } diff --git a/tests/Output/ColorTest.php b/tests/Output/ColorTest.php index 607beda..9cfe381 100644 --- a/tests/Output/ColorTest.php +++ b/tests/Output/ColorTest.php @@ -30,14 +30,11 @@ public function test_comment() public function test_custom_style() { - Color::style('alert', ['bg' => Color::YELLOW, 'fg' => Color::RED, 'bold' => 1]); + Color::style('alert', ['bg' => Color::YELLOW, 'fg' => Color::RED]); - $this->assertSame("\033[1;31;43malert\033[0m", (new Color)->alert('alert')); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Trying to define existing style'); - - Color::style('alert', ['bg' => Color::BLACK]); + $this->assertSame("\033[0;31;43malert\033[0m", (new Color)->alert('alert')); + $this->assertSame("\033[1;31;43malert\033[0m", (new Color)->boldAlert('alert')); + $this->assertSame("\033[1;31;43malert\033[0m", (new Color)->alertBold('alert')); } public function test_invalid_custom_style() From 887920a822341e674f3c05ea7e0e6b402aa56186 Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Mon, 25 Nov 2024 16:45:03 -0600 Subject: [PATCH 02/14] Put back Interactor Writer method definitions --- src/IO/Interactor.php | 136 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/src/IO/Interactor.php b/src/IO/Interactor.php index e711097..68fbbb6 100644 --- a/src/IO/Interactor.php +++ b/src/IO/Interactor.php @@ -37,6 +37,142 @@ * @license MIT * * @link https://github.com/adhocore/cli + * @method Writer bgBlack($text, $eol = false) + * @method Writer bgBlue($text, $eol = false) + * @method Writer bgCyan($text, $eol = false) + * @method Writer bgGreen($text, $eol = false) + * @method Writer bgPurple($text, $eol = false) + * @method Writer bgRed($text, $eol = false) + * @method Writer bgWhite($text, $eol = false) + * @method Writer bgYellow($text, $eol = false) + * @method Writer black($text, $eol = false) + * @method Writer blackBgBlue($text, $eol = false) + * @method Writer blackBgCyan($text, $eol = false) + * @method Writer blackBgGreen($text, $eol = false) + * @method Writer blackBgPurple($text, $eol = false) + * @method Writer blackBgRed($text, $eol = false) + * @method Writer blackBgWhite($text, $eol = false) + * @method Writer blackBgYellow($text, $eol = false) + * @method Writer blue($text, $eol = false) + * @method Writer blueBgBlack($text, $eol = false) + * @method Writer blueBgCyan($text, $eol = false) + * @method Writer blueBgGreen($text, $eol = false) + * @method Writer blueBgPurple($text, $eol = false) + * @method Writer blueBgRed($text, $eol = false) + * @method Writer blueBgWhite($text, $eol = false) + * @method Writer blueBgYellow($text, $eol = false) + * @method Writer bold($text, $eol = false) + * @method Writer boldBlack($text, $eol = false) + * @method Writer boldBlackBgBlue($text, $eol = false) + * @method Writer boldBlackBgCyan($text, $eol = false) + * @method Writer boldBlackBgGreen($text, $eol = false) + * @method Writer boldBlackBgPurple($text, $eol = false) + * @method Writer boldBlackBgRed($text, $eol = false) + * @method Writer boldBlackBgWhite($text, $eol = false) + * @method Writer boldBlackBgYellow($text, $eol = false) + * @method Writer boldBlue($text, $eol = false) + * @method Writer boldBlueBgBlack($text, $eol = false) + * @method Writer boldBlueBgCyan($text, $eol = false) + * @method Writer boldBlueBgGreen($text, $eol = false) + * @method Writer boldBlueBgPurple($text, $eol = false) + * @method Writer boldBlueBgRed($text, $eol = false) + * @method Writer boldBlueBgWhite($text, $eol = false) + * @method Writer boldBlueBgYellow($text, $eol = false) + * @method Writer boldCyan($text, $eol = false) + * @method Writer boldCyanBgBlack($text, $eol = false) + * @method Writer boldCyanBgBlue($text, $eol = false) + * @method Writer boldCyanBgGreen($text, $eol = false) + * @method Writer boldCyanBgPurple($text, $eol = false) + * @method Writer boldCyanBgRed($text, $eol = false) + * @method Writer boldCyanBgWhite($text, $eol = false) + * @method Writer boldCyanBgYellow($text, $eol = false) + * @method Writer boldGreen($text, $eol = false) + * @method Writer boldGreenBgBlack($text, $eol = false) + * @method Writer boldGreenBgBlue($text, $eol = false) + * @method Writer boldGreenBgCyan($text, $eol = false) + * @method Writer boldGreenBgPurple($text, $eol = false) + * @method Writer boldGreenBgRed($text, $eol = false) + * @method Writer boldGreenBgWhite($text, $eol = false) + * @method Writer boldGreenBgYellow($text, $eol = false) + * @method Writer boldPurple($text, $eol = false) + * @method Writer boldPurpleBgBlack($text, $eol = false) + * @method Writer boldPurpleBgBlue($text, $eol = false) + * @method Writer boldPurpleBgCyan($text, $eol = false) + * @method Writer boldPurpleBgGreen($text, $eol = false) + * @method Writer boldPurpleBgRed($text, $eol = false) + * @method Writer boldPurpleBgWhite($text, $eol = false) + * @method Writer boldPurpleBgYellow($text, $eol = false) + * @method Writer boldRed($text, $eol = false) + * @method Writer boldRedBgBlack($text, $eol = false) + * @method Writer boldRedBgBlue($text, $eol = false) + * @method Writer boldRedBgCyan($text, $eol = false) + * @method Writer boldRedBgGreen($text, $eol = false) + * @method Writer boldRedBgPurple($text, $eol = false) + * @method Writer boldRedBgWhite($text, $eol = false) + * @method Writer boldRedBgYellow($text, $eol = false) + * @method Writer boldWhite($text, $eol = false) + * @method Writer boldWhiteBgBlack($text, $eol = false) + * @method Writer boldWhiteBgBlue($text, $eol = false) + * @method Writer boldWhiteBgCyan($text, $eol = false) + * @method Writer boldWhiteBgGreen($text, $eol = false) + * @method Writer boldWhiteBgPurple($text, $eol = false) + * @method Writer boldWhiteBgRed($text, $eol = false) + * @method Writer boldWhiteBgYellow($text, $eol = false) + * @method Writer boldYellow($text, $eol = false) + * @method Writer boldYellowBgBlack($text, $eol = false) + * @method Writer boldYellowBgBlue($text, $eol = false) + * @method Writer boldYellowBgCyan($text, $eol = false) + * @method Writer boldYellowBgGreen($text, $eol = false) + * @method Writer boldYellowBgPurple($text, $eol = false) + * @method Writer boldYellowBgRed($text, $eol = false) + * @method Writer boldYellowBgWhite($text, $eol = false) + * @method Writer colors($text) + * @method Writer comment($text, $eol = false) + * @method Writer cyan($text, $eol = false) + * @method Writer cyanBgBlack($text, $eol = false) + * @method Writer cyanBgBlue($text, $eol = false) + * @method Writer cyanBgGreen($text, $eol = false) + * @method Writer cyanBgPurple($text, $eol = false) + * @method Writer cyanBgRed($text, $eol = false) + * @method Writer cyanBgWhite($text, $eol = false) + * @method Writer cyanBgYellow($text, $eol = false) + * @method Writer error($text, $eol = false) + * @method Writer green($text, $eol = false) + * @method Writer greenBgBlack($text, $eol = false) + * @method Writer greenBgBlue($text, $eol = false) + * @method Writer greenBgCyan($text, $eol = false) + * @method Writer greenBgPurple($text, $eol = false) + * @method Writer greenBgRed($text, $eol = false) + * @method Writer greenBgWhite($text, $eol = false) + * @method Writer greenBgYellow($text, $eol = false) + * @method Writer info($text, $eol = false) + * @method Writer ok($text, $eol = false) + * @method Writer purple($text, $eol = false) + * @method Writer purpleBgBlack($text, $eol = false) + * @method Writer purpleBgBlue($text, $eol = false) + * @method Writer purpleBgCyan($text, $eol = false) + * @method Writer purpleBgGreen($text, $eol = false) + * @method Writer purpleBgRed($text, $eol = false) + * @method Writer purpleBgWhite($text, $eol = false) + * @method Writer purpleBgYellow($text, $eol = false) + * @method Writer red($text, $eol = false) + * @method Writer redBgBlack($text, $eol = false) + * @method Writer redBgBlue($text, $eol = false) + * @method Writer redBgCyan($text, $eol = false) + * @method Writer redBgGreen($text, $eol = false) + * @method Writer redBgPurple($text, $eol = false) + * @method Writer redBgWhite($text, $eol = false) + * @method Writer redBgYellow($text, $eol = false) + * @method Writer warn($text, $eol = false) + * @method Writer white($text, $eol = false) + * @method Writer yellow($text, $eol = false) + * @method Writer yellowBgBlack($text, $eol = false) + * @method Writer yellowBgBlue($text, $eol = false) + * @method Writer yellowBgCyan($text, $eol = false) + * @method Writer yellowBgGreen($text, $eol = false) + * @method Writer yellowBgPurple($text, $eol = false) + * @method Writer yellowBgRed($text, $eol = false) + * @method Writer yellowBgWhite($text, $eol = false) */ class Interactor { From e817254dc4e829347495e35a0421785fa2f7a92c Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Mon, 25 Nov 2024 16:46:54 -0600 Subject: [PATCH 03/14] Put back eol and table method definitions for Interactor --- src/IO/Interactor.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/IO/Interactor.php b/src/IO/Interactor.php index 68fbbb6..5e2deab 100644 --- a/src/IO/Interactor.php +++ b/src/IO/Interactor.php @@ -136,6 +136,7 @@ * @method Writer cyanBgRed($text, $eol = false) * @method Writer cyanBgWhite($text, $eol = false) * @method Writer cyanBgYellow($text, $eol = false) + * @method Writer eol(int $n = 1) * @method Writer error($text, $eol = false) * @method Writer green($text, $eol = false) * @method Writer greenBgBlack($text, $eol = false) @@ -163,6 +164,7 @@ * @method Writer redBgPurple($text, $eol = false) * @method Writer redBgWhite($text, $eol = false) * @method Writer redBgYellow($text, $eol = false) + * @method Writer table(array $rows, array $styles = []) * @method Writer warn($text, $eol = false) * @method Writer white($text, $eol = false) * @method Writer yellow($text, $eol = false) From 316eed491b4d2ebe246bb49e232cfa0a27e7096d Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Mon, 25 Nov 2024 16:49:46 -0600 Subject: [PATCH 04/14] Put this blank line back? I'm not sure how that happened --- src/IO/Interactor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IO/Interactor.php b/src/IO/Interactor.php index 5e2deab..ec6e2a7 100644 --- a/src/IO/Interactor.php +++ b/src/IO/Interactor.php @@ -35,7 +35,7 @@ * * @author Jitendra Adhikari * @license MIT - * + * * @link https://github.com/adhocore/cli * @method Writer bgBlack($text, $eol = false) * @method Writer bgBlue($text, $eol = false) From 413475dd715ba4933a31720ff75b89d092fd48a0 Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Mon, 25 Nov 2024 16:52:04 -0600 Subject: [PATCH 05/14] Remove un-needed space --- src/IO/Interactor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IO/Interactor.php b/src/IO/Interactor.php index ec6e2a7..5e2deab 100644 --- a/src/IO/Interactor.php +++ b/src/IO/Interactor.php @@ -35,7 +35,7 @@ * * @author Jitendra Adhikari * @license MIT - * + * * @link https://github.com/adhocore/cli * @method Writer bgBlack($text, $eol = false) * @method Writer bgBlue($text, $eol = false) From 57d1bbfb8df04b12f40c63168884eff5e68c1090 Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Mon, 25 Nov 2024 17:00:50 -0600 Subject: [PATCH 06/14] Hopefully fix issue with test --- src/IO/Interactor.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/IO/Interactor.php b/src/IO/Interactor.php index 5e2deab..6fda3ce 100644 --- a/src/IO/Interactor.php +++ b/src/IO/Interactor.php @@ -37,6 +37,7 @@ * @license MIT * * @link https://github.com/adhocore/cli + * * @method Writer bgBlack($text, $eol = false) * @method Writer bgBlue($text, $eol = false) * @method Writer bgCyan($text, $eol = false) From cab2dd793b94c75e4440ca1dbf707a036b24c5a6 Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Mon, 25 Nov 2024 19:39:46 -0600 Subject: [PATCH 07/14] Put factory color functions back --- src/Output/Color.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/Output/Color.php b/src/Output/Color.php index d9187bb..cb1e57d 100644 --- a/src/Output/Color.php +++ b/src/Output/Color.php @@ -74,6 +74,46 @@ class Color 'warn' => ['fg' => 33], ]; + /** + * Returns a line formatted as comment. + */ + public function comment(string $text, array $style = []): string + { + return $this->line($text, static::$styles['comment'] + $style); + } + + /** + * Returns a line formatted as comment. + */ + public function error(string $text, array $style = []): string + { + return $this->line($text, static::$styles['error'] + $style); + } + + /** + * Returns a line formatted as ok msg. + */ + public function ok(string $text, array $style = []): string + { + return $this->line($text, static::$styles['ok'] + $style); + } + + /** + * Returns a line formatted as warning. + */ + public function warn(string $text, array $style = []): string + { + return $this->line($text, static::$styles['warn'] + $style); + } + + /** + * Returns a line formatted as info. + */ + public function info(string $text, array $style = []): string + { + return $this->line($text, static::$styles['info'] + $style); + } + /** * Returns a formatted/colored line. */ From 9124e36be1cddc1bc361a9f64204553ee13ab55f Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Mon, 25 Nov 2024 19:51:51 -0600 Subject: [PATCH 08/14] Prevent users from making factory functions invisible --- src/Output/Color.php | 4 ++++ tests/Output/ColorTest.php | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/Output/Color.php b/src/Output/Color.php index cb1e57d..8da4f3e 100644 --- a/src/Output/Color.php +++ b/src/Output/Color.php @@ -176,6 +176,10 @@ public static function style(string $name, array $style): void throw new InvalidArgumentException('Trying to set empty or invalid style'); } + if (method_exists(static::class, $name) && isset($style['bg']) && isset($style['fg']) && $style['bg'] === $style['fg']) { + throw new InvalidArgumentException('Built-in styles cannot be invisible (matching background and foreground)'); + } + static::$styles[$name] = $style; } diff --git a/tests/Output/ColorTest.php b/tests/Output/ColorTest.php index 9cfe381..321f45f 100644 --- a/tests/Output/ColorTest.php +++ b/tests/Output/ColorTest.php @@ -45,6 +45,14 @@ public function test_invalid_custom_style() Color::style('alert', ['invalid' => true]); } + public function test_invisible_built_in_style() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Built-in styles cannot be invisible (matching background and foreground)'); + + Color::style('error', ['bg' => Color::RED, 'fg' => Color::RED]); + } + public function test_colors() { $c = new Color; From 83cb5128509fb3abaf0628ced04ac43d3a3cd266 Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Mon, 25 Nov 2024 19:53:30 -0600 Subject: [PATCH 09/14] Shorten a couple lines --- src/Output/Color.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Output/Color.php b/src/Output/Color.php index 8da4f3e..f194563 100644 --- a/src/Output/Color.php +++ b/src/Output/Color.php @@ -176,8 +176,9 @@ public static function style(string $name, array $style): void throw new InvalidArgumentException('Trying to set empty or invalid style'); } - if (method_exists(static::class, $name) && isset($style['bg']) && isset($style['fg']) && $style['bg'] === $style['fg']) { - throw new InvalidArgumentException('Built-in styles cannot be invisible (matching background and foreground)'); + $invisible = (isset($style['bg']) && isset($style['fg']) && $style['bg'] === $style['fg']); + if ($invisible && method_exists(static::class, $name)) { + throw new InvalidArgumentException('Built-in styles cannot be invisible'); } static::$styles[$name] = $style; From e709cf689e3599400b95746b9936800f5baa55eb Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Mon, 25 Nov 2024 20:04:13 -0600 Subject: [PATCH 10/14] Update invisible_built_in_style expected exception message --- tests/Output/ColorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Output/ColorTest.php b/tests/Output/ColorTest.php index 321f45f..622ddf8 100644 --- a/tests/Output/ColorTest.php +++ b/tests/Output/ColorTest.php @@ -48,7 +48,7 @@ public function test_invalid_custom_style() public function test_invisible_built_in_style() { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Built-in styles cannot be invisible (matching background and foreground)'); + $this->expectExceptionMessage('Built-in styles cannot be invisible'); Color::style('error', ['bg' => Color::RED, 'fg' => Color::RED]); } From 8b8464216a58fb5d8b74539fe1718b99dcf8c54f Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Mon, 25 Nov 2024 22:09:48 -0600 Subject: [PATCH 11/14] Add new method definitions for Writer and Interactor classes --- src/IO/Interactor.php | 13 +++++++++++++ src/Output/Writer.php | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/IO/Interactor.php b/src/IO/Interactor.php index 6fda3ce..1881ea7 100644 --- a/src/IO/Interactor.php +++ b/src/IO/Interactor.php @@ -38,6 +38,7 @@ * * @link https://github.com/adhocore/cli * + * @method Writer answer($text, $eol = false) * @method Writer bgBlack($text, $eol = false) * @method Writer bgBlue($text, $eol = false) * @method Writer bgCyan($text, $eol = false) @@ -127,6 +128,7 @@ * @method Writer boldYellowBgPurple($text, $eol = false) * @method Writer boldYellowBgRed($text, $eol = false) * @method Writer boldYellowBgWhite($text, $eol = false) + * @method Writer choice($text, $eol = false) * @method Writer colors($text) * @method Writer comment($text, $eol = false) * @method Writer cyan($text, $eol = false) @@ -147,6 +149,15 @@ * @method Writer greenBgRed($text, $eol = false) * @method Writer greenBgWhite($text, $eol = false) * @method Writer greenBgYellow($text, $eol = false) + * @method Writer help_category($text, $eol = false) + * @method Writer help_description($text, $eol = false) + * @method Writer help_example($text, $eol = false) + * @method Writer help_footer($text, $eol = false) + * @method Writer help_group($text, $eol = false) + * @method Writer help_header($text, $eol = false) + * @method Writer help_item($text, $eol = false) + * @method Writer help_summary($text, $eol = false) + * @method Writer help_text($text, $eol = false) * @method Writer info($text, $eol = false) * @method Writer ok($text, $eol = false) * @method Writer purple($text, $eol = false) @@ -157,6 +168,7 @@ * @method Writer purpleBgRed($text, $eol = false) * @method Writer purpleBgWhite($text, $eol = false) * @method Writer purpleBgYellow($text, $eol = false) + * @method Writer question($text, $eol = false) * @method Writer red($text, $eol = false) * @method Writer redBgBlack($text, $eol = false) * @method Writer redBgBlue($text, $eol = false) @@ -166,6 +178,7 @@ * @method Writer redBgWhite($text, $eol = false) * @method Writer redBgYellow($text, $eol = false) * @method Writer table(array $rows, array $styles = []) + * @method Writer version($text, $eol = false) * @method Writer warn($text, $eol = false) * @method Writer white($text, $eol = false) * @method Writer yellow($text, $eol = false) diff --git a/src/Output/Writer.php b/src/Output/Writer.php index 626978f..38f3ebe 100644 --- a/src/Output/Writer.php +++ b/src/Output/Writer.php @@ -35,6 +35,7 @@ * * @link https://github.com/adhocore/cli * + * @method Writer answer($text, $eol = false) * @method Writer bgBlack($text, $eol = false) * @method Writer bgBlue($text, $eol = false) * @method Writer bgCyan($text, $eol = false) @@ -124,6 +125,7 @@ * @method Writer boldYellowBgPurple($text, $eol = false) * @method Writer boldYellowBgRed($text, $eol = false) * @method Writer boldYellowBgWhite($text, $eol = false) + * @method Writer choice($text, $eol = false) * @method Writer colors($text) * @method Writer comment($text, $eol = false) * @method Writer cyan($text, $eol = false) @@ -143,6 +145,15 @@ * @method Writer greenBgRed($text, $eol = false) * @method Writer greenBgWhite($text, $eol = false) * @method Writer greenBgYellow($text, $eol = false) + * @method Writer help_category($text, $eol = false) + * @method Writer help_description($text, $eol = false) + * @method Writer help_example($text, $eol = false) + * @method Writer help_footer($text, $eol = false) + * @method Writer help_group($text, $eol = false) + * @method Writer help_header($text, $eol = false) + * @method Writer help_item($text, $eol = false) + * @method Writer help_summary($text, $eol = false) + * @method Writer help_text($text, $eol = false) * @method Writer info($text, $eol = false) * @method Writer ok($text, $eol = false) * @method Writer purple($text, $eol = false) @@ -153,6 +164,7 @@ * @method Writer purpleBgRed($text, $eol = false) * @method Writer purpleBgWhite($text, $eol = false) * @method Writer purpleBgYellow($text, $eol = false) + * @method Writer question($text, $eol = false) * @method Writer red($text, $eol = false) * @method Writer redBgBlack($text, $eol = false) * @method Writer redBgBlue($text, $eol = false) @@ -161,6 +173,7 @@ * @method Writer redBgPurple($text, $eol = false) * @method Writer redBgWhite($text, $eol = false) * @method Writer redBgYellow($text, $eol = false) + * @method Writer version($text, $eol = false) * @method Writer warn($text, $eol = false) * @method Writer white($text, $eol = false) * @method Writer yellow($text, $eol = false) From 49d08fe3724a384fd968d52d04b2af1e01298b1a Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Mon, 25 Nov 2024 23:20:28 -0600 Subject: [PATCH 12/14] Make logo a built-in style --- README.md | 1 + src/Application.php | 2 +- src/IO/Interactor.php | 1 + src/Output/Color.php | 1 + src/Output/Writer.php | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 26afffc..761c862 100644 --- a/README.md +++ b/README.md @@ -468,6 +468,7 @@ There are a number of pre-defined built-in styles that allows you granular custo - help_summary - help_text - info + - logo - ok - question - version diff --git a/src/Application.php b/src/Application.php index 3b41793..eb5d5e1 100644 --- a/src/Application.php +++ b/src/Application.php @@ -353,7 +353,7 @@ public function showHelp(): mixed $footer = 'Run ` --help` for specific help'; if ($this->logo) { - $writer->write($this->logo, true); + $writer->logo($this->logo, true); } $this->outputHelper()->showCommandsHelp($this->commands(), $header, $footer); diff --git a/src/IO/Interactor.php b/src/IO/Interactor.php index 1881ea7..a36747b 100644 --- a/src/IO/Interactor.php +++ b/src/IO/Interactor.php @@ -159,6 +159,7 @@ * @method Writer help_summary($text, $eol = false) * @method Writer help_text($text, $eol = false) * @method Writer info($text, $eol = false) + * @method Writer logo($text, $eol = false) * @method Writer ok($text, $eol = false) * @method Writer purple($text, $eol = false) * @method Writer purpleBgBlack($text, $eol = false) diff --git a/src/Output/Color.php b/src/Output/Color.php index f194563..c2fceb2 100644 --- a/src/Output/Color.php +++ b/src/Output/Color.php @@ -68,6 +68,7 @@ class Color 'help_summary' => ['fg' => 37, 'mod' => 2], 'help_text' => ['fg' => 37, 'mod' => 1], 'info' => ['fg' => 34], + 'logo' => ['fg' => 37], 'ok' => ['fg' => 32], 'question' => ['fg' => 33], 'version' => ['fg' => 37, 'mod' => 1], diff --git a/src/Output/Writer.php b/src/Output/Writer.php index 38f3ebe..9528c12 100644 --- a/src/Output/Writer.php +++ b/src/Output/Writer.php @@ -155,6 +155,7 @@ * @method Writer help_summary($text, $eol = false) * @method Writer help_text($text, $eol = false) * @method Writer info($text, $eol = false) + * @method Writer logo($text, $eol = false) * @method Writer ok($text, $eol = false) * @method Writer purple($text, $eol = false) * @method Writer purpleBgBlack($text, $eol = false) From 531851d621b5e5811e9d71475689dd63f735f13f Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Mon, 25 Nov 2024 23:57:54 -0600 Subject: [PATCH 13/14] Make help_description into help_description_even/odd and make help_item into help_item_even/odd --- README.md | 6 ++++-- src/Helper/OutputHelper.php | 11 +++++++--- src/IO/Interactor.php | 6 ++++-- src/Output/Color.php | 40 +++++++++++++++++++------------------ src/Output/Writer.php | 6 ++++-- 5 files changed, 41 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 761c862..a59086c 100644 --- a/README.md +++ b/README.md @@ -459,12 +459,14 @@ There are a number of pre-defined built-in styles that allows you granular custo - comment - error - help_category - - help_description + - help_description_even + - help_description_odd - help_example - help_footer - help_group - help_header - - help_item + - help_item_even + - help_item_odd - help_summary - help_text - info diff --git a/src/Helper/OutputHelper.php b/src/Helper/OutputHelper.php index df518c8..21e9583 100644 --- a/src/Helper/OutputHelper.php +++ b/src/Helper/OutputHelper.php @@ -197,7 +197,7 @@ protected function showHelp(string $for, array $items, string $header = '', stri $group = $lastGroup = null; $withDefault = $for === 'Options' || $for === 'Arguments'; - foreach ($this->sortItems($items, $padLen, $for) as $item) { + foreach (array_values($this->sortItems($items, $padLen, $for)) as $idx => $item) { $name = $this->getName($item); if ($for === 'Commands' && $lastGroup !== $group = $item->group()) { $this->writer->help_group($group ?: '*', true); @@ -205,8 +205,13 @@ protected function showHelp(string $for, array $items, string $header = '', stri } $desc = str_replace(["\r\n", "\n"], str_pad("\n", $padLen + $space + 3), $item->desc($withDefault)); - $this->writer->help_item(' ' . str_pad($name, $padLen + $space)); - $this->writer->help_description($desc, true); + if ($idx % 2 == 0) { + $this->writer->help_item_even(' ' . str_pad($name, $padLen + $space)); + $this->writer->help_description_even($desc, true); + } else { + $this->writer->help_item_odd(' ' . str_pad($name, $padLen + $space)); + $this->writer->help_description_odd($desc, true); + } } if ($footer) { diff --git a/src/IO/Interactor.php b/src/IO/Interactor.php index a36747b..9112383 100644 --- a/src/IO/Interactor.php +++ b/src/IO/Interactor.php @@ -150,12 +150,14 @@ * @method Writer greenBgWhite($text, $eol = false) * @method Writer greenBgYellow($text, $eol = false) * @method Writer help_category($text, $eol = false) - * @method Writer help_description($text, $eol = false) + * @method Writer help_description_even($text, $eol = false) + * @method Writer help_description_odd($text, $eol = false) * @method Writer help_example($text, $eol = false) * @method Writer help_footer($text, $eol = false) * @method Writer help_group($text, $eol = false) * @method Writer help_header($text, $eol = false) - * @method Writer help_item($text, $eol = false) + * @method Writer help_item_even($text, $eol = false) + * @method Writer help_item_odd($text, $eol = false) * @method Writer help_summary($text, $eol = false) * @method Writer help_text($text, $eol = false) * @method Writer info($text, $eol = false) diff --git a/src/Output/Color.php b/src/Output/Color.php index c2fceb2..e53ee69 100644 --- a/src/Output/Color.php +++ b/src/Output/Color.php @@ -54,25 +54,27 @@ class Color /** @var array Custom styles */ protected static array $styles = [ - 'answer' => ['fg' => 37, 'mod' => 2], - 'choice' => ['fg' => 36], - 'comment' => ['fg' => 37, 'mod' => 2], - 'error' => ['fg' => 31], - 'help_category' => ['fg' => 32, 'mod' => 1], - 'help_description' => ['fg' => 37, 'mod' => 2], - 'help_example' => ['fg' => 33], - 'help_footer' => ['fg' => 33], - 'help_group' => ['fg' => 33, 'mod' => 1], - 'help_header' => ['fg' => 37, 'mod' => 1], - 'help_item' => ['fg' => 37, 'mod' => 1], - 'help_summary' => ['fg' => 37, 'mod' => 2], - 'help_text' => ['fg' => 37, 'mod' => 1], - 'info' => ['fg' => 34], - 'logo' => ['fg' => 37], - 'ok' => ['fg' => 32], - 'question' => ['fg' => 33], - 'version' => ['fg' => 37, 'mod' => 1], - 'warn' => ['fg' => 33], + 'answer' => ['fg' => 37, 'mod' => 2], + 'choice' => ['fg' => 36], + 'comment' => ['fg' => 37, 'mod' => 2], + 'error' => ['fg' => 31], + 'help_category' => ['fg' => 32, 'mod' => 1], + 'help_description_even' => ['fg' => 37, 'mod' => 2], + 'help_description_odd' => ['fg' => 37, 'mod' => 2], + 'help_example' => ['fg' => 33], + 'help_footer' => ['fg' => 33], + 'help_group' => ['fg' => 33, 'mod' => 1], + 'help_header' => ['fg' => 37, 'mod' => 1], + 'help_item_even' => ['fg' => 37, 'mod' => 1], + 'help_item_odd' => ['fg' => 37, 'mod' => 1], + 'help_summary' => ['fg' => 37, 'mod' => 2], + 'help_text' => ['fg' => 37, 'mod' => 1], + 'info' => ['fg' => 34], + 'logo' => ['fg' => 37], + 'ok' => ['fg' => 32], + 'question' => ['fg' => 33], + 'version' => ['fg' => 37, 'mod' => 1], + 'warn' => ['fg' => 33], ]; /** diff --git a/src/Output/Writer.php b/src/Output/Writer.php index 9528c12..ca1cff9 100644 --- a/src/Output/Writer.php +++ b/src/Output/Writer.php @@ -146,12 +146,14 @@ * @method Writer greenBgWhite($text, $eol = false) * @method Writer greenBgYellow($text, $eol = false) * @method Writer help_category($text, $eol = false) - * @method Writer help_description($text, $eol = false) + * @method Writer help_description_even($text, $eol = false) + * @method Writer help_description_odd($text, $eol = false) * @method Writer help_example($text, $eol = false) * @method Writer help_footer($text, $eol = false) * @method Writer help_group($text, $eol = false) * @method Writer help_header($text, $eol = false) - * @method Writer help_item($text, $eol = false) + * @method Writer help_item_even($text, $eol = false) + * @method Writer help_item_odd($text, $eol = false) * @method Writer help_summary($text, $eol = false) * @method Writer help_text($text, $eol = false) * @method Writer info($text, $eol = false) From b22ba75b47e8b14fc6ce12d5fa1c173774522527 Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Tue, 26 Nov 2024 00:04:20 -0600 Subject: [PATCH 14/14] Fix indentation --- src/Helper/OutputHelper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Helper/OutputHelper.php b/src/Helper/OutputHelper.php index 21e9583..5f54200 100644 --- a/src/Helper/OutputHelper.php +++ b/src/Helper/OutputHelper.php @@ -206,11 +206,11 @@ protected function showHelp(string $for, array $items, string $header = '', stri $desc = str_replace(["\r\n", "\n"], str_pad("\n", $padLen + $space + 3), $item->desc($withDefault)); if ($idx % 2 == 0) { - $this->writer->help_item_even(' ' . str_pad($name, $padLen + $space)); - $this->writer->help_description_even($desc, true); + $this->writer->help_item_even(' ' . str_pad($name, $padLen + $space)); + $this->writer->help_description_even($desc, true); } else { - $this->writer->help_item_odd(' ' . str_pad($name, $padLen + $space)); - $this->writer->help_description_odd($desc, true); + $this->writer->help_item_odd(' ' . str_pad($name, $padLen + $space)); + $this->writer->help_description_odd($desc, true); } }