PHPackages                             molovo/graphite - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. molovo/graphite

ActiveLibrary[CLI &amp; Console](/categories/cli)

molovo/graphite
===============

A collection of helpers for building pretty command-line tools.

v0.1.3(10y ago)2819MITPHP

Since Mar 8Pushed 10y ago1 watchersCompare

[ Source](https://github.com/molovo/graphite)[ Packagist](https://packagist.org/packages/molovo/graphite)[ RSS](/packages/molovo-graphite/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (5)Used By (0)

Graphite
========

[](#graphite)

A collection of helpers for building pretty command-line tools.

```
$graphite = new Molovo\Graphite\Graphite;

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

Installation
------------

[](#installation)

Install using composer:

```
composer require molovo/graphite
```

Basic Usage
-----------

[](#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.

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

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.

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

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.

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

#### Available styling methods

[](#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
------------------

[](#additional-methods)

As well as the styling methods above, the following helper methods are available.

#### `strip(string $str)`

[](#stripstring-str)

The `strip()` method strips all ANSI escape codes from the passed string and returns it.

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

#### `repeat(string $character, int $length)`

[](#repeatstring-character-int-length)

The `repeat()` method returns a string consisting of the defined `$character`, repeated `$length` times.

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

Boxes
-----

[](#boxes)

The `Box` class adds a border around a string (or an array of strings, where each item is a line).

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

Boxes can be styled in a number of ways, by passing an array of styles as a second parameter.

```
$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
]);
```

The following styles are available:

```
Box::SINGLE
┌──────────┐
│The string│
└──────────┘

Box::DOUBLE
╔══════════╗
║The string║
╚══════════╝

Box::ROUNDED
╭──────────╮
│The string│
╰──────────╯

Box::SINGLE_DOUBLE
╓──────────╖
║The string║
╙──────────╜

Box::DOUBLE_SINGLE
╒══════════╕
│The string│
╘══════════╛

Box::CLASSIC
+----------+
|The string|
+----------+

```

You can also use the `Box::NO_BORDER` to add margin and padding to a string without a border.

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

You can also add titles to boxes. These are rendered within the border, in the same color.

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

Tables
------

[](#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
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

3713d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/790a48c33c76e344f6eab8edd15abca37ad75d2a957e744347b5ac4acecd9ec6?d=identicon)[molovo](/maintainers/molovo)

---

Tags

cliansigraphite

### Embed Badge

![Health badge](/badges/molovo-graphite/health.svg)

```
[![Health](https://phpackages.com/badges/molovo-graphite/health.svg)](https://phpackages.com/packages/molovo-graphite)
```

###  Alternatives

[symfony/console

Eases the creation of beautiful and testable command line interfaces

9.8k1.1B11.2k](/packages/symfony-console)[nunomaduro/collision

Cli error handling for console/command-line PHP applications.

4.6k331.8M8.5k](/packages/nunomaduro-collision)[nunomaduro/termwind

It's like Tailwind CSS, but for the console.

2.5k239.8M285](/packages/nunomaduro-termwind)[wp-cli/wp-cli

WP-CLI framework

5.0k17.2M319](/packages/wp-cli-wp-cli)[wp-cli/php-cli-tools

Console utilities for PHP

68325.0M364](/packages/wp-cli-php-cli-tools)[alecrabbit/php-console-spinner

Extremely flexible spinner for \[async\] php cli applications

24032.0k2](/packages/alecrabbit-php-console-spinner)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
