Permalink
Browse files

first commit to sync with my local code repository

  • Loading branch information...
0 parents commit 9e63c0485272731041c80481ab2cb14d1edcb32a @iannsp iannsp committed Aug 3, 2011
@@ -0,0 +1 @@
+Package Console_Color API release notes for version 0.1.0.
@@ -0,0 +1,2 @@
+;Maintainer of PEAR2_Command_Color
+Ivo Nascimento [ivonascimento] <ivo@o8o.com.br> (lead)
4 README
@@ -0,0 +1,4 @@
+PEAR2_Console_Color is a Package to provide a easy way to print text in
+command line when its necessary.
+Have a simple interface and basicly using the static function 'convert'
+you can make use of this Object.
@@ -0,0 +1,3 @@
+Iniciar cover of needs to echo messages to command with color, background and styles
+Trying to use the save public interface the PEAR/Console_Color to provide a way to
+use as 4.* (PEAR) or 5.* (PEAR2)
@@ -0,0 +1,25 @@
+<?php
+/**
+ * This file is used to provide extra files/packages outside package.xml
+ * More information: http://pear.php.net/manual/en/pyrus.commands.package.php#pyrus.commands.package.extrasetup
+ */
+$extrafiles = array();
+
+/**
+ * for example:
+if (basename(__DIR__) == 'trunk') {
+ $extrafiles = array(
+ new \PEAR2\Pyrus\Package(__DIR__ . '/../../HTTP_Request/trunk/package.xml'),
+ new \PEAR2\Pyrus\Package(__DIR__ . '/../../sandbox/Console_CommandLine/trunk/package.xml'),
+ new \PEAR2\Pyrus\Package(__DIR__ . '/../../MultiErrors/trunk/package.xml'),
+ new \PEAR2\Pyrus\Package(__DIR__ . '/../../Exception/trunk/package.xml'),
+ );
+} else {
+ $extrafiles = array(
+ new \PEAR2\Pyrus\Package(__DIR__ . '/../HTTP_Request/package.xml'),
+ new \PEAR2\Pyrus\Package(__DIR__ . '/../sandbox/Console_CommandLine/package.xml'),
+ new \PEAR2\Pyrus\Package(__DIR__ . '/../MultiErrors/package.xml'),
+ new \PEAR2\Pyrus\Package(__DIR__ . '/../Exception/package.xml'),
+ );
+}
+*/
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package version="2.1" xmlns="http://pear.php.net/dtd/package-2.1" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.1 http://pear.php.net/dtd/package-2.1.xsd">
+ <name>PEAR2_Console_Color</name>
+ <channel>pear2.php.net</channel>
+ <summary>Package PEAR2_Console_Color summary.</summary>
+ <description>
+Package detailed description here (found in README)</description>
+ <lead>
+ <name>Ivo Nascimento</name>
+ <user>ivonascimento</user>
+ <email>ivo@o8o.com.br</email>
+ <active>yes</active>
+ </lead>
+ <date>2011-08-02</date>
+ <time>13:24:31</time>
+ <version>
+ <release>0.1.0</release>
+ <api>0.1.0</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD License</license>
+ <notes>Package PEAR2_Console_Color release notes for version 0.1.0.
+
+Package PEAR2_CacheSystem API release notes for version 0.1.0.</notes>
+ <contents>
+ <dir name="/">
+ <dir name="src" baseinstalldir="PEAR2">
+ <dir name="Console_Color">
+ <file role="php" name="Main.php"/>
+ </dir>
+ </dir>
+ </dir>
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>5.3.0</min>
+ </php>
+ <pearinstaller>
+ <min>2.0.0a1</min>
+ </pearinstaller>
+ </required>
+ </dependencies>
+ <phprelease/>
+</package>
@@ -0,0 +1,18 @@
+<?php
+/**
+ * Extra package.xml settings such as dependencies.
+ * More information: http://pear.php.net/manual/en/pyrus.commands.make.php#pyrus.commands.make.packagexmlsetup
+ */
+/**
+ * for example:
+$package->dependencies['required']->package['pear2.php.net/PEAR2_Autoload']->save();
+$package->dependencies['required']->package['pear2.php.net/PEAR2_Exception']->save();
+$package->dependencies['required']->package['pear2.php.net/PEAR2_MultiErrors']->save();
+$package->dependencies['required']->package['pear2.php.net/PEAR2_HTTP_Request']->save();
+
+$compatible->dependencies['required']->package['pear2.php.net/PEAR2_Autoload']->save();
+$compatible->dependencies['required']->package['pear2.php.net/PEAR2_Exception']->save();
+$compatible->dependencies['required']->package['pear2.php.net/PEAR2_MultiErrors']->save();
+$compatible->dependencies['required']->package['pear2.php.net/PEAR2_HTTP_Request']->save();
+*/
+?>
@@ -0,0 +1,91 @@
+<?php
+/**
+ * Console\Color\Main
+ *
+ * PHP version 5
+ *
+ * @category Console
+ * @package Console_Color
+ * @author Ivo Nascimento <ivo@o8o.com.br>
+ * @copyright 2011 Ivo Nascimento
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
+ * @version SVN: $Id$
+ * @link
+ */
+
+/**
+ * Main class for Console_Color
+ *
+ * @category Console
+ * @package Console_Color
+ * @author Ivo Nascimento <ivo@o8o.com.br>
+ * @copyright 2011 Ivo Nascimento
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
+ * @link http://pear.php.net/package/Console_Color
+ */
+namespace PEAR2\Console\Color;
+class Color
+{
+ /**
+ *
+ * add constant values to values retrieved by specific mappers
+ * @param string $value the value form the mappers
+ * @return string the final value to command line
+ * @access private
+ */
+ private static function decorateValue($value){
+ return "\033[".$value.'m';
+ }
+ /**
+ *
+ * get the value into mappers
+ * @param string $value the value the user insert in text
+ * @return string
+ * @access private
+ */
+ private static function get($value){
+ $diff = $value[1];
+ if ( filter_var($diff,FILTER_SANITIZE_NUMBER_INT) == $diff )
+ {
+ $returnvalue = BackgroundMapper::get($value);
+ }
+ else if ( strtolower($diff) == $diff)
+ {
+ $returnvalue = ColorMapper::get($value);
+ }
+ else
+ {
+ $returnvalue = StyleMapper::get($value);
+ }
+
+ if ($returnvalue !== false)
+ return $returnvalue;
+ else
+ throw New \Exception( "Value {$value} not found" );
+ }
+ /**
+ *
+ * search values into string and replace with mapped values
+ * @param string $string
+ * @access public
+ * @return string
+ */
+ public static function convert($string){
+ $string = self::sanitize($string);
+ $matches = self::getPatterns($string);
+ if ( count($matches) ){
+ foreach ($matches[0] as $key) {
+ $newvalue ="";
+ if ( is_array( ($keys=self::get($key)))){
+ foreach ($keys as $ikey){
+ $newvalue .= self::decorateValue( $ikey ) ;
+ }
+ }else
+ $newvalue = self::decorateValue(
+ self::get($key)) ;
+ $string = str_replace($key, $newvalue, $string);
+ }
+ }
+ return $string;
+ }
+}
@@ -0,0 +1,35 @@
+<?php
+
+/**
+ * ColorMapper class for PEAR2_Console_Color
+ * Mappping the names of BackGroundColor to your values
+ *
+ * @category Console
+ * @package PEAR2_Console_Color
+ * @author Ivo Nascimento <ivo@o8o.com.br>
+ * @copyright 2011 Ivo Nascimento
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
+ * @link http://svn.php.net/repository/pear2/PEAR2_Console_Color
+ */
+namespace PEAR2\Console\Color;
+class BackgroundMapper extends Mapper
+{
+ const BLACK = 40;
+ const RED = 41;
+ const GREEN = 42;
+ const BROWN = 43;
+ const YELLOW = 43;
+ const BLUE = 44;
+ const PURPLE = 45;
+ const CYAN = 46;
+ const GREY = 47;
+ const percent3 = self::YELLOW;
+ const percent2 = self::GREEN;
+ const percent4 = self::BLUE;
+ const percent1 = self::RED;
+ const percent5 = self::PURPLE;
+ const percent6 = self::CYAN;
+ const percent7 = self::GREY;
+ const percent0 = self::BLACK;
+
+}
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * ColorMapper class for PEAR2_Console_Color
+ * Mappping the names of color to your values
+ *
+ * @category Console
+ * @package PEAR2_Console_Color
+ * @author Ivo Nascimento <ivo@o8o.com.br>
+ * @copyright 2011 Ivo Nascimento
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
+ * @link
+ */
+namespace PEAR2\Console\Color;
+class ColorMapper extends Mapper
+{
+ const BLACK = 30;
+ const GREEN = 32;
+ const BROWN = 33;
+ const RED = 31;
+ const BLUE = 34;
+ const PURPLE = 35;
+ const CYAN = 36;
+ const GREY = 37;
+ const YELLOW = 33;
+ const percenty = self::YELLOW;
+ const percentg = self::GREEN;
+ const percentb = self::BLUE;
+ const percentr = self::RED;
+ const percentp = self::PURPLE;
+ const percentm = self::PURPLE;
+ const percentc = self::CYAN;
+ const percentw = self::GREY;
+ const percentk = self::BLACK;
+ const percentn = 0;
+ const RESET = 0;
+
+}
@@ -0,0 +1,30 @@
+<?php
+
+/**
+ * Mapper class for PEAR2_Console_Color
+ * the Abstract class used to construct mappers to colors
+ *
+ * @category Console
+ * @package PEAR2_Console_Color
+ * @author Ivo Nascimento <ivo@o8o.com.br>
+ * @copyright 2011 Ivo Nascimento
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
+ * @link http://svn.php.net/repository/pear2/PEAR2_Console_Color
+ */
+namespace PEAR2\Console\Color;
+abstract class Mapper
+{
+
+ public static function get( $name )
+ {
+ $name = str_replace('%', 'percent', $name);
+ $rColorMapper = New \ReflectionClass( get_called_class() );
+ if( ($item=$rColorMapper->getConstant($name) )!==false )
+ return $item;
+ else if( ($item=$rColorMapper->getProperty($name) )!==false )
+ return $item->getValue( get_called_class() );
+ else
+ return false;
+ }
+
+}
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * StyleMapper class for PEAR2_Console_Color
+ * Mappping the names of Font Style to your values
+ *
+ * @category Console
+ * @package PEAR2_Console_Color
+ * @author Ivo Nascimento <ivo@o8o.com.br>
+ * @copyright 2011 Ivo Nascimento
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
+ * @link http://svn.php.net/repository/pear2/PEAR2_Console_Color
+ */
+namespace PEAR2\Console\Color;
+
+class StyleMapper extends ColorMapper
+{
+ const NORMAL = 0;
+ const BOLD = 1;
+ const LIGHT = 1;
+ const UNDERSCORE = 4;
+ const UNDERLINE = 4;
+ const BLINK = 5;
+ const INVERSE = 6;
+ const HIDDEN = 8;
+ const CONCEALED = 8;
+ public static $percentY = Array(ColorMapper::YELLOW,self::LIGHT);
+ public static $percentG = Array(ColorMapper::GREEN,self::LIGHT);
+ public static $percentB = Array(ColorMapper::BLUE,self::LIGHT);
+ public static $percentR = Array(ColorMapper::RED,self::LIGHT);
+ public static $percentP = Array(ColorMapper::PURPLE,self::LIGHT);
+ public static $percentM = Array(ColorMapper::PURPLE,self::LIGHT);
+ public static $percentC = Array(ColorMapper::CYAN,self::LIGHT);
+ public static $percentW = Array(ColorMapper::GREY,self::LIGHT);
+ public static $percentK = Array(ColorMapper::BLACK,self::LIGHT);
+ public static $percentN = Array(ColorMapper::RESET,self::LIGHT);
+}
@@ -0,0 +1,52 @@
+#!/usr/bin/env php
+<?php
+/**
+ * If your package does special stuff in phar format, use this file. Remove if
+ * no phar format is ever generated
+ * More information: http://pear.php.net/manual/en/pyrus.commands.package.php#pyrus.commands.package.stub
+ */
+if (version_compare(phpversion(), '5.3.1', '<')) {
+ if (substr(phpversion(), 0, 5) != '5.3.1') {
+ // this small hack is because of running RCs of 5.3.1
+ echo "Console_Color requires PHP 5.3.1 or newer.
+";
+ exit -1;
+ }
+}
+foreach (array('phar', 'spl', 'pcre', 'simplexml') as $ext) {
+ if (!extension_loaded($ext)) {
+ echo 'Extension ', $ext, " is required
+";
+ exit -1;
+ }
+}
+try {
+ Phar::mapPhar();
+} catch (Exception $e) {
+ echo "Cannot process Console_Color phar:
+";
+ echo $e->getMessage(), "
+";
+ exit -1;
+}
+function Console_Color_autoload($class)
+{
+ $class = str_replace(array('_', '\\'), '/', $class);
+ if (file_exists('phar://' . __FILE__ . '/Console_Color-0.4.0/php/' . $class . '.php')) {
+ include 'phar://' . __FILE__ . '/Console_Color-0.4.0/php/' . $class . '.php';
+ }
+}
+spl_autoload_register("Console_Color_autoload");
+$phar = new Phar(__FILE__);
+$sig = $phar->getSignature();
+define('Console_Color_SIG', $sig['hash']);
+define('Console_Color_SIGTYPE', $sig['hash_type']);
+
+// your package-specific stuff here, for instance, here is what Pyrus does:
+
+/**
+ * $frontend = new \PEAR2\Pyrus\ScriptFrontend\Commands;
+ * @array_shift($_SERVER['argv']);
+ * $frontend->run($_SERVER['argv']);
+ */
+__HALT_COMPILER();

0 comments on commit 9e63c04

Please sign in to comment.