wilensky / cli-colorizer
A lightweight tool for easy PHP7 CLI output coloring.
v1.5.0
2017-01-03 17:18 UTC
Requires
- php: >=7.0.1
This package is not auto-updated.
Last update: 2025-04-12 22:26:28 UTC
README
Lightweight PHP7 CLI output colorizer
- Available via
composer require
wilensky/cli-colorizer
- PHP7 compliant
- PSR2 compliant
- Lightweight
- Documented
- Compatible with native linux
tail
andcat
commands
Usage
For ease of use CliColorizer
can/should be aliased with help of use
statement.
<?php use Wilensky/CliColorizer as WCC;
Changing text color
Regular method
echo WCC::fgYellow('YoHoHo').PHP_EOL; // YoHoHo will be yellowed on default background
All available foregroung color
@method
s are listed under the class docblock withfg*
prefix.
Advanced method
$answer = true; $isOk = $answer === true; echo WCC::fg( $isOk ? 'Yes' : 'No', $isOk ? 'green' : 'red' ).PHP_EOL;
Changing background color
Regular method
echo WCC::bgCyan('YoHoHo').PHP_EOL; // YoHoHo will be displayed on cyan background with default foreground color
All availabe backgorund color
@method
s are listed under the class docblock withbg*
prefix.
Advanced method
$error = true; $hasError = $error === true; echo WCC::bg( $hasError ? 'Failed' : 'Ready', $hasError ? 'red' : 'black' ).PHP_EOL;
Mixing fore and background colors
echo WCC::bgGreen(WCC::fgYellow('YoHoHo')).PHP_EOL; // YoHoHo will be displayed as yellow text on green background echo WCC::fgYellow(WCC::bgGreen('YoHoHo')).PHP_EOL; // Produces same output as invocation priority doesn't matter for display
Making text bold
echo WCC::bold('YoHoHo').PHP_EOL; // YoHoHo will be displayed bold with default fore/background colors
Making bold colors
echo WCC::bold(WCC::fgYellow('YoHoHo')).PHP_EOL; // YoHoHo will be bold yellow echo WCC::fgYellow(WCC::bold('YoHoHo')).PHP_EOL; // Produces same output
echo WCC::bold(WCC::bgCyan('YoHoHo')).PHP_EOL; // YoHoHo will be bold with default color on cyan background
echo WCC::bold(WCC::fgYellow(WCC::bgCyan('YoHoHo'))).PHP_EOL; // YoHoHo will be bold yellow on cyan background