This package is abandoned and no longer maintained. No replacement package was suggested.

Return your terminal message in style! Change the text style, text color and text background color from the terminal, console or shell interface with ANSI color codes.


  • The easiest way to style your text in the command line / terminal
  • Change text color to red, green, yellow ...
  • Change background color to red, green, yellow ...
  • Change text style to bold, dim, underlined, blink ...
  • Has support for 0 , 16, 256 and true color ...



$ composer require testomat/terminal-colour

Note : By default, the Windows command console doesn’t support output coloring. This library disables output coloring for Windows systems. But if your commands or scripts invoke other scripts which emit color sequences, they will be wrongly displayed as raw escape characters. Install the Cmder, ConEmu, ANSICON or Mintty (used by default in GitBash and Cygwin) to add coloring support to your Windows command console.


Using Color Styles



use Testomat\TerminalColour\Formatter;

$formatter = new Formatter();

// green text

// yellow text

// black text on a cyan background

// white text on a red background

The closing tag can be replaced by </>, which revokes all formatting options established by the last opened tag.

It’s possible to define your own styles using the Formatter class:



use Testomat\TerminalColour\Formatter;
use Testomat\TerminalColour\Style;

$style = new Style('red', 'yellow', ['bold', 'blink']);

$formatter = new Formatter(false, ['fire' => $style]);


Available foreground and background colors are black, red, green, yellow, blue, magenta, cyan, white, default, dark_grey, light_grey, light_red, light_green, light_yellow, light_blue, light_magenta, light_cyan, light_white.

And available options are: none, bold, dark, italic, underscore, blink, blink_fast, crossed_out, double_underline, curly_underline, overlinem, reverse (enables the "reverse video" mode where the background and foreground colors are swapped) and conceal (sets the foreground color to transparent, making the typed text invisible—although it can be selected and copied; this option is commonly used when asking the user to type sensitive information).

You want to use 256 colors or true colors than you must use the StyleCode class.



use Testomat\TerminalColour\Formatter;
use Testomat\TerminalColour\StyleCode;

$style256 = new StyleCode(34); // will be transformed to '38;5;34' blue
$trueStyle = new StyleCode("38;2;1;1;1"); // same goes for 1;1;1 as value; will be transformed to '38;2;1;1;1'

$formatter = new Formatter(false, ['color256Blue' => $style256,  'trueColor' => $trueStyle]);


You can also set these colors and options directly inside the tag name:

// green text

// black text on a cyan background

// bold text on a yellow background

// bold text with underscore

Note: if you need to render a tag literally, escape it with a backslash: <info> or use the escape() method to escape all the tags included in the given string.

You have the possibility with formatAndWrap(string $message, int $width) function to wrap you text to a specific width, 0 means no wrapping.

Note: you want to check the color support for you terminal check the example folder out.

Displaying Clickable Links

Commands can use the special <href> tag to display links like the <a> elements of web pages:

$formatter->format('<href=https://narrowspark.com>Narrowspark Homepage</>');

If your terminal belongs to the list of terminal emulators that support links you can click on the "Narrowspark Homepage" text to open its URL in your default browser. Otherwise, you’ll see "Narrowspark Homepage" as regular text and the URL will be lost.

Terminal Util

You want to know, what color or how any columns your terminal supports, than you can call:



use Testomat\TerminalColour\Util;

echo Util::getNumberOfColumns(); // returns the number of the columns

echo Util::getSupportedColor(); // returns the supported color as int


Colors 3/4 bit


Hyperlinks (a.k.a. HTML-like anchors) in terminal emulators


This library follows semantic versioning, and additions to the code ruleset are performed in major releases.


Please have a look at CHANGELOG.md.


Please have a look at CONTRIBUTING.md.

Code of Conduct

Please have a look at CODE_OF_CONDUCT.md.


This package is licensed using the MIT License.

Please have a look at LICENSE.md.