PHP code example of cspray / labrador-styled-byte-stream

1. Go to this page and download the library: Download cspray/labrador-styled-byte-stream 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/ */

    

cspray / labrador-styled-byte-stream example snippets




mp\Loop;
use Cspray\Labrador\StyledByteStream\TerminalOutputStream;
use function Amp\ByteStream\getStdout;

$stream = new TerminalOutputStream(getStdout());

// The example code is expected to be executed here

$stream->writeln('This is content on a new line');

$stream->br(3); // adds 3 new lines to the terminal output

$stream->backgroundBlue('This has a blue background');
$stream->backgroundYellow('This has a yellow background');

$stream->magenta('This is magenta text');
$stream->cyan('This is cyan text');

$stream->bold('This is bolded text');
$stream->underline('This text has an underline');

$stream->backgroundWhite()->red('This has a white background and red text');
$stream->bold()->yellow()->underline()->backgroundRed('The order of the chaining does not matter');

$stream->inline()->bold()->red('This is inline bold red text');
$stream->bold()->red('... This is text with a new line at the end');

$stream->bold()->red()->write('I am bold red inline text too!');

$stream->bold()->red()->forceNewline(2)->write('I am bold red text with 2 new lines at the end');



use Amp\ByteStream\OutputStream;
use Amp\Promise;use function Amp\call;

class ReportSummaryPrinter {

    public function __construct(private OutputStream $output) {}

    public function writeReportResults(array $report) : Promise {
        return call(function() use($report) {
            $this->output->write($report['name'] . ' received');
        });    
    }

}



spray\Labrador\StyledByteStream\TerminalOutputStream;
use function Amp\ByteStream\getStdout;

$stream = new TerminalOutputStream(getStdout());

$successfulReportOutput = $stream->forceNewline()->green();
$failedReportOutput = $stream->forceNewline()->backgroundRed()->white()->bold();
$disabledReportOutput = $stream->forceNewline()->yellow()->underline();

$successfulReportPrinter = new ReportSummaryPrinter($successfulReportOutput);
$failedReportPrinter = new ReportSummaryPrinter($failedReportOutput);
$disabledReportPrinter = new ReportSummaryPrinter($disabledReportOutput);

$successfulReportPrinter->writeReportResults(['name' => 'Foo Bar Report']);
$failedReportPrinter->writeReportResults(['name' => 'A failed report!']);
$disabledReportPrinter->writeReportResults(['name' => 'We never ran this report...']);