apply() public method

public apply ( $style, $text = null )
 public function error()
 {
     if ($this->color) {
         $this->writer->write($this->color->apply('bg_red', 'X'));
         $this->progress();
     } else {
         parent::error();
     }
 }
 /**
  * @param string $string
  * @param array|string $colourOrStyle
  *
  * @return string
  *
  */
 public function style($string, $colourOrStyle)
 {
     if (is_array($colourOrStyle)) {
         $this->color->__invoke($string);
         while ($style = array_shift($colourOrStyle)) {
             $this->color->apply($style);
         }
         return $this->color->__toString();
     }
     return $this->color->__invoke($string)->apply($colourOrStyle, $string);
 }
Example #3
0
#!/usr/bin/env php
<?php 
require_once __DIR__ . '/vendor/autoload.php';
use Colors\Color;
$c = new Color();
// highlight('green') === bg('green') === bg_green()
// white() === fg('white')
echo $c('Hello World!')->white()->bold()->highlight('green') . PHP_EOL;
// using some magic
echo $c('Hello World!')->white->bold->bg_green . PHP_EOL;
// create your own styles
$c->setUserStyles(array('welcome' => array('white', 'bg_green'), 'bye' => 'blue'));
echo $c('Hello World!')->welcome->bold . PHP_EOL;
echo $c('Bye!')->bye . PHP_EOL;
// use style tags
$text = <<<EOF
1 : <welcome>Hello <bold>World!</bold></welcome>
2 : <bye>Bye!</bye>
EOF;
echo $c($text)->colorize() . PHP_EOL;
// center text
$text = 'hello' . PHP_EOL . '✩' . PHP_EOL . 'world';
echo $c($text)->center() . PHP_EOL;
// use standard API
$message = $c->apply('bold', $c->white('Hello World!'));
echo $message . PHP_EOL;
echo $c->clean($message) . PHP_EOL;
Example #4
0
#!/usr/bin/env php
<?php 
require_once __DIR__ . '/vendor/autoload.php';
use Colors\Color;
$c = new Color();
echo 'System colors:' . PHP_EOL;
for ($i = 0; $i < 16; $i++) {
    echo $c->apply('bg_color[' . $i . ']', '  ');
}
echo PHP_EOL . PHP_EOL . 'Color cube, 6x6x6:' . PHP_EOL;
for ($g = 0; $g < 6; $g++) {
    for ($r = 0; $r < 6; $r++) {
        for ($b = 0; $b < 6; $b++) {
            $color = 16 + $r * 36 + $g * 6 + $b;
            echo $c('  ')->bg('color[' . $color . ']');
        }
        echo ' ';
    }
    echo PHP_EOL;
}
echo PHP_EOL . 'Grayscale ramp:' . PHP_EOL;
for ($i = 232; $i < 256; $i++) {
    echo $c('  ')->bg('color[' . $i . ']');
}