Created
May 11, 2016 07:02
-
-
Save oo-ilin/1c2c6f4361f516a822dd5489b9d0c2f6 to your computer and use it in GitHub Desktop.
Generating Command Line Colors with PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function colorize($text, $status) { | |
| $out = ""; | |
| switch($status) { | |
| case "SUCCESS": | |
| $out = "[42m"; //Green background | |
| break; | |
| case "FAILURE": | |
| $out = "[41m"; //Red background | |
| break; | |
| case "WARNING": | |
| $out = "[43m"; //Yellow background | |
| break; | |
| case "NOTE": | |
| $out = "[44m"; //Blue background | |
| break; | |
| default: | |
| throw new Exception("Invalid status: " . $status); | |
| } | |
| return chr(27) . "$out" . "$text" . chr(27) . "[0m"; | |
| } | |
| echo colorize("Your command was successfully executed...", "SUCCESS"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment