Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 30 changed files with 453 additions and 198 deletions.
6 changes: 0 additions & 6 deletions src/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@
* @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;
use Zend\Console\Exception;

/**
* @category Zend
* @package Zend_Console
* @subpackage Adapter
*/
abstract class AbstractAdapter implements AdapterInterface
{
/**
Expand Down
5 changes: 0 additions & 5 deletions src/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
91 changes: 41 additions & 50 deletions src/Adapter/Posix.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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";
Expand All @@ -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';
}

Expand All @@ -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';
}

Expand Down Expand Up @@ -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;
}
}
5 changes: 0 additions & 5 deletions src/Adapter/Virtual.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,10 +13,6 @@

/**
* Virtual buffer adapter
*
* @category Zend
* @package Zend_Console
* @subpackage Adapter
*/
class Virtual extends AbstractAdapter
{
Expand Down
6 changes: 0 additions & 6 deletions src/Adapter/Windows.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@
* @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;
use Zend\Console\Exception;

/**
* @category Zend
* @package Zend_Console
* @subpackage Adapter
*/
class Windows extends Virtual
{
/**
Expand Down
5 changes: 0 additions & 5 deletions src/Adapter/WindowsAnsicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down
5 changes: 0 additions & 5 deletions src/Charset/Ascii.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 0 additions & 4 deletions src/Charset/AsciiExtended.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down
5 changes: 0 additions & 5 deletions src/Charset/CharsetInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
4 changes: 0 additions & 4 deletions src/Charset/DECSG.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down
4 changes: 0 additions & 4 deletions src/Charset/Utf8.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down
4 changes: 0 additions & 4 deletions src/Charset/Utf8Heavy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down
Loading

0 comments on commit 7783b57

Please sign in to comment.