Skip to content

Commit ce9dfc3

Browse files
committed
some modofy
1 parent 0ebda79 commit ce9dfc3

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

src/color/Lite.php renamed to src/color/LiteColor.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
*/
88

99
namespace inhere\console\color;
10+
use inhere\console\Helper;
1011

1112
/**
12-
* Class Lite
13+
* Class LiteColor
1314
* @package inhere\console\color
1415
*/
15-
class Lite
16+
class LiteColor
1617
{
1718
const NORMAL = 0;
1819

@@ -71,11 +72,14 @@ class Lite
7172
/**
7273
* @param $text
7374
* @param string|int|array $style
74-
* @param bool $return
7575
* @return string
7676
*/
77-
public static function render($text, $style = self::NORMAL, $return = true)
77+
public static function render($text, $style = self::NORMAL)
7878
{
79+
if (!Helper::isSupportColor()) {
80+
return $text;
81+
}
82+
7983
if(is_string($style)) {
8084
$out = isset(self::$styles[$style]) ? self::$styles[$style] : self::NORMAL;
8185
} elseif (is_int($style)) {
@@ -91,13 +95,7 @@ public static function render($text, $style = self::NORMAL, $return = true)
9195
// $result = chr(27). "$out{$text}" . chr(27) . chr(27) . "[0m". chr(27);
9296
$result = "\033[{$out}m{$text}\033[0m";
9397

94-
if($return ){
95-
return $result;
96-
}
97-
98-
echo $result;
99-
100-
return true;
98+
return $result;
10199
}
102100

103101
}

src/color/Style.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ final class Style
2525
*/
2626
const BG_BASE = 40;
2727

28+
// color
29+
const BLACK = 0;
30+
const RED = 1;
31+
const GREEN = 2;
32+
const BROWN = 3;
33+
const BLUE = 4;
34+
const CYAN = 6;
35+
const WHITE = 7;
36+
const NORMAL = 9;
37+
38+
// color option
39+
const BOLD = 1; // 加粗
40+
const FUZZY = 2; // 模糊(不是所有的终端仿真器都支持)
41+
const ITALIC = 3; // 斜体(不是所有的终端仿真器都支持)
42+
const UNDERSCORE = 4; // 下划线
43+
const BLINK = 5; // 闪烁
44+
const REVERSE = 7; // 颠倒的 交换背景色与前景色
45+
2846
//////////////////////////////////////////// Color Style ////////////////////////////////////////////
2947

3048
/**
@@ -39,7 +57,7 @@ final class Style
3957
'magenta' => 5, // 洋红色 洋红 品红色
4058
'cyan' => 6, // 青色 青绿色 蓝绿色
4159
'white' => 7,
42-
'default' => 9
60+
'normal' => 9
4361
);
4462

4563
/**

0 commit comments

Comments
 (0)