Gombo
Gombo

Reputation: 748

Symfony task: displaying colored text in the output (command line)?

I would like to have a very basic formatting (just colors) on the text displayed by a Symfony task in the command line output (just like the colors you see when running tests): any idea?

Thanks a lot

Upvotes: 1

Views: 2907

Answers (3)

Volkkerine
Volkkerine

Reputation: 86

You can change the color of the Symfony terminal output by changing the file:

/lib/symfony/vendor/phing/listener/AnsiColorLogger.php

At the constructor method you can change the color of each type of output (info, error, debug...):

public function __construct() {
    parent::__construct();
    $this->errColor = self::PREFIX . self::ATTR_DIM . self::SEPARATOR . self::FG_RED . self::SUFFIX;
    $this->warnColor = self::PREFIX . self::ATTR_DIM . self::SEPARATOR . self::FG_MAGENTA . self::SUFFIX;
    $this->infoColor = self::PREFIX . self::ATTR_DIM . self::SEPARATOR . self::FG_GREEN . self::SUFFIX;
    $this->verboseColor = self::PREFIX . self::ATTR_DIM . self::SEPARATOR . self::FG_CYAN . self::SUFFIX;
    $this->debugColor = self::PREFIX . self::ATTR_DIM . self::SEPARATOR . self::FG_BLUE . self::SUFFIX;
}

You have a limited range of colors but it may help you.

Upvotes: 1

domi27
domi27

Reputation: 6923

In your task you may use two functions, both with a $style parameter, to generate an output :

And here you can find Symfony's documentation.

Upvotes: 3

samura
samura

Reputation: 4395

You can try something like:

echo "\033[01;31m Show me some red colors \033[0m";

More colors here: http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html

Upvotes: 3

Related Questions