Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove

  • Loading branch information...
commit d1d20e367b1edb0cd5f1cdacac4eeaf340c9e60e 1 parent 467044a
@CloCkWeRX CloCkWeRX authored
View
140 Color.php → Console/Color2.php
@@ -2,7 +2,7 @@
/**
* Color.php
*
- * PHP version 4
+ * PHP version 5
*
* Copyright (c) 2007 Stefan Walk
*
@@ -25,49 +25,13 @@
* IN THE SOFTWARE.
*
* @category Console
- * @package Console_Color
+ * @package Console_Color2
* @author Stefan Walk <et@php.net>
* @license http://www.opensource.org/licenses/mit-license.php MIT License
- * @link http://pear.php.net/package/Console_Color
+ * @link http://pear.php.net/package/Console_Color2
*/
-$GLOBALS['_CONSOLE_COLOR_CODES'] = array (
- 'color' => array(
- 'black' => 30,
- 'red' => 31,
- 'green' => 32,
- 'brown' => 33,
- 'blue' => 34,
- 'purple' => 35,
- 'cyan' => 36,
- 'grey' => 37,
- 'yellow' => 33
- ),
- 'style' => array(
- 'normal' => 0,
- 'bold' => 1,
- 'light' => 1,
- 'underscore' => 4,
- 'underline' => 4,
- 'blink' => 5,
- 'inverse' => 6,
- 'hidden' => 8,
- 'concealed' => 8
- ),
- 'background' => array(
- 'black' => 40,
- 'red' => 41,
- 'green' => 42,
- 'brown' => 43,
- 'yellow' => 43,
- 'blue' => 44,
- 'purple' => 45,
- 'cyan' => 46,
- 'grey' => 47
- )
-);
-
/**
* A simple class to use ANSI Colorcodes.
@@ -82,9 +46,60 @@
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @link http://pear.php.net/package/Console_Color
*/
-class Console_Color
+class Console_Color2
{
+ protected $color_codes;
+
+ public function __construct() {
+ $this->setColorCodes(array(
+ 'color' => array(
+ 'black' => 30,
+ 'red' => 31,
+ 'green' => 32,
+ 'brown' => 33,
+ 'blue' => 34,
+ 'purple' => 35,
+ 'cyan' => 36,
+ 'grey' => 37,
+ 'yellow' => 33
+ ),
+ 'style' => array(
+ 'normal' => 0,
+ 'bold' => 1,
+ 'light' => 1,
+ 'underscore' => 4,
+ 'underline' => 4,
+ 'blink' => 5,
+ 'inverse' => 6,
+ 'hidden' => 8,
+ 'concealed' => 8
+ ),
+ 'background' => array(
+ 'black' => 40,
+ 'red' => 41,
+ 'green' => 42,
+ 'brown' => 43,
+ 'yellow' => 43,
+ 'blue' => 44,
+ 'purple' => 45,
+ 'cyan' => 46,
+ 'grey' => 47
+ )
+ )
+ );
+ }
+
+ public function setColorCodes($color_codes)
+ {
+ $this->color_codes = $color_codes;
+ }
+
+ public function getColorCodes()
+ {
+ return $this->color_codes;
+ }
+
/**
* Returns an ANSI-Controlcode
*
@@ -100,16 +115,15 @@ class Console_Color
* @param string $style Optional name of the style
* @param string $background Optional name of the background color
*
- * @access public
* @return string
*/
- function color($color = null, $style = null, $background = null) // {{{
+ public function color($color = null, $style = null, $background = null) // {{{
{
- $colors = &$GLOBALS['_CONSOLE_COLOR_CODES'];
+ $colors = $this->getColorCodes();
if (is_array($color)) {
- $style = @$color['style'];
- $background = @$color['background'];
- $color = @$color['color'];
+ $style = $color['style'];
+ $background = $color['background'];
+ $color = $color['color'];
}
if ($color == 'reset') {
@@ -142,12 +156,12 @@ function color($color = null, $style = null, $background = null) // {{{
*
* @param string $name Name of controlcode
*
- * @access public
* @return string
*/
- function fgcolor($name)
+ public function fgcolor($name)
{
- $colors = &$GLOBALS['_CONSOLE_COLOR_CODES'];
+ $colors = $this->getColorCodes();
+
return "\033[".$colors['color'][$name].'m';
}
@@ -156,26 +170,11 @@ function fgcolor($name)
*
* @param string $name Name of controlcode
*
- * @access public
- * @return string
- */
- function style($name)
- {
- $colors = &$GLOBALS['_CONSOLE_COLOR_CODES'];
- return "\033[".$colors['style'][$name].'m';
- }
-
- /**
- * Returns a BG color controlcode
- *
- * @param string $name Name of controlcode
- *
- * @access public
* @return string
*/
function bgcolor($name)
{
- $colors = &$GLOBALS['_CONSOLE_COLOR_CODES'];
+ $colors = $this->getColorCodes();
return "\033[".$colors['background'][$name].'m';
}
@@ -211,10 +210,9 @@ function bgcolor($name)
* @param string $string String to convert
* @param bool $colored Should the string be colored?
*
- * @access public
* @return string
*/
- function convert($string, $colored = true)
+ public function convert($string, $colored = true)
{
static $conversions = array ( // static so the array doesn't get built
// everytime
@@ -259,7 +257,7 @@ function convert($string, $colored = true)
if ($colored) {
$string = str_replace('%%', '% ', $string);
foreach ($conversions as $key => $value) {
- $string = str_replace($key, Console_Color::color($value),
+ $string = str_replace($key, $this->color($value),
$string);
}
$string = str_replace('% ', '%', $string);
@@ -276,10 +274,9 @@ function convert($string, $colored = true)
*
* @param string $string String to escape
*
- * @access public
* @return string
*/
- function escape($string)
+ public function escape($string)
{
return str_replace('%', '%%', $string);
}
@@ -292,10 +289,9 @@ function escape($string)
* @acess public
* @return string
*/
- function strip($string)
+ public function strip($string)
{
return preg_replace('/\033\[[\d;]+m/', '', $string);
}
}
-?>
View
19 examples/color_example.php
@@ -1,22 +1,21 @@
<?php
-require 'Console/Color.php';
+require 'Console/Color2.php';
+
+$color = new Console_Color2();
-error_reporting(E_ALL);
// Let's add a little color to the world
// %n resets the color so the following stuff doesn't get messed up
-print Console_Color::convert("%bHello World!%n\n");
+print $color->convert("%bHello World!%n\n");
// Colorless mode, in case you need to strip colorcodes off a text
-print Console_Color::convert("%rHello World!%n\n", false);
+print $color->convert("%rHello World!%n\n", false);
// The uppercase version makes a colorcode bold/bright
-print Console_Color::convert("%BHello World!%n\n");
+print $color->convert("%BHello World!%n\n");
// To print a %, you use %%
-print Console_Color::convert("3 out of 4 people make up about %r75%% %nof the "
+print $color->convert("3 out of 4 people make up about %r75%% %nof the "
."world population.\n");
// Or you can use the escape() method.
-print Console_Color::convert("%y"
- .Console_Color::escape('If you feel that you do everying wrong, be random'
+print $color->convert("%y"
+ .$color->escape('If you feel that you do everying wrong, be random'
.', there\'s a 50% Chance of making the right '
.'decision.')."%n\n");
-?>
-
View
35 package.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.9.1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" 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.0 http://pear.php.net/dtd/package-2.0.xsd">
+<package packagerversion="1.9.4" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" 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.0 http://pear.php.net/dtd/package-2.0.xsd">
<name>Console_Color</name>
<channel>pear.php.net</channel>
<summary>This Class allows you to easily use ANSI console colors in your application.</summary>
@@ -18,11 +18,11 @@ control codes. print Console_Color::convert(&quot;%rHello World!%n&quot;); would
<email>scottmattocks@php.net</email>
<active>yes</active>
</lead>
- <date>2010-10-25</date>
- <time>20:09:26</time>
+ <date>2011-12-18</date>
+ <time>18:36:56</time>
<version>
- <release>1.0.3</release>
- <api>1.0.0</api>
+ <release>0.1.0</release>
+ <api>0.1.0</api>
</version>
<stability>
<release>stable</release>
@@ -30,17 +30,15 @@ control codes. print Console_Color::convert(&quot;%rHello World!%n&quot;); would
</stability>
<license uri="http://www.opensource.org/licenses/mit-license.php">MIT</license>
<notes>
-QA release
-Doc Bug #9948 License file not included in tarball
-Request #14785 Improve PHPCS results
-SVN dir layout
+PHP5 syntax
</notes>
<contents>
<dir baseinstalldir="/" name="/">
- <file baseinstalldir="Console" md5sum="ded272b8ea930a3d361476b696b0ac4b" name="examples/color_example.php" role="doc" />
+ <file baseinstalldir="/" md5sum="68d09798545466f4cf2152e710623934" name="Console/Color2.php" role="php" />
+ <file baseinstalldir="Console" md5sum="04c232aa258bd5c8d14b2a370fcd1292" name="examples/color_example.php" role="doc" />
<file baseinstalldir="Console" md5sum="32593f1641504e01f9fb6df55c1c5478" name="examples/documentation" role="doc" />
- <file baseinstalldir="Console" md5sum="587fea16d168de58e6e47a7d05cfb5f0" name="Color.php" role="php" />
<file baseinstalldir="Console" md5sum="386286831b7c47adae39ddfb51d483ab" name="LICENSE" role="doc" />
+ <file baseinstalldir="/" md5sum="ea4ee09f74764a34fc99e6da91a06c62" name="README" role="data" />
</dir>
</contents>
<dependencies>
@@ -118,5 +116,20 @@ Request #14785 Improve PHPCS results
SVN dir layout
</notes>
</release>
+ <release>
+ <version>
+ <release>0.1.0</release>
+ <api>0.1.0</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <date>2011-12-18</date>
+ <license uri="http://www.opensource.org/licenses/mit-license.php">MIT</license>
+ <notes>
+PHP5 syntax
+ </notes>
+ </release>
</changelog>
</package>
Please sign in to comment.
Something went wrong with that request. Please try again.