PHP code example of travail / term-ansicolor

1. Go to this page and download the library: Download travail/term-ansicolor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

travail / term-ansicolor example snippets


use \Term\ANSIColor;

ing
echo ANSIColor::colored("Yellow text\n", 'yellow');
echo ANSIColor::colored("Normal text on magenta\n", null, 'magenta');
echo ANSIColor::colored("Underscored text\n", null, null, 'underscore');
echo ANSIColor::colored("Red on cyan\n", 'red', 'cyan');
echo ANSIColor::colored("Blinking blue text on light gray\n", 'blue', 'light_gray', 'blink');

// Get a colored string by an alias
ANSIColor::setAlias('debug', 'red', 'light_gray');
echo ANSIColor::colored("[DEBUG] Debug message in red on light_gray\n" , 'debug');
ANSIColor::setAlias('error', 'red', 'black');
echo ANSIColor::colored("[ERROR] Error message in red on black\n" , 'error');

array(
    'black'       => '0;30',
    'dark_gray'   => '1;30',
    'blue'        => '0;34',
    'light_blue'  => '1;34',
    'green'       => '0;32',
    'light_green' => '1;32',
    'cyan'        => '0;36',
    'light_cyan'  => '1;36',
    'red'         => '0;31',
    'light_red'   => '1;31',
    'purple'      => '0;35',
    'light_purple'=> '1;35',
    'brown'       => '0;33',
    'yellow'      => '1;33',
    'light_gray'  => '0;37',
    'white'       => '1;37',
);

array(
    'black'      => '40',
    'red'        => '41',
    'green'      => '42',
    'yellow'     => '43',
    'blue'       => '44',
    'magenta'    => '45',
    'cyan'       => '46',
    'light_gray' => '47',
);