PHPackages                             weew/console-formatter - 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. weew/console-formatter

ActiveLibrary

weew/console-formatter
======================

Formatter for command line output.

v2.1.2(9y ago)012.4kMITPHP

Since Apr 4Pushed 9y ago1 watchersCompare

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

READMEChangelogDependencies (6)Versions (9)Used By (0)

Output Formatter for command line
=================================

[](#output-formatter-for-command-line)

[![Build Status](https://camo.githubusercontent.com/1b1a2d0275254d6cf2a7e611265421c3fcbf8fa04422cc9cace2882b20e84bb8/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f776565772f636f6e736f6c652d666f726d61747465722e737667)](https://travis-ci.org/weew/console-formatter)[![Code Quality](https://camo.githubusercontent.com/9b3b0bd243723d578f3504b17cdac90f7810af0b0bdf6aa126eedad3c85bd6c1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f776565772f636f6e736f6c652d666f726d61747465722e737667)](https://scrutinizer-ci.com/g/weew/console-formatter)[![Test Coverage](https://camo.githubusercontent.com/fbd0dc064a7de2a317c7bfa559016273bde6f51f4b5262144c10a38241d785b9/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f776565772f636f6e736f6c652d666f726d61747465722e737667)](https://coveralls.io/github/weew/console-formatter)[![Version](https://camo.githubusercontent.com/a1073085541abe5eadff8437a90462b2d59513bc0f3f5c0fa4f9bcefcf0cc45e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f776565772f636f6e736f6c652d666f726d61747465722e737667)](https://packagist.org/packages/weew/console-formatter)[![Licence](https://camo.githubusercontent.com/444babb431dd2b9521d8a07772dddc160746bf498027aebe119f69a39cbf5d50/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f776565772f636f6e736f6c652d666f726d61747465722e737667)](https://packagist.org/packages/weew/console-formatter)

Table of contents
-----------------

[](#table-of-contents)

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

[](#installation)

`composer require weew/console-formatter`

Introduction
------------

[](#introduction)

This package allows you to format text for terminal, using very simple and html like syntax. You will be able to change *text color*, *text background* and *text format*.

This package **has not been tested on windows** and I do not intend to do so. Contributions for windows support are highly appreciated.

Adding styles
-------------

[](#adding-styles)

Before you'll be able to use styles, you must created them first.

```
$formatter = new ConsoleFormatter();

$style = (new ConsoleStyle('alert'))
    ->setColor(ConsoleColor::WHITE)
    ->setBackground(ConsoleBackground::RED)
    ->setFormat([ConsoleFormat::BOLD, ConsoleFormat::UNDERLINE]);
$formatter->addStyle($style);

// or

$formatter->style('alert')
    ->setColor(ConsoleColor::WHITE)
    ->setBackground(ConsoleBackground::RED)
    ->setFormat([ConsoleFormat::BOLD, ConsoleFormat::UNDERLINE]);

// or

$formatter->style('alert')
    ->parseStyle('clr=white bg=red fmt=bold,underline');
```

Using styles
------------

[](#using-styles)

As soon as you've register a style, it will be applied to matching tags. If a style is unknown, the tag will be ignored. Example below will output properly formatted text.

```
echo $formatter->format('text');
```

Using inline styles
-------------------

[](#using-inline-styles)

You can apply styling inline, without having to register a new style. To do that you must use the `` tag.

```
echo $formatter->format('red text on white background');
```

You can also use inline styling on predefined styles.

```
$formatter->format('alert style with yellow text');
```

Style isolation
---------------

[](#style-isolation)

Whenever you have nested styles, one style might inherit from the parent. This is disabled by default to prevent unwanted styles changes. You can enable it for each style separately.

```
$formatter->style('name')
   ->setAllowInheritance(true);
```

Disabling ANSI
--------------

[](#disabling-ansi)

If you're working with a terminal that does not support ANSI, you can disable formatting. All known style tags will be removed from the string.

```
$formatter->setEnableAnsi(false);
// will return: alert tag
$formatter->format('alert tag');
```

Examples
--------

[](#examples)

You can run the `examples.php` file to see if it works on your system.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity68

Established project with proven stability

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

Recently: every ~26 days

Total

8

Last Release

3579d ago

Major Versions

v1.2.0 → v2.0.02016-04-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/10b2b854b5829dd13a15967c000ed2119b5faef67aca24d94c653c8ac550d85e?d=identicon)[weew](/maintainers/weew)

### Embed Badge

![Health badge](/badges/weew-console-formatter/health.svg)

```
[![Health](https://phpackages.com/badges/weew-console-formatter/health.svg)](https://phpackages.com/packages/weew-console-formatter)
```

###  Alternatives

[magento/magento2-functional-testing-framework

Magento2 Functional Testing Framework

15511.5M30](/packages/magento-magento2-functional-testing-framework)

PHPackages © 2026

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