Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logo support for commands #112

Closed
wants to merge 53 commits into from
Closed
Changes from 5 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2c6f07d
Add logo support for commands
kodie Nov 25, 2024
6a7f7d6
Update readme copy for command logo example
kodie Nov 26, 2024
b50f502
Make logo property logo for command to avoid any conflicts
kodie Nov 26, 2024
04cfefd
Fix logo checking and writing
kodie Nov 26, 2024
3843419
Use the app's logo in a command's help screen if its the default command
kodie Nov 26, 2024
79e459a
Make all written text built-in styles so that their styles can be cus…
kodie Nov 25, 2024
ef091d0
Put back Interactor Writer method definitions
kodie Nov 25, 2024
7f7466f
Put back eol and table method definitions for Interactor
kodie Nov 25, 2024
a4ebc07
Put this blank line back? I'm not sure how that happened
kodie Nov 25, 2024
229d58c
Remove un-needed space
kodie Nov 25, 2024
5f7fb39
Hopefully fix issue with test
kodie Nov 25, 2024
4463acb
Put factory color functions back
kodie Nov 26, 2024
1365912
Prevent users from making factory functions invisible
kodie Nov 26, 2024
44c1bc1
Shorten a couple lines
kodie Nov 26, 2024
0453b1b
Update invisible_built_in_style expected exception message
kodie Nov 26, 2024
5c2681e
Add new method definitions for Writer and Interactor classes
kodie Nov 26, 2024
929aa8c
Make logo a built-in style
kodie Nov 26, 2024
5017764
Make help_description into help_description_even/odd and make help_it…
kodie Nov 26, 2024
47ef57b
Fix indentation
kodie Nov 26, 2024
07a58fa
Add support for custom help screens
kodie Nov 26, 2024
7737fe6
Fix identation
kodie Nov 26, 2024
1f0832a
Hopefully fix issues with tests
kodie Nov 26, 2024
be41352
Tests don't like variables starting with underscores in the application
kodie Nov 26, 2024
3321966
Add example to readme showing how you can get colors working in a cus…
kodie Nov 26, 2024
4b3084e
Just pass the colorizer as the help parameter in the custom help read…
kodie Nov 26, 2024
e46c51b
Rename custom_help to help
kodie Nov 26, 2024
dc2cbe8
Add support for 256 colors
kodie Nov 25, 2024
4cd771f
Add documentation about default command functionality
kodie Nov 25, 2024
0d5deae
Use 256 colors in test_custom_style test
kodie Nov 25, 2024
0a5c8ad
Add Color::bg256 and Color::fg256
kodie Nov 26, 2024
0bceee7
Add periods to bg256 and fg256 descriptions
kodie Nov 26, 2024
8bd27e1
Add mising A to fg256 example in readme
kodie Nov 26, 2024
cbb5476
Add return types for bg256 and fg256 functions
kodie Nov 26, 2024
50bfd67
Make bg256 and fg256 functions static
kodie Nov 26, 2024
a5358f4
Use PHP comments in Default command example in readme instead of Bash…
kodie Nov 26, 2024
0d62301
Make all written text built-in styles so that their styles can be cus…
kodie Nov 25, 2024
b53faa7
Put back eol and table method definitions for Interactor
kodie Nov 25, 2024
00a7636
Put this blank line back? I'm not sure how that happened
kodie Nov 25, 2024
765b71d
Remove un-needed space
kodie Nov 25, 2024
00cefbd
Hopefully fix issue with test
kodie Nov 25, 2024
df68b6c
Prevent users from making factory functions invisible
kodie Nov 26, 2024
641f690
Shorten a couple lines
kodie Nov 26, 2024
d02e462
Add new method definitions for Writer and Interactor classes
kodie Nov 26, 2024
559a457
Make help_description into help_description_even/odd and make help_it…
kodie Nov 26, 2024
e051346
Add support for custom help screens
kodie Nov 26, 2024
f6fe5bc
Fix identation
kodie Nov 26, 2024
7988eb7
Add example to readme showing how you can get colors working in a cus…
kodie Nov 26, 2024
a64b36c
Add logo support for commands
kodie Nov 25, 2024
7452e46
Make logo property logo for command to avoid any conflicts
kodie Nov 26, 2024
602d975
Fix logo checking and writing
kodie Nov 26, 2024
757349f
Remove duplicate test_custom_help that happened during rebase somehow
kodie Nov 26, 2024
cbec8dc
Return this from command logo function - got changed during rebase so…
kodie Nov 26, 2024
32bcfdc
Remove merge conflict indicators from Interactor that happened during…
kodie Nov 26, 2024
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -181,7 +181,8 @@ class InitCommand extends Ahc\Cli\Input\Command
'<bold> init</end> <comment>--apple applet --ball ballon <arggg></end> ## details 1<eol/>' .
// $0 will be interpolated to actual command name
'<bold> $0</end> <comment>-a applet -b ballon <arggg> [arg2]</end> ## details 2<eol/>'
);
)
->logo('Ascii art logo of your command');
}

// This method is auto called before `self::execute()` and receives `Interactor $io` instance
4 changes: 2 additions & 2 deletions src/Application.php
Original file line number Diff line number Diff line change
@@ -352,8 +352,8 @@ public function showHelp(): mixed
$header = "{$this->name}, version {$this->version}";
$footer = 'Run `<command> --help` for specific help';

if ($this->logo) {
$writer->write($this->logo, true);
if ($logo = $this->logo()) {
$writer->write($logo, true);
}

$this->outputHelper()->showCommandsHelp($this->commands(), $header, $footer);
25 changes: 25 additions & 0 deletions src/Input/Command.php
Original file line number Diff line number Diff line change
@@ -52,6 +52,8 @@ class Command extends Parser implements Groupable

protected ?string $_alias = null;

protected string $_logo = '';

private array $_events = [];

private bool $_argVariadic = false;
@@ -152,6 +154,24 @@ public function bind(?App $app = null): self
return $this;
}

/**
* Sets or gets the ASCII art logo.
*
* @param string|null $logo
*
* @return string|self
*/
public function logo(?string $logo = null)
{
if (func_num_args() === 0) {
return $this->_logo;
}

$this->_logo = $logo;

return $this;
}

/**
* Registers argument definitions (all at once). Only last one can be variadic.
*/
@@ -297,6 +317,11 @@ public function showHelp(): mixed
{
$io = $this->io();
$helper = new OutputHelper($io->writer());
$app = $this->app();

if (($logo = $this->logo()) || ($app && ($logo = $app->logo()) && $app->getDefaultCommand() === $this->_name)) {
$io->write($logo, true);
}

$io->bold("Command {$this->_name}, version {$this->_version}", true)->eol();
$io->comment($this->_desc, true)->eol();
15 changes: 15 additions & 0 deletions tests/ApplicationTest.php
Original file line number Diff line number Diff line change
@@ -226,6 +226,21 @@ public function test_logo()
$this->assertSame($logo, $a->logo());
}

public function test_logo_command()
{
$a = $this->newApp('test', '0.0.2');
$c = $a->command('cmd');

$this->assertSame($c, $c->logo($logo = '
| |_ ___ ___| |_
| __/ _ \/ __| __|
| || __/\__ \ |_
\__\___||___/\__|
'));

$this->assertSame($logo, $c->logo());
}

public function test_add()
{
$a = $this->newApp('test', '0.0.1-test');