[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/pake/ -> pakeColor.class.php (source)

   1  <?php
   2  
   3  /**
   4   * @package    pake
   5   * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
   6   * @copyright  2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
   7   * @license    see the LICENSE file included in the distribution
   8   * @version    SVN: $Id: pakeColor.class.php 2990 2006-12-09 11:10:59Z fabien $
   9   */
  10  
  11  /**
  12   *
  13   * main pake class.
  14   *
  15   * This class is a singleton.
  16   *
  17   * @package    pake
  18   * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  19   * @copyright  2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
  20   * @license    see the LICENSE file included in the distribution
  21   * @version    SVN: $Id: pakeColor.class.php 2990 2006-12-09 11:10:59Z fabien $
  22   */
  23  class pakeColor
  24  {
  25    static public $styles = array();
  26  
  27    static function style($name, $options = array())
  28    {
  29      self::$styles[$name] = $options;
  30    }
  31  
  32    static function colorize($text = '', $parameters = array(), $stream = STDOUT)
  33    {
  34      // disable colors if not supported (windows or non tty console)
  35      if (DIRECTORY_SEPARATOR == '\\' || !function_exists('posix_isatty') || !@posix_isatty($stream))
  36      {
  37        return $text;
  38      }
  39  
  40      static $options    = array('bold' => 1, 'underscore' => 4, 'blink' => 5, 'reverse' => 7, 'conceal' => 8);
  41      static $foreground = array('black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37);
  42      static $background = array('black' => 40, 'red' => 41, 'green' => 42, 'yellow' => 43, 'blue' => 44, 'magenta' => 45, 'cyan' => 46, 'white' => 47);
  43  
  44      if (!is_array($parameters) && isset(self::$styles[$parameters]))
  45      {
  46        $parameters = self::$styles[$parameters];
  47      }
  48  
  49      $codes = array();
  50      if (isset($parameters['fg']))
  51      {
  52        $codes[] = $foreground[$parameters['fg']];
  53      }
  54      if (isset($parameters['bg']))
  55      {
  56        $codes[] = $background[$parameters['bg']];
  57      }
  58      foreach ($options as $option => $value)
  59      {
  60        if (isset($parameters[$option]) && $parameters[$option])
  61        {
  62          $codes[] = $value;
  63        }
  64      }
  65  
  66      return "\033[".implode(';', $codes).'m'.$text."\033[0m";
  67    }
  68  }
  69  
  70  pakeColor::style('ERROR',    array('bg' => 'red', 'fg' => 'white', 'bold' => true));
  71  pakeColor::style('INFO',     array('fg' => 'green', 'bold' => true));
  72  pakeColor::style('COMMENT',  array('fg' => 'yellow'));


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7