Skip to content
Vasil Rangelov edited this page Jan 27, 2018 · 5 revisions

Getting started

Introduction

When working with command line applications, you can color the text and background by writing ANSI escape sequences to the stream. This package allows you to specify the settings you want, and it will generate the escape sequence for you.

Requirements

  • PHP 5.3.0 or later to use this package.
  • To actually see the colors, your application needs to be ran from a console that supports ANSI escape sequences. These include:
    • Most UNIX/Linux distributions.
    • Some inner consoles in some IDEs (e.g. the console in NetBeans)
    • Windows' command prompt, but only when ANSICON is installed.

Installation

Direct PHAR usage

If you download the ".phar" archive, you can just include the archive, and be ready to go, like for example:

<?php
//You may want to include a namespace declaration here
require_once 'PEAR2_Console_Color-1.0.0.phar';
//Use PEAR2_Console_Color from here on

Installation with Pyrus/PEAR2 (recommended)

Assuming you have installed Pyrus, you can install PEAR2_Console_Color from the PEAR2 channel with just

php pyrus.phar install PEAR2_Console_Color

Installation with PEAR

Like most PEAR2 packages, PEAR_Console_Color is compatible with the PEAR installer. However, you have to first discover the PEAR2 channel with

pear channel-discover pear2.php.net

and only then install PEAR2_Console_Color with

pear install pear2.php.net/PEAR2_Console_Color

though you can omit the first step if you have ever previously called

pear config-set auto_discover 1

Installation with Composer

This package is available from packagist.org, so all you have to do is call

composer require pear2/console_color

Manual installation

Instead of using the PEAR(2) installer or Composer, you can just download a packaged archive, and extract the contents of the "src" folder wherever you like. To emulate the PEAR(2) installer, you can place the files in a folder that's within your include_path.