-
-
Notifications
You must be signed in to change notification settings - Fork 36
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 support for outputting 256 colors and also add documentation about default command functionality #110
Conversation
If we wanted to get real fancy, we could add two methods that add the prefixes for us: \Ahc\Cli\Output\Color::style('mystyle', [
'fg' => \Ahc\Cli\Output\Color::fg256(57),
'bg' => \Ahc\Cli\Output\Color::bg256(82)
]); Just an idea, thoughts? |
Orrrrr, we could have it be it's own style property that can fallback for terminals that don't support 256: \Ahc\Cli\Output\Color::style('mystyle', [
'bg' => Ahc\Cli\Output\Color::CYAN, // used if no 256-support
'fg' => Ahc\Cli\Output\Color::WHITE, // used if no 256-support
'bg_256' => 82,
'fg_256' => 57
]); Just another idea. But I'm totally fine with just how the PR is now. |
hello, thank you for this idea/ feature/ pull. and yes we can add the color consts Color::RED6, Color::GREEN6 etc for common/major colors and static func |
cc @dimtrovich more new exciting pulls might need your look 😁 😉 |
I figured the first suggestion was slightly better than the second as it only adds two methods rather than changing the flow of things (text, style, mod, etc). So I've implemented this the fg256 and bg256 methods like so: \Ahc\Cli\Output\Color::style('mystyle', [
'fg' => \Ahc\Cli\Output\Color::fg256(57),
'bg' => \Ahc\Cli\Output\Color::bg256(82)
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great, thanks
is it possible to share a screenshot of 256 colors using this code, as well as from the other pulls? :D |
I have a branch on my fork where I have been merging all of my PRs together for testing (https://github.com/kodie/adhocore-php-cli/tree/kodie/development). Given this code: $app = new Ahc\Cli\Application('My App', $version);
$writer = new Ahc\Cli\Output\Writer();
\Ahc\Cli\Output\Color::style('indigo', array('fg' => \Ahc\Cli\Output\Color::fg256(57)));
\Ahc\Cli\Output\Color::style('spring', array('fg' => \Ahc\Cli\Output\Color::RED, 'bg' => \Ahc\Cli\Output\Color::bg256(49)));
$help = "<indigo>Hello</end>\n<spring>World</end>";
$app->help($writer->colorizer()->colors($help));
$app->handle($_SERVER['argv']); and running ./bin/my-app --help |
thanks, looks good, lets see if @dimtrovich would like to have a look as well |
For the moment I'm still at home. As soon as I get to the office, I'll take a closer look. |
Here's a better screenshot of the additional colors as well as the customizable help styles from #111 |
Just playing around with colors. Added even and odd capabilities to #111 // Custom colors
\Ahc\Cli\Output\Color::style('indigo', array('fg' => \Ahc\Cli\Output\Color::fg256(57)));
\Ahc\Cli\Output\Color::style('orange', array('fg' => \Ahc\Cli\Output\Color::fg256(214)));
\Ahc\Cli\Output\Color::style('spring', array('fg' => \Ahc\Cli\Output\Color::fg256(49)));
\Ahc\Cli\Output\Color::style('question', array('fg' => \Ahc\Cli\Output\Color::fg256(57)));
\Ahc\Cli\Output\Color::style('choice', array('fg' => \Ahc\Cli\Output\Color::fg256(49)));
\Ahc\Cli\Output\Color::style('logo', array('fg' => \Ahc\Cli\Output\Color::fg256(172)));
\Ahc\Cli\Output\Color::style('choice', array('fg' => \Ahc\Cli\Output\Color::fg256(49)));
\Ahc\Cli\Output\Color::style('help_category', array('fg' => \Ahc\Cli\Output\Color::fg256(49)));
\Ahc\Cli\Output\Color::style('help_example', array('fg' => \Ahc\Cli\Output\Color::fg256(213)));
\Ahc\Cli\Output\Color::style('help_summary', array('fg' => \Ahc\Cli\Output\Color::fg256(190)));
\Ahc\Cli\Output\Color::style('help_description_even', array('fg' => \Ahc\Cli\Output\Color::fg256(250)));
\Ahc\Cli\Output\Color::style('help_description_odd', array('fg' => \Ahc\Cli\Output\Color::fg256(230)));
\Ahc\Cli\Output\Color::style('help_item_even', array('fg' => \Ahc\Cli\Output\Color::fg256(230)));
\Ahc\Cli\Output\Color::style('help_item_odd', array('fg' => \Ahc\Cli\Output\Color::fg256(250)));
\Ahc\Cli\Output\Color::style('help_footer', array('fg' => \Ahc\Cli\Output\Color::fg256(39)));
\Ahc\Cli\Output\Color::style('help_summary', array('fg' => \Ahc\Cli\Output\Color::fg256(58)));
\Ahc\Cli\Output\Color::style('help_text', array('fg' => \Ahc\Cli\Output\Color::fg256(174))); |
it's cool, thanks. |
…em into help_item_even/odd
…p-cli into kodie/allow-256-colors
@kodie it still shows merge conflict:
besides that i think good to go |
Just wanted to tag this resource in case anyone is looking for a naming system for custom colors: https://gist.github.com/kodie/b63881ccf4368e9e00c0c3277779524a I don't think it's worth making naming look up for 256 colors worth a feature but having a list is a sort of nice resource. |
As the title says, this PR allows us to use 256 colors in our custom styles like so:
and all it took was removing typecasting on the
fg
style value (allowing us to pass strings) and doing a check on thebg
style value to see if it's being passed an interval or not, if it is (default behavior) then add 10 to it and use it just the same before, but if it's not an interval (like a string) then just use that value, allowing us to use 256 colors.This opens up the world of setting custom colors:
I added a small example of this to the readme and also added documentation about the default command functionality as that seemed to be missing.