PHP code example of molovo / graphite

1. Go to this page and download the library: Download molovo/graphite 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/ */

    

molovo / graphite example snippets


$graphite = new Molovo\Graphite\Graphite;

echo $graphite->green->underline('I believe in unicorns!');

echo $graphite->red('A string');
// "\033[0;31mA string\033[0;m"

echo $graphite->red->yellowbg()->underline('A string');
// "\033[4;31;43mA string\033[0;m"

$graphite->setGlobalIndentation(2);
echo $graphite->yellow->render('A string');
// "  \033[0;33mA string\033[0;m\n"

$str = "\033[0;31mA string with ANSI escaping\033[0;m"
echo $graphite->strip($str);
// "A string with ANSI escaping"

echo $graphite->repeat('+', 5);
// "+++++"

$box = new Molovo\Graphite\Box('Rainbows!');
echo $box;
// ┌─────────┐
// │Rainbows!│
// └─────────┘

$box = new Box('Unicorns!', [
  'borderColor' => Graphite::WHITE, // The color of the border (and title)
  'borderStyle' => Box::SINGLE,    // The border style
  'marginX'     => 0,               // The number of characters to add to left and right
  'marginY'     => 0,               // The number of lines to add above and below
  'paddingX'    => 0,               // The number of characters to add as left and right padding
  'paddingY'    => 0,               The number of lines to add as top and bottom padding
]);

$box = new Box("Unicorns and\nrainbows", [
  'borderStyle' => Box::NO_BORDER,
  'paddingX' => 2,
  'paddingY' => 1
]);
echo $box;
//
//   Unicorns and
//   rainbows
//

$box = new Box('The string', ['paddingX' => 1]);
$box->setTitle('My Box');
echo $box;
// ┌ My Box ────┐
// │ The string │
// └────────────┘