PHP code example of win0err / php-terminal-tools

1. Go to this page and download the library: Download win0err/php-terminal-tools 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/ */

    

win0err / php-terminal-tools example snippets



use win0err\TerminalTools\TextFormatter;
use win0err\TerminalTools\Colors\{Classic, Extended, TrueColor};

$textFormatter = new TextFormatter( "Съешь ещё этих мягких французских булок, да выпей чаю" );
echo $textFormatter;
// или сокращённая запись: 
echo TextFormatter::format( 
	"В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!" /* $text */, // Обязательно
	new Extended(198) /* $textColor = null */, 
	new Extended(200) /* $backgroundColor = null*/, 
	TextFormatter::BOLD /* ...$styles */ 
	);


$textFormatter->setStyles( TextFormatter::UNDERLINE );

$textFormatter->setStyles( TextFormatter::BOLD, TextFormatter::UNDERLINE );
// или
$textFormatter->setStyles( TextFormatter::BOLD );
$textFormatter->setStyles( TextFormatter::UNDERLINE );

$color = new Classic( Classic::MAGENTA );

$textFormatter
    ->setTextColor( $color )
    ->setBackgroundColor( new Classic( Classic::WHITE ) );

$textFormatter
    ->setTextColor( new Extended( 198 ) )
    ->setBackgroundColor( new Extended( rand(0, 255) ) );

$textFormatter
    ->setTextColor( TrueColor::hex( TrueColor::REBECCA_PURPLE ) )
    ->setBackgroundColor( TrueColor::hex( "#fff" ) ) );

$textFormatter->setTextColor( new TrueColor( 255, 255, 255 ) );


win0err\TerminalTools\TextFormatter;
use win0err\TerminalTools\Colors\{
	Classic, Extended, TrueColor
};

$textFormatter = new TextFormatter( "  " );

echo 'System colors:' . PHP_EOL . PHP_EOL;
for( $i = 30; $i < 38; $i++ )
	echo $textFormatter->setBackgroundColor( new Classic( $i ) );
echo PHP_EOL;
for( $i = 90; $i < 98; $i++ )
	echo $textFormatter->setBackgroundColor( new Classic( $i ) );
echo PHP_EOL . PHP_EOL . PHP_EOL;


echo 'Extended palette: ' . PHP_EOL . PHP_EOL;
for( $green = 0; $green < 6; $green++ ) {
	for( $red = 0; $red < 6; $red++ ) {
		for( $blue = 0; $blue < 6; $blue++ ) 
			echo $textFormatter->setBackgroundColor( new Extended( 16 + ($red * 36) + ($green * 6) + $blue ) );
		
		echo " ";
	}
	echo PHP_EOL;
}
echo PHP_EOL;
for( $color = 232; $color < 256; $color++ )
	echo $textFormatter->setBackgroundColor( new Extended( $color ) );
echo PHP_EOL . PHP_EOL . PHP_EOL;

echo 'TrueColor palette (partially): ' . PHP_EOL . PHP_EOL;
for( $green = 0; $green < 256; $green += 51 ) {
	for( $red = 0; $red < 256; $red += 51 ) {
		for( $blue = 0; $blue < 256; $blue += 51 )
			echo $textFormatter->setBackgroundColor( new TrueColor( $red, $green, $blue ) );
		
		echo " ";
	}
	echo PHP_EOL;
}
echo PHP_EOL;
bash
composer