A simple functional PHP library for formatting string output π
$ composer require troublete/crayon
The purpose of the library is to simplify the usage of formatting of strings on the PHP CLI.
The usage should be strictly a functional one, to write the least code with the biggest impact.
Simple use the function Crayon\text
which returns a Crayon\Font
instance which handles the formatting
and return as string. Formatting calls may be chained.
β οΈ Be aware that there is a formatting order: underline > italic > bold > color. Last color set will be used and that italic weighs more than bold formatting. So if both options are set the prior one will be used.
<?php
require_once 'path/to/vendor/autoload.php';
use function Crayon\{text as crayon, error, success};
echo crayon('text')->green(); // returns green text
echo crayon('text')->green()->bold(); // returns bold green text
echo crayon('text')->green()->underline()->bold(); // returns underlined bold green text
echo crayon('text')->green()->underline()->bold()->background(); // returns underlined bold green backgrounded text
echo success('text'); // returns green bold text with checkmark at the end
echo error('text'); // returns red bold text with x at the end
GPL-2.0 Β© Willi EΓer