Skip to content

Commit

Permalink
some modofy
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed May 11, 2017
1 parent 0ebda79 commit ce9dfc3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
20 changes: 9 additions & 11 deletions src/color/Lite.php → src/color/LiteColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
*/

namespace inhere\console\color;
use inhere\console\Helper;

/**
* Class Lite
* Class LiteColor
* @package inhere\console\color
*/
class Lite
class LiteColor
{
const NORMAL = 0;

Expand Down Expand Up @@ -71,11 +72,14 @@ class Lite
/**
* @param $text
* @param string|int|array $style
* @param bool $return
* @return string
*/
public static function render($text, $style = self::NORMAL, $return = true)
public static function render($text, $style = self::NORMAL)
{
if (!Helper::isSupportColor()) {
return $text;
}

if(is_string($style)) {
$out = isset(self::$styles[$style]) ? self::$styles[$style] : self::NORMAL;
} elseif (is_int($style)) {
Expand All @@ -91,13 +95,7 @@ public static function render($text, $style = self::NORMAL, $return = true)
// $result = chr(27). "$out{$text}" . chr(27) . chr(27) . "[0m". chr(27);
$result = "\033[{$out}m{$text}\033[0m";

if($return ){
return $result;
}

echo $result;

return true;
return $result;
}

}
20 changes: 19 additions & 1 deletion src/color/Style.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ final class Style
*/
const BG_BASE = 40;

// color
const BLACK = 0;
const RED = 1;
const GREEN = 2;
const BROWN = 3;
const BLUE = 4;
const CYAN = 6;
const WHITE = 7;
const NORMAL = 9;

// color option
const BOLD = 1; // 加粗
const FUZZY = 2; // 模糊(不是所有的终端仿真器都支持)
const ITALIC = 3; // 斜体(不是所有的终端仿真器都支持)
const UNDERSCORE = 4; // 下划线
const BLINK = 5; // 闪烁
const REVERSE = 7; // 颠倒的 交换背景色与前景色

//////////////////////////////////////////// Color Style ////////////////////////////////////////////

/**
Expand All @@ -39,7 +57,7 @@ final class Style
'magenta' => 5, // 洋红色 洋红 品红色
'cyan' => 6, // 青色 青绿色 蓝绿色
'white' => 7,
'default' => 9
'normal' => 9
);

/**
Expand Down

0 comments on commit ce9dfc3

Please sign in to comment.