diff --git a/composer.json b/composer.json index 7ca19ff..a94c5d0 100644 --- a/composer.json +++ b/composer.json @@ -22,8 +22,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.4-dev", - "dev-develop": "2.5-dev" + "dev-master": "2.1-dev", + "dev-develop": "2.2-dev" } }, "autoload-dev": { diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 53d3285..ea1ddb8 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Adapter; @@ -13,11 +12,6 @@ use Zend\Console\Charset; use Zend\Console\Exception; -/** - * @category Zend - * @package Zend_Console - * @subpackage Adapter - */ abstract class AbstractAdapter implements AdapterInterface { /** diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index e823740..2b9e320 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -5,17 +5,12 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Adapter; use Zend\Console\Charset\CharsetInterface; -/** - * @category Zend - * @package Zend_Console - */ interface AdapterInterface { const LINE_NONE = 1; diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 4b9205e..d3e6f5c 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -5,20 +5,18 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Adapter; +use ReflectionClass; use Zend\Console\Charset; use Zend\Console\Exception; +use Zend\Console\Color\Xterm256; use Zend\Console\ColorInterface as Color; /** * @todo Add GNU readline support - * @category Zend - * @package Zend_Console - * @subpackage Adapter * @link http://en.wikipedia.org/wiki/ANSI_escape_code */ class Posix extends AbstractAdapter @@ -38,7 +36,6 @@ class Posix extends AbstractAdapter /** * Map of colors to ANSI codes * - * @todo implement Xterm 256 colors (http://www.frexx.de/xterm-256-notes/) * @var array */ protected static $ansiColorMap = array( @@ -218,28 +215,9 @@ public function setPos($x, $y) */ public function colorize($string, $color = null, $bgColor = null) { - // Retrieve ansi color codes - if ($color !== null) { - if (!isset(static::$ansiColorMap['fg'][$color])) { - throw new Exception\BadMethodCallException(sprintf( - 'Unknown color "%s". Please use one of the Zend\Console\ColorInterface constants', - $color - )); - } - $color = static::$ansiColorMap['fg'][$color]; - } - - if ($bgColor !== null) { - if (!isset(static::$ansiColorMap['bg'][$bgColor])) { - throw new Exception\BadMethodCallException(sprintf( - 'Unknown color "%s". Please use one of the Zend\Console\ColorInterface constants', - $bgColor - )); - } - $bgColor = static::$ansiColorMap['bg'][$bgColor]; - } - - return ($color !== null ? "\x1b[" . $color . 'm' : '') + $color = $this->getColorCode($color, 'fg'); + $bgColor = $this->getColorCode($bgColor, 'bg'); + return ($color !== null ? "\x1b[" . $color . 'm' : '') . ($bgColor !== null ? "\x1b[" . $bgColor . 'm' : '') . $string . "\x1b[22;39m\x1b[0;49m"; @@ -253,17 +231,7 @@ public function colorize($string, $color = null, $bgColor = null) */ public function setColor($color) { - // Retrieve ansi color code - if ($color !== null) { - if (!isset(static::$ansiColorMap['fg'][$color])) { - throw new Exception\BadMethodCallException(sprintf( - 'Unknown color "%s". Please use one of the Zend\Console\ColorInterface constants', - $color - )); - } - $color = static::$ansiColorMap['fg'][$color]; - } - + $color = $this->getColorCode($color, 'fg'); echo "\x1b[" . $color . 'm'; } @@ -275,18 +243,7 @@ public function setColor($color) */ public function setBgColor($bgColor) { - // Retrieve ansi color code - if ($bgColor !== null) { - if (!isset(static::$ansiColorMap['bg'][$bgColor])) { - throw new Exception\BadMethodCallException(sprintf( - 'Unknown color "%s". Please use one of the Zend\Console\ColorInterface constants', - $bgColor - )); - } - - $bgColor = static::$ansiColorMap['bg'][$bgColor]; - } - + $bgColor = $this->getColorCode($bgColor, 'bg'); echo "\x1b[" . ($bgColor) . 'm'; } @@ -402,4 +359,38 @@ protected function setTTYMode($mode) // Set new mode shell_exec('stty '.escapeshellcmd($mode)); } + + /** + * Get the final color code and throw exception on error + * + * @param null|int|Xterm256 $color + * @throws Exception\BadMethodCallException + * @return string + */ + protected function getColorCode($color, $type = 'fg') + { + if ($color instanceof Xterm256) { + $r = new ReflectionClass($color); + $code = $r->getStaticPropertyValue('color'); + if ($type == 'fg') { + $code = sprintf($code, $color::FOREGROUND); + } else { + $code = sprintf($code, $color::BACKGROUND); + } + return $code; + } + + if ($color !== null) { + if (!isset(static::$ansiColorMap[$type][$color])) { + throw new Exception\BadMethodCallException(sprintf( + 'Unknown color "%s". Please use one of the Zend\Console\ColorInterface constants or use Zend\Console\Color\Xterm256::calculate', + $color + )); + } + + return static::$ansiColorMap[$type][$color]; + } + + return null; + } } diff --git a/src/Adapter/Virtual.php b/src/Adapter/Virtual.php index aa09ab6..3f25a1c 100644 --- a/src/Adapter/Virtual.php +++ b/src/Adapter/Virtual.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Adapter; @@ -14,10 +13,6 @@ /** * Virtual buffer adapter - * - * @category Zend - * @package Zend_Console - * @subpackage Adapter */ class Virtual extends AbstractAdapter { diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index 074cfcd..7f40a35 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Adapter; @@ -13,11 +12,6 @@ use Zend\Console\Charset; use Zend\Console\Exception; -/** - * @category Zend - * @package Zend_Console - * @subpackage Adapter - */ class Windows extends Virtual { /** diff --git a/src/Adapter/WindowsAnsicon.php b/src/Adapter/WindowsAnsicon.php index 761b72e..b487505 100644 --- a/src/Adapter/WindowsAnsicon.php +++ b/src/Adapter/WindowsAnsicon.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Adapter; @@ -27,10 +26,6 @@ * Console should not run in UTF8 code page (65001), because ANSICON does not behave well with it. * It's best to use non-unicode code page 437, 850, 851, 852 or similar. Run "help mode" for more * information on how to change Windows console code page. - * - * @category Zend - * @package Zend_Console - * @subpackage Adapter */ class WindowsAnsicon extends Posix { diff --git a/src/Charset/Ascii.php b/src/Charset/Ascii.php index 77796e8..4bda285 100644 --- a/src/Charset/Ascii.php +++ b/src/Charset/Ascii.php @@ -5,17 +5,12 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Charset; /** * Basic (low) ASCII line drawing characters. - * - * @category Zend - * @package Zend_Console - * @subpackage Charset */ class Ascii implements CharsetInterface { diff --git a/src/Charset/AsciiExtended.php b/src/Charset/AsciiExtended.php index 81a5e90..8561d71 100644 --- a/src/Charset/AsciiExtended.php +++ b/src/Charset/AsciiExtended.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Charset; @@ -14,9 +13,6 @@ * Extended ASCII character set (positions 127+, MS DOS & Windows compatible) * * @link http://en.wikipedia.org/wiki/Box-drawing_characters - * @category Zend - * @package Zend_Console - * @subpackage Charset */ class AsciiExtended implements CharsetInterface { diff --git a/src/Charset/CharsetInterface.php b/src/Charset/CharsetInterface.php index 246d8cb..138f642 100644 --- a/src/Charset/CharsetInterface.php +++ b/src/Charset/CharsetInterface.php @@ -5,15 +5,10 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Charset; -/** - * @category Zend - * @package Zend_Console - */ interface CharsetInterface { } diff --git a/src/Charset/DECSG.php b/src/Charset/DECSG.php index d829ec7..038809a 100644 --- a/src/Charset/DECSG.php +++ b/src/Charset/DECSG.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Charset; @@ -14,9 +13,6 @@ * DEC Special Graphics (VT100 line drawing) character set * * @link http://vt100.net/docs/vt220-rm/table2-4.html - * @category Zend - * @package Zend_Console - * @subpackage Charset */ class DECSG implements CharsetInterface { diff --git a/src/Charset/Utf8.php b/src/Charset/Utf8.php index dd88274..634e7b4 100644 --- a/src/Charset/Utf8.php +++ b/src/Charset/Utf8.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Charset; @@ -14,9 +13,6 @@ * UTF-8 box drawing * * @link http://en.wikipedia.org/wiki/Box-drawing_characters - * @category Zend - * @package Zend_Console - * @subpackage Charset */ class Utf8 implements CharsetInterface { diff --git a/src/Charset/Utf8Heavy.php b/src/Charset/Utf8Heavy.php index 4c41456..cad5ac7 100644 --- a/src/Charset/Utf8Heavy.php +++ b/src/Charset/Utf8Heavy.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Charset; @@ -14,9 +13,6 @@ * UTF-8 box drawing (modified to use heavy single lines) * * @link http://en.wikipedia.org/wiki/Box-drawing_characters - * @category Zend - * @package Zend_Console - * @subpackage Charset */ class Utf8Heavy extends Utf8 { diff --git a/src/Color/Xterm256.php b/src/Color/Xterm256.php new file mode 100644 index 0000000..f2b5ae6 --- /dev/null +++ b/src/Color/Xterm256.php @@ -0,0 +1,70 @@ + 0 ? (int) $val : 0; + }, $hex); + + $dhex = array_map('hexdec', $hex); + + if (array_fill(0, 3, $dhex[0]) === $dhex && (int) substr($dhex[0], -1) === 8) { + $x11 = 232 + (int) floor($dhex[0]/10); + return new static($x11); + } + + $x11 = $ahex[0] * 36 + $ahex[1] * 6 + $ahex[2] + 16; + + return new static($x11); + } +} diff --git a/src/ColorInterface.php b/src/ColorInterface.php index 8629d85..fa5d321 100644 --- a/src/ColorInterface.php +++ b/src/ColorInterface.php @@ -5,15 +5,10 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console; -/** - * @category Zend - * @package Zend_Console - */ interface ColorInterface { const NORMAL = 0; diff --git a/src/Console.php b/src/Console.php index 8199429..7389e60 100644 --- a/src/Console.php +++ b/src/Console.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console; @@ -13,9 +12,6 @@ /** * An static, utility class for interacting with Console environment. * Declared abstract to prevent from instantiating. - * - * @category Zend - * @package Zend_Console */ abstract class Console { diff --git a/src/Exception/BadMethodCallException.php b/src/Exception/BadMethodCallException.php index 6ad6dc2..f95109c 100644 --- a/src/Exception/BadMethodCallException.php +++ b/src/Exception/BadMethodCallException.php @@ -5,16 +5,10 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Exception; -/** - * @category Zend - * @package Zend_Console - * @subpackage Exception - */ class BadMethodCallException extends \BadMethodCallException implements ExceptionInterface { diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index 301c316..b0893dd 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -5,16 +5,10 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Exception; -/** - * @category Zend - * @package Zend_Console - * @subpackage Exception - */ interface ExceptionInterface { } diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 6fc8d8e..3380d5c 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -5,16 +5,10 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Exception; -/** - * @category Zend - * @package Zend_Console - * @subpackage Exception - */ class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface { } diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index 842f5b7..21e2771 100644 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -5,16 +5,10 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Exception; -/** - * @category Zend - * @package Zend_Console - * @subpackage Exception - */ class RuntimeException extends \RuntimeException implements ExceptionInterface { /** diff --git a/src/Getopt.php b/src/Getopt.php index aa1a644..e7de857 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console; @@ -68,11 +67,6 @@ * Example: 'abc:' means options '-a', '-b', and '-c' * are legal, and the latter requires a string parameter. * - * @category Zend - * @package Zend_Console_Getopt - * @version Release: @package_version@ - * @since Class available since Release 0.6.0 - * * @todo Handle flags that implicitly print usage message, e.g. --help * * @todo Enable user to specify header and footer content in the help message. diff --git a/src/Prompt/AbstractPrompt.php b/src/Prompt/AbstractPrompt.php index be4b31c..1b67525 100644 --- a/src/Prompt/AbstractPrompt.php +++ b/src/Prompt/AbstractPrompt.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Prompt; @@ -15,11 +14,6 @@ use Zend\Console\Adapter\AdapterInterface as ConsoleAdapter; use Zend\Console\Exception; -/** - * @category Zend - * @package Zend_Console - * @subpackage Prompt - */ abstract class AbstractPrompt implements PromptInterface { /** @@ -32,13 +26,6 @@ abstract class AbstractPrompt implements PromptInterface */ protected $lastResponse; - /** - * Show a prompt - * - * @return void - */ - abstract public function show(); - /** * Return last answer to this prompt. * diff --git a/src/Prompt/Char.php b/src/Prompt/Char.php index 82afde3..b49b21e 100644 --- a/src/Prompt/Char.php +++ b/src/Prompt/Char.php @@ -5,16 +5,10 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Prompt; -/** - * @category Zend - * @package Zend_Console - * @subpackage Prompt - */ class Char extends AbstractPrompt { /** diff --git a/src/Prompt/Confirm.php b/src/Prompt/Confirm.php index 2c8599e..65a8a05 100644 --- a/src/Prompt/Confirm.php +++ b/src/Prompt/Confirm.php @@ -5,16 +5,10 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Prompt; -/** - * @category Zend - * @package Zend_Console - * @subpackage Prompt - */ class Confirm extends Char { /** diff --git a/src/Prompt/Line.php b/src/Prompt/Line.php index e46d5b2..45a885a 100644 --- a/src/Prompt/Line.php +++ b/src/Prompt/Line.php @@ -5,16 +5,10 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Prompt; -/** - * @category Zend - * @package Zend_Console - * @subpackage Prompt - */ class Line extends AbstractPrompt { /** diff --git a/src/Prompt/Number.php b/src/Prompt/Number.php index 235173e..c5e2f6e 100644 --- a/src/Prompt/Number.php +++ b/src/Prompt/Number.php @@ -5,16 +5,10 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Prompt; -/** - * @category Zend - * @package Zend_Console - * @subpackage Prompt - */ class Number extends Line { /** diff --git a/src/Prompt/PromptInterface.php b/src/Prompt/PromptInterface.php index f383c8f..4f1ece4 100644 --- a/src/Prompt/PromptInterface.php +++ b/src/Prompt/PromptInterface.php @@ -5,17 +5,12 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Prompt; use Zend\Console\Adapter\AdapterInterface as ConsoleAdapter; -/** - * @category Zend - * @package Zend_Console - */ interface PromptInterface { /** diff --git a/src/Prompt/Select.php b/src/Prompt/Select.php index 73acb11..6eb5e42 100644 --- a/src/Prompt/Select.php +++ b/src/Prompt/Select.php @@ -5,18 +5,12 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console\Prompt; use Zend\Console\Exception; -/** - * @category Zend - * @package Zend_Console - * @subpackage Prompt - */ class Select extends Char { /** diff --git a/src/Request.php b/src/Request.php index 029c093..84ecab7 100644 --- a/src/Request.php +++ b/src/Request.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console; @@ -14,10 +13,6 @@ use Zend\Stdlib\Parameters; use Zend\Stdlib\RequestInterface; -/** - * @category Zend - * @package Zend_Console - */ class Request extends Message implements RequestInterface { /** diff --git a/src/Response.php b/src/Response.php index 3717ca3..50426c1 100644 --- a/src/Response.php +++ b/src/Response.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Console */ namespace Zend\Console; @@ -13,14 +12,20 @@ use Zend\Stdlib\Message; use Zend\Stdlib\ResponseInterface; -/** - * @category Zend - * @package Zend_Console - */ class Response extends Message implements ResponseInterface { + + /** + * @var bool + */ protected $contentSent = false; + /** + * Check if content was sent + * + * @return bool + * @deprecated + */ public function contentSent() { return $this->contentSent; @@ -48,6 +53,12 @@ public function getErrorLevel() return $this->getMetadata('errorLevel', 0); } + /** + * Send content + * + * @return Response + * @deprecated + */ public function sendContent() { if ($this->contentSent()) { @@ -58,10 +69,14 @@ public function sendContent() return $this; } + /** + * @deprecated + */ public function send() { $this->sendContent(); $errorLevel = (int) $this->getMetadata('errorLevel',0); exit($errorLevel); } + } diff --git a/test/Xterm256Test.php b/test/Xterm256Test.php new file mode 100644 index 0000000..4dacc9a --- /dev/null +++ b/test/Xterm256Test.php @@ -0,0 +1,322 @@ + array('FFFFFF0'), + 'too-long-and-char-out-of-range' => array('ABCDEFG'), + 'too-long-digits' => array('01048212'), + 'too-long-and-invalid-enc' => array('ééààööüü'), + 'char-out-of-range' => array('FF00GG'), + 'null' => array(null), + ); + } + + /** + * @dataProvider invalidHexCodes + */ + public function testWrongHexCodeInputs($hex) + { + $color = Xterm256::calculate($hex); + $r = new ReflectionClass($color); + $code = $r->getStaticPropertyValue('color'); + $this->assertNull($code); + } + + public function approximateHexCodes() + { + return array( + 'sixteen' => array('000100', 16), + 'one-ninety-nine' => array('FF33A0', 199), + ); + } + + /** + * @dataProvider approximateHexCodes + */ + public function testApproximateHexCodeInputs($hex, $gcode) + { + $color = Xterm256::calculate($hex); + $r = new ReflectionClass($color); + $gcode = sprintf('%%s;5;%s', $gcode); + $this->assertEquals($gcode, $r->getStaticPropertyValue('color')); + } + + public function exactHexCodes() + { + return array( + '000000' => array('000000', 16), + '00005F' => array('00005F', 17), + '000087' => array('000087', 18), + '0000AF' => array('0000AF', 19), + '0000D7' => array('0000D7', 20), + '0000FF' => array('0000FF', 21), + '005F00' => array('005F00', 22), + '005F5F' => array('005F5F', 23), + '005F87' => array('005F87', 24), + '005FAF' => array('005FAF', 25), + '005FD7' => array('005FD7', 26), + '005FFF' => array('005FFF', 27), + '008700' => array('008700', 28), + '00875F' => array('00875F', 29), + '008787' => array('008787', 30), + '0087AF' => array('0087AF', 31), + '0087D7' => array('0087D7', 32), + '0087FF' => array('0087FF', 33), + '00AF00' => array('00AF00', 34), + '00AF5F' => array('00AF5F', 35), + '00AF87' => array('00AF87', 36), + '00AFAF' => array('00AFAF', 37), + '00AFD7' => array('00AFD7', 38), + '00AFFF' => array('00AFFF', 39), + '00D700' => array('00D700', 40), + '00D75F' => array('00D75F', 41), + '00D787' => array('00D787', 42), + '00D7AF' => array('00D7AF', 43), + '00D7D7' => array('00D7D7', 44), + '00D7FF' => array('00D7FF', 45), + '00FF00' => array('00FF00', 46), + '00FF5F' => array('00FF5F', 47), + '00FF87' => array('00FF87', 48), + '00FFAF' => array('00FFAF', 49), + '00FFD7' => array('00FFD7', 50), + '00FFFF' => array('00FFFF', 51), + '5F0000' => array('5F0000', 52), + '5F005F' => array('5F005F', 53), + '5F0087' => array('5F0087', 54), + '5F00AF' => array('5F00AF', 55), + '5F00D7' => array('5F00D7', 56), + '5F00FF' => array('5F00FF', 57), + '5F5F00' => array('5F5F00', 58), + '5F5F5F' => array('5F5F5F', 59), + '5F5F87' => array('5F5F87', 60), + '5F5FAF' => array('5F5FAF', 61), + '5F5FD7' => array('5F5FD7', 62), + '5F5FFF' => array('5F5FFF', 63), + '5F8700' => array('5F8700', 64), + '5F875F' => array('5F875F', 65), + '5F8787' => array('5F8787', 66), + '5F87AF' => array('5F87AF', 67), + '5F87D7' => array('5F87D7', 68), + '5F87FF' => array('5F87FF', 69), + '5FAF00' => array('5FAF00', 70), + '5FAF5F' => array('5FAF5F', 71), + '5FAF87' => array('5FAF87', 72), + '5FAFAF' => array('5FAFAF', 73), + '5FAFD7' => array('5FAFD7', 74), + '5FAFFF' => array('5FAFFF', 75), + '5FD700' => array('5FD700', 76), + '5FD75F' => array('5FD75F', 77), + '5FD787' => array('5FD787', 78), + '5FD7AF' => array('5FD7AF', 79), + '5FD7D7' => array('5FD7D7', 80), + '5FD7FF' => array('5FD7FF', 81), + '5FFF00' => array('5FFF00', 82), + '5FFF5F' => array('5FFF5F', 83), + '5FFF87' => array('5FFF87', 84), + '5FFFAF' => array('5FFFAF', 85), + '5FFFD7' => array('5FFFD7', 86), + '5FFFFF' => array('5FFFFF', 87), + '870000' => array('870000', 88), + '87005F' => array('87005F', 89), + '870087' => array('870087', 90), + '8700AF' => array('8700AF', 91), + '8700D7' => array('8700D7', 92), + '8700FF' => array('8700FF', 93), + '875F00' => array('875F00', 94), + '875F5F' => array('875F5F', 95), + '875F87' => array('875F87', 96), + '875FAF' => array('875FAF', 97), + '875FD7' => array('875FD7', 98), + '875FFF' => array('875FFF', 99), + '878700' => array('878700', 100), + '87875F' => array('87875F', 101), + '878787' => array('878787', 102), + '8787AF' => array('8787AF', 103), + '8787D7' => array('8787D7', 104), + '8787FF' => array('8787FF', 105), + '87AF00' => array('87AF00', 106), + '87AF5F' => array('87AF5F', 107), + '87AF87' => array('87AF87', 108), + '87AFAF' => array('87AFAF', 109), + '87AFD7' => array('87AFD7', 110), + '87AFFF' => array('87AFFF', 111), + '87D700' => array('87D700', 112), + '87D75F' => array('87D75F', 113), + '87D787' => array('87D787', 114), + '87D7AF' => array('87D7AF', 115), + '87D7D7' => array('87D7D7', 116), + '87D7FF' => array('87D7FF', 117), + '87FF00' => array('87FF00', 118), + '87FF5F' => array('87FF5F', 119), + '87FF87' => array('87FF87', 120), + '87FFAF' => array('87FFAF', 121), + '87FFD7' => array('87FFD7', 122), + '87FFFF' => array('87FFFF', 123), + 'AF0000' => array('AF0000', 124), + 'AF005F' => array('AF005F', 125), + 'AF0087' => array('AF0087', 126), + 'AF00AF' => array('AF00AF', 127), + 'AF00D7' => array('AF00D7', 128), + 'AF00FF' => array('AF00FF', 129), + 'AF5F00' => array('AF5F00', 130), + 'AF5F5F' => array('AF5F5F', 131), + 'AF5F87' => array('AF5F87', 132), + 'AF5FAF' => array('AF5FAF', 133), + 'AF5FD7' => array('AF5FD7', 134), + 'AF5FFF' => array('AF5FFF', 135), + 'AF8700' => array('AF8700', 136), + 'AF875F' => array('AF875F', 137), + 'AF8787' => array('AF8787', 138), + 'AF87AF' => array('AF87AF', 139), + 'AF87D7' => array('AF87D7', 140), + 'AF87FF' => array('AF87FF', 141), + 'AFAF00' => array('AFAF00', 142), + 'AFAF5F' => array('AFAF5F', 143), + 'AFAF87' => array('AFAF87', 144), + 'AFAFAF' => array('AFAFAF', 145), + 'AFAFD7' => array('AFAFD7', 146), + 'AFAFFF' => array('AFAFFF', 147), + 'AFD700' => array('AFD700', 148), + 'AFD75F' => array('AFD75F', 149), + 'AFD787' => array('AFD787', 150), + 'AFD7AF' => array('AFD7AF', 151), + 'AFD7D7' => array('AFD7D7', 152), + 'AFD7FF' => array('AFD7FF', 153), + 'AFFF00' => array('AFFF00', 154), + 'AFFF5F' => array('AFFF5F', 155), + 'AFFF87' => array('AFFF87', 156), + 'AFFFAF' => array('AFFFAF', 157), + 'AFFFD7' => array('AFFFD7', 158), + 'AFFFFF' => array('AFFFFF', 159), + 'D70000' => array('D70000', 160), + 'D7005F' => array('D7005F', 161), + 'D70087' => array('D70087', 162), + 'D700AF' => array('D700AF', 163), + 'D700D7' => array('D700D7', 164), + 'D700FF' => array('D700FF', 165), + 'D75F00' => array('D75F00', 166), + 'D75F5F' => array('D75F5F', 167), + 'D75F87' => array('D75F87', 168), + 'D75FAF' => array('D75FAF', 169), + 'D75FD7' => array('D75FD7', 170), + 'D75FFF' => array('D75FFF', 171), + 'D78700' => array('D78700', 172), + 'D7875F' => array('D7875F', 173), + 'D78787' => array('D78787', 174), + 'D787AF' => array('D787AF', 175), + 'D787D7' => array('D787D7', 176), + 'D787FF' => array('D787FF', 177), + 'D7AF00' => array('D7AF00', 178), + 'D7AF5F' => array('D7AF5F', 179), + 'D7AF87' => array('D7AF87', 180), + 'D7AFAF' => array('D7AFAF', 181), + 'D7AFD7' => array('D7AFD7', 182), + 'D7AFFF' => array('D7AFFF', 183), + 'D7D700' => array('D7D700', 184), + 'D7D75F' => array('D7D75F', 185), + 'D7D787' => array('D7D787', 186), + 'D7D7AF' => array('D7D7AF', 187), + 'D7D7D7' => array('D7D7D7', 188), + 'D7D7FF' => array('D7D7FF', 189), + 'D7FF00' => array('D7FF00', 190), + 'D7FF5F' => array('D7FF5F', 191), + 'D7FF87' => array('D7FF87', 192), + 'D7FFAF' => array('D7FFAF', 193), + 'D7FFD7' => array('D7FFD7', 194), + 'D7FFFF' => array('D7FFFF', 195), + 'FF0000' => array('FF0000', 196), + 'FF005F' => array('FF005F', 197), + 'FF0087' => array('FF0087', 198), + 'FF00AF' => array('FF00AF', 199), + 'FF00D7' => array('FF00D7', 200), + 'FF00FF' => array('FF00FF', 201), + 'FF5F00' => array('FF5F00', 202), + 'FF5F5F' => array('FF5F5F', 203), + 'FF5F87' => array('FF5F87', 204), + 'FF5FAF' => array('FF5FAF', 205), + 'FF5FD7' => array('FF5FD7', 206), + 'FF5FFF' => array('FF5FFF', 207), + 'FF8700' => array('FF8700', 208), + 'FF875F' => array('FF875F', 209), + 'FF8787' => array('FF8787', 210), + 'FF87AF' => array('FF87AF', 211), + 'FF87D7' => array('FF87D7', 212), + 'FF87FF' => array('FF87FF', 213), + 'FFAF00' => array('FFAF00', 214), + 'FFAF5F' => array('FFAF5F', 215), + 'FFAF87' => array('FFAF87', 216), + 'FFAFAF' => array('FFAFAF', 217), + 'FFAFD7' => array('FFAFD7', 218), + 'FFAFFF' => array('FFAFFF', 219), + 'FFD700' => array('FFD700', 220), + 'FFD75F' => array('FFD75F', 221), + 'FFD787' => array('FFD787', 222), + 'FFD7AF' => array('FFD7AF', 223), + 'FFD7D7' => array('FFD7D7', 224), + 'FFD7FF' => array('FFD7FF', 225), + 'FFFF00' => array('FFFF00', 226), + 'FFFF5F' => array('FFFF5F', 227), + 'FFFF87' => array('FFFF87', 228), + 'FFFFAF' => array('FFFFAF', 229), + 'FFFFD7' => array('FFFFD7', 230), + 'FFFFFF' => array('FFFFFF', 231), + '080808' => array('080808', 232), + '121212' => array('121212', 233), + '1C1C1C' => array('1C1C1C', 234), + '262626' => array('262626', 235), + '303030' => array('303030', 236), + '3A3A3A' => array('3A3A3A', 237), + '444444' => array('444444', 238), + '4E4E4E' => array('4E4E4E', 239), + '585858' => array('585858', 240), + '626262' => array('626262', 241), + '6C6C6C' => array('6C6C6C', 242), + '767676' => array('767676', 243), + '808080' => array('808080', 244), + '8A8A8A' => array('8A8A8A', 245), + '949494' => array('949494', 246), + '9E9E9E' => array('9E9E9E', 247), + 'A8A8A8' => array('A8A8A8', 248), + 'B2B2B2' => array('B2B2B2', 249), + 'BCBCBC' => array('BCBCBC', 250), + 'C6C6C6' => array('C6C6C6', 251), + 'D0D0D0' => array('D0D0D0', 252), + 'DADADA' => array('DADADA', 253), + 'E4E4E4' => array('E4E4E4', 254), + 'EEEEEE' => array('EEEEEE', 255), + ); + } + + /** + * @dataProvider exactHexCodes + */ + public function testExactHexCodeInputs($hex, $gcode) + { + $color = Xterm256::calculate($hex); + $r = new ReflectionClass($color); + $gcode = sprintf('%%s;5;%s', $gcode); + $this->assertEquals($gcode, $r->getStaticPropertyValue('color')); + } +}