PHPackages                             malenki/ansi - 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. malenki/ansi

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

malenki/ansi
============

Simple class to put some colors into your CLI PHP apps!

1.2.6(12y ago)4345.0k↓50%[4 issues](https://github.com/malenkiki/ansi/issues)1MITPHPPHP &gt;=5.3.0

Since Sep 1Pushed 8y ago3 watchersCompare

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

READMEChangelogDependenciesVersions (8)Used By (1)

Ansi
====

[](#ansi)

[![Latest Stable Version](https://camo.githubusercontent.com/f70dafc936156c38013c54eefcb037c5c29d660294fcb5adc1aecc1d0e29efdc/68747470733a2f2f706f7365722e707567782e6f72672f6d616c656e6b692f616e73692f762f737461626c652e737667)](https://packagist.org/packages/malenki/ansi) [![Total Downloads](https://camo.githubusercontent.com/0785bfd6c5a19d8831d192edd37981d42e312ec0468f0640a4af69de7afd1161/68747470733a2f2f706f7365722e707567782e6f72672f6d616c656e6b692f616e73692f646f776e6c6f6164732e737667)](https://packagist.org/packages/malenki/ansi) [![Latest Unstable Version](https://camo.githubusercontent.com/7e3a5cef969e0c7a0226398926da392ad689d2358e37848ae0031f5cd0dcf165/68747470733a2f2f706f7365722e707567782e6f72672f6d616c656e6b692f616e73692f762f756e737461626c652e737667)](https://packagist.org/packages/malenki/ansi) [![License](https://camo.githubusercontent.com/ea42de9ec5913ab91bf1f525ee79bc6120ac214cb92cca2f2dd9588e3ff2f481/68747470733a2f2f706f7365722e707567782e6f72672f6d616c656e6b692f616e73692f6c6963656e73652e737667)](https://packagist.org/packages/malenki/ansi)

Use colors and styles in PHP terminal apps!

Quick example to understand:

```
use Malenki\Ansi;

$a = new Ansi('Hello World!');
echo $a->red->bold->underline; // you get string in red color, bold and underline! :)
```

This was just little example, please read all this doc to see how to use Ansi! You can use metthod or magic getters, as you want, and chaining methods are available.

Install It
----------

[](#install-it)

You can get code here, from github by cloning this repository, or you can use [composer](https://getcomposer.org/) too. [Ansi is available on Packagist](https://packagist.org/packages/malenki/ansi)!

So, to install it using **composer**, just put something similar to the following lines into your own `composer.json` project file:

```
{
    "require": {
        "malenki/ansi": "1.2.6",
    }
}
```

Play With It
------------

[](#play-with-it)

### What It can Do

[](#what-it-can-do)

You can use many **foregrounds**, **backgrounds** and **styles**:

- Available **foreground** colors are: `black`, `red`, `green`, `yellow`, `blue`, `purple`, `cyan` and `white`.
- Available **background** colors are: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan` and `gray`.
- Available **styles** are: `faint`, `bold`, `italic` and `underline`, but this effects may appear in different way into some terminals.

Ansi can also **parse** a string containing special XML-like tags to format it.

Magic getters are available too, and many methods are chainable. Look at the [examples directory](https://github.com/malenkiki/ansi/tree/master/examples) or read next section to see how to use Ansi.

### Example Of Use

[](#example-of-use)

"Hello World!" in red:

```
use Malenki\Ansi;

$a = new Ansi('Hello World!');
echo $a->fg('red');
```

You can **set string after constructor call** using `v()` or `value()` methods, so you can keep color and formating and apply them for other strings:

```
$a = new Ansi();
$a->fg('red');
echo $a->v('Hello World!'); //in red
echo $a->v('Hello World again!'); //in red too
```

"Hello World!" in red, background yellow:

```
use Malenki\Ansi;
echo (new Ansi('Hello World!'))->fg('red')->bg('yellow');
```

"Hello World!" in red, background yellow and in bold:

```
use Malenki\Ansi;
echo (new Ansi('Hello World!'))->fg('red')->bg('yellow')->bold();
```

You can use rendered string too:

```
use Malenki\Ansi;
$str = (new Ansi('Hello World!'))->fg('red')->bg('yellow')->bold()->render();
```

All methods are chainable, except `render()`.

Some magic getters allow new syntax, so, all **foreground colors** are available by calling their name as attribute, it is also true for **faint**, **bold**, **italic** and **underline**. Example:

```
echo (new Ansi('Hello World!'))->red->bold->underline;
```

For **background colors**, you must preceed its name by `bg` like you can see into this example:

```
echo (new Ansi('Hello World!'))->red->bold->underline->bg_blue;
```

More complex feature just added: parsing string having tags with same name as foreground colors and effects.

So an example to understand:

```
echo Ansi::parse('You can parse string containing some tags to have some effects too!');
```

Enjoy!

MIT Open Source License
-----------------------

[](#mit-open-source-license)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~36 days

Recently: every ~21 days

Total

6

Last Release

4459d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6af62130bd16d4e6bbaa5877829b6377386ef9fb6593592052dbb6eeb87c4a02?d=identicon)[malenki](/maintainers/malenki)

---

Top Contributors

[![malenkiki](https://avatars.githubusercontent.com/u/195776?v=4)](https://github.com/malenkiki "malenkiki (57 commits)")

---

Tags

cliansicolors

### Embed Badge

![Health badge](/badges/malenki-ansi/health.svg)

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

###  Alternatives

[symfony/console

Eases the creation of beautiful and testable command line interfaces

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

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

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

PHP's best friend for the terminal. CLImate allows you to easily output colored text, special formats, and more.

1.9k14.0M273](/packages/league-climate)[nunomaduro/termwind

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

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

WP-CLI framework

5.0k17.2M320](/packages/wp-cli-wp-cli)[kevinlebrun/colors.php

Colors for PHP CLI scripts

3426.7M45](/packages/kevinlebrun-colorsphp)

PHPackages © 2026

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