Colors and styles for PHP CLI output.
composer require romanato/php-coloringo-cli
// Create new instance
$console = new Romanato\ColoringoCLI\Coloringo;
// Set output
print $console->out('100% Awesomeness');
// Set inline output (without new line)
print $console->inline('100% Awesomeness');
// Set color
print $console->out('Text of this message is red.', 'red');
// Set other attributes
print $console->out('A lot of attributes!', [
'color' => 'magenta',
'background' => 'blue',
'style' => 'underline'
]);
// Merge more outputs inside one print
print(
$console->out('This is first line', 'red')
.$console->inline('This is second line.', [
'color' => 'yellow',
'style' => 'bold'
])
.$console->out(' Still second line but gonna make another line.', 'green')
);
Available attributes are: color
, background
, style
Available colors (and backgrounds):
- default
- white
- black
- red
- green
- yellow
- blue
- magenta
- cyan
- light_grey
- dark_grey
- light_red
- light_green
- light_yellow
- light_blue
- light_magenta
- light_cyan
Available styles:
- bold
- dim
- underline
- blink
- reverse
- hidden
This method makes an output into CLI with a new line at the end.
print $console->out($output, $attributes);
This method makes an output into CLI without a new line at the end.
print $console->inline($output, $attributes);
This method creates a new line.
print $console->newLine();
Checks if the php script is running via CLI.
print $console->isSupported();
Properties of the class are basically the configuration of all colors and styles. You can see all available attributes and their values.
Shows all supported (foreground) colors.
print $console->color;
Shows all supported (background) colors.
print $console->background;
Shows all supported styles.
print $console->style;
Shows all supported attributes.
print $console->attributes;
You can set your own colors and styles very easily by editing: Coloringo.php
class.
class Coloringo
{
public $color = [
'...' => '..',
'customColor' => 'code'
];
public $background = [
'...' => '..',
'customBackground' => 'code'
];
public $styles = [
'...' => '..',
'customStyle' => 'code'
];
}