PHPackages                             twoixter/ansicolors - 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. twoixter/ansicolors

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

twoixter/ansicolors
===================

A no-nonsense library to display ANSI colors in CLI PHP scripts.

1.0.1(12y ago)512.1k↓50%MITPHPPHP &gt;=5.3.0

Since Apr 26Pushed 12y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (3)Used By (0)

ansi::\[colors\] for PHP CLI
============================

[](#ansicolors-for-php-cli)

**ansi::\[colors\]** is a simple library for PHP CLI applications. Made for simplicity, it avoids complicated methods for ANSI code output.

By complicated methods I mean something like:

```

```

You get the point. I want to avoid a "FactorySingletonGenerator" to just print a red "E".

---

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

[](#installation)

Just use Composer. Add this to your `composer.json`:

```
{
    ...
    "require" : {
        ....
        "twoixter/ansicolors" : "~1.0"
    }
}
```

Or you just can download the `lib/ansi.php` file to your own source directory. Require it and you're ready to go.

Usage
-----

[](#usage)

**ansi:\[colors\]** uses a global Class. You **don't** need to instantiate it, just use it's static methods. If the name `ansi` in lower case collides with some other global class of your own, please rename your class. :-)

Example usage without arguments:

```

```

Note that you need to `ansi::reset()` if you don't use arguments or your text will be red forever, even when you exit the PHP script.

Alternatively, you can put some strings inside the method:

```

```

The string `this is red` will be printed in red and automatically reset to the previous console color.

### Available colors

[](#available-colors)

Available colors are the usual suspects: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan` and `white`.

Use then as static methods to the `ansi` class:

```
ansi::black(...)
ansi::red(...)

```

...and so on. They return a string containing the ANSI escape sequences, you must output it yourself, nothing is automatically echoed to the console.

### Uppercase and lowercase methods

[](#uppercase-and-lowercase-methods)

The above eight color names are lowercase. It is on purpose. Lower case name colors are dull, the brighter ones are **UPPERCASE** or **CamelCased**. Example:

```
ansi::White(...)    # Bright white. Alternate: ansi::WHITE()
ansi::Red(...)      # Bright red. Alternate: ansi::RED()

```

### Background colors

[](#background-colors)

You can not change the background color on its own, you must add also a foreground color using the following form:

```

```

The string `Yep!` will use a bright red foreground color over a white background. Background colors are all dull, `Red_on_White` has no effect, even when using all uppercase.

You can use all combinations of colors for foreground and background. Examples:

```
ansi::Red_on_white(), ansi::White_on_blue(), ansi::Black_on_green()...

```

### Named colors

[](#named-colors)

**ansi::\[colors\]** supports color aliasing as named colors. Use `ansi::define("name", "color");` to create a new named color.

Example:

```

```

### Support for pipes

[](#support-for-pipes)

**ansi:\[colors\]** is smart enough to disable itself when piped. So you can do things like:

```
$ php myscript.php | less
$ php myscript.php > output_file.txt

```

And you can be sure no ANSI codes will mangle your output. Perfect for logging to file for example, or using `less` to paginate.

License
-------

[](#license)

Licensed under the MIT license --

If you like **ansi::\[colors\]**, please send some cheers to my Twitter at @twoixter. If you find some bugs, please fork and send me a pull request, I'm open to suggestions except changing the class name `ansi` to uppercase `Ansi`... *(Just kidding)* :-)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

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

Total

2

Last Release

4405d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4ff9e79311491f3b163849c7f62380993791552e8c50d9612945e88ccd2ef7bd?d=identicon)[twoixter](/maintainers/twoixter)

---

Top Contributors

[![twoixter](https://avatars.githubusercontent.com/u/88262?v=4)](https://github.com/twoixter "twoixter (3 commits)")

---

Tags

clicoloransidisplay

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/twoixter-ansicolors/health.svg)

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

###  Alternatives

[symfony/console

Eases the creation of beautiful and testable command line interfaces

9.8k1.1B11.3k](/packages/symfony-console)[kevinlebrun/colors.php

Colors for PHP CLI scripts

3426.7M45](/packages/kevinlebrun-colorsphp)[alecrabbit/php-console-spinner

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

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

Lightweight cli spinner with zero dependencies

29211.3k5](/packages/alecrabbit-php-cli-snake)[inhere/console

php console library, provide console argument parse, console controller/command run, color style, user interactive, information show.

3477.4k12](/packages/inhere-console)[malenki/ansi

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

4345.0k1](/packages/malenki-ansi)

PHPackages © 2026

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