Download the PHP package molovo/graphite without Composer
On this page you can find all versions of the php package molovo/graphite. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package graphite
Graphite
A collection of helpers for building pretty command-line tools.
Installation
Install using composer:
Basic Usage
Once instantiated, the Graphite class becomes a re-usable string rendering tool. It comes with a number of methods for styling the foreground color, background color and style of a string using ANSI escape codes.
When accessed as a property, or as a method without arguments, these methods allow chaining of styles. When a string is passed as the first argument, it is returned with all the chained styles applied.
Global indentation can be set with the setGlobalIndentation()
method. Once defined, when the render()
method is invoked, the string passed to it is output with the defined indentation prepended to it, and with a newline appended.
Available styling methods
black
blackbg
red
redbg
green
greenbg
yellow
yellowbg
blue
bluebg
magenta
magentabg
cyan
cyanbg
white
whitebg
gray
graybg
bold
italic
underline
inverse
strikethrough
Additional Methods
As well as the styling methods above, the following helper methods are available.
strip(string $str)
The strip()
method strips all ANSI escape codes from the passed string and returns it.
repeat(string $character, int $length)
The repeat()
method returns a string consisting of the defined $character
, repeated $length
times.
Boxes
The Box
class adds a border around a string (or an array of strings, where each item is a line).
Boxes can be styled in a number of ways, by passing an array of styles as a second parameter.
The following styles are available:
You can also use the Box::NO_BORDER
to add margin and padding to a string without a border.
You can also add titles to boxes. These are rendered within the border, in the same color.
Tables
$data = [
['First', 'Second', 'Third'],
[1, 2, 3],
[11, 22, 33],
];
$table = new Table($data, [
'cellPadding' => 1,
'columnSeparator' => '│',
'headerColor' => Graphite::WHITE,
'headerSeparator' => '═',
'marginX' => 0,
'marginY' => 0,
'separatorColor' => Graphite::WHITE,
]);
echo $table;
// First │ Second │ Third
// ══════════════════════════
// 1 │ 2 │ 3
// 11 │ 22 │ 33