PHPackages                             cdoco/ansi-styles - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. cdoco/ansi-styles

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

cdoco/ansi-styles
=================

ANSI escape codes for styling strings in the terminal

1.0.0(8y ago)1102PHP

Since Nov 15Pushed 8y ago1 watchersCompare

[ Source](https://github.com/cdoco/ansi-styles)[ Packagist](https://packagist.org/packages/cdoco/ansi-styles)[ RSS](/packages/cdoco-ansi-styles/feed)WikiDiscussions master Synced 2w ago

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

ansi-styles
===========

[](#ansi-styles)

> [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) for styling strings in the terminal

[![](screenshot.png)](screenshot.png)

Install
-------

[](#install)

```
$ composer require cdoco/ansi-styles

```

Usage
-----

[](#usage)

```
require_once 'vendor/autoload.php';

$style = new \Cdoco\AnsiStyles();

echo $style->blue->open . 'Hello Word!' . PHP_EOL . $style->blue->close;

echo $style->color->rgb(100, 200, 15) . "Hello Word!" . PHP_EOL . $style->color->close;
echo $style->color->hsl(120, 100, 60) . "Hello Word!" . PHP_EOL . $style->color->close;
echo $style->color->hex('#C0FFEE') . "Hello Word!" . PHP_EOL . $style->color->close;

echo $style->bgColor->rgb(100, 200, 15) . "Hello Word!" . PHP_EOL . $style->bgColor->close;
```

API
---

[](#api)

Each style has an `open` and `close` property.

Styles
------

[](#styles)

### Modifiers

[](#modifiers)

- `reset`
- `bold`
- `dim`
- `italic` *(Not widely supported)*
- `underline`
- `inverse`
- `hidden`
- `strikethrough` *(Not widely supported)*

### Colors

[](#colors)

- `black`
- `red`
- `green`
- `yellow`
- `blue`
- `magenta`
- `cyan`
- `white`
- `gray` ("bright black")
- `redBright`
- `greenBright`
- `yellowBright`
- `blueBright`
- `magentaBright`
- `cyanBright`
- `whiteBright`

### Background colors

[](#background-colors)

- `bgBlack`
- `bgRed`
- `bgGreen`
- `bgYellow`
- `bgBlue`
- `bgMagenta`
- `bgCyan`
- `bgWhite`
- `bgBlackBright`
- `bgRedBright`
- `bgGreenBright`
- `bgYellowBright`
- `bgBlueBright`
- `bgMagentaBright`
- `bgCyanBright`
- `bgWhiteBright`

Advanced usage
--------------

[](#advanced-usage)

By default, you get a map of styles, but the styles are also available as groups. They are non-enumerable so they don't show up unless you access them explicitly. This makes it easier to expose only a subset in a higher-level module.

- `$style->modifier`
- `$style->color`
- `$style->bgColor`

###### Example

[](#example)

```
echo $style->color->green->open;
```

[256 / 16 million (TrueColor) support](https://gist.github.com/XVilka/8346728)
------------------------------------------------------------------------------

[](#256--16-million-truecolor-support)

To use these, call the associated conversion function with the intended output, for example:

```
$style->color->rgb(100, 200, 15); // RGB to 16 color ansi foreground code
$style->bgColor->rgb(100, 200, 15); // RGB to 16 color ansi background code

$style->color->hsl(120, 100, 60); // HSL to 256 color ansi foreground code
$style->bgColor->hsl(120, 100, 60); // HSL to 256 color ansi foreground code

$style->color->hex('#C0FFEE'); // Hex (RGB) to 16 million color foreground code
$style->bgColor->hex('#C0FFEE'); // Hex (RGB) to 16 million color background code
```

License
-------

[](#license)

MIT

###  Health Score

28

—

LowBetter than 51% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

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

Unknown

Total

1

Last Release

3195d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8597204?v=4)[ZiHang Gao](/maintainers/cdoco)[@cdoco](https://github.com/cdoco)

---

Top Contributors

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

---

Tags

ansi-colorsansi-stylesconsole-colorlogcliconsolecommand-lineterminalloggingstringshellcolorrgbtextformattingansiEscapestylescolourcolorsxtermtty256

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[kevinlebrun/colors.php

Colors for PHP CLI scripts

3427.1M47](/packages/kevinlebrun-colorsphp)[alecrabbit/php-console-spinner

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

24039.8k2](/packages/alecrabbit-php-console-spinner)[trash-panda/progress-bar-log

Component to display a progress bar and last X logs at the same time

4119.5k](/packages/trash-panda-progress-bar-log)[phpconsole/phpconsole

A detached logging facility for PHP to aid your daily development routine

417.5k1](/packages/phpconsole-phpconsole)

PHPackages © 2026

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