Skip to content

Commit 667bb0a

Browse files
committed
update some class structure
1 parent ce9dfc3 commit 667bb0a

File tree

7 files changed

+157
-165
lines changed

7 files changed

+157
-165
lines changed

examples/HomeController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function colorCommand()
3535
return 0;
3636
}
3737

38-
$styles = $this->output->getColor()->getStyleNames();
38+
$styles = $this->output->getStyle()->getStyleNames();
3939
$this->write('normal text output');
4040

4141
$this->write('color text output');
File renamed without changes.

src/io/Output.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace inhere\console\io;
1010

1111
use inhere\console\Helper;
12-
use inhere\console\color\Color;
12+
use inhere\console\style\Style;
1313
use inhere\console\utils\Interact;
1414

1515
/**
@@ -33,9 +33,9 @@ class Output
3333
/**
3434
* 控制台窗口(字体/背景)颜色添加处理
3535
* window colors
36-
* @var Color
36+
* @var Style
3737
*/
38-
protected $color;
38+
protected $style;
3939

4040
/////////////////////////////////////////////////////////////////
4141
/// Output Message
@@ -116,44 +116,44 @@ public function table(array $data, $title = 'Info List', $showBorder = true)
116116
* @param string $style
117117
* @param int|boolean $quit If is int, setting it is exit code.
118118
*/
119-
public function block($messages, $type = 'MESSAGE', $style = 'default', $quit = false)
119+
public function block($messages, $type = 'MESSAGE', $style = Style::NORMAL, $quit = false)
120120
{
121121
Interact::block($messages, $type, $style, $quit);
122122
}
123123

124124
public function primary($messages, $quit = false)
125125
{
126-
$this->block($messages, 'IMPORTANT', 'primary', $quit);
126+
$this->block($messages, 'IMPORTANT', Style::PRIMARY, $quit);
127127
}
128128

129129
public function success($messages, $quit = false)
130130
{
131-
$this->block($messages, 'SUCCESS', 'success', $quit);
131+
$this->block($messages, 'SUCCESS', Style::SUCCESS, $quit);
132132
}
133133

134134
public function info($messages, $quit = false)
135135
{
136-
$this->block($messages, 'INFO', 'info', $quit);
136+
$this->block($messages, 'INFO', Style::INFO, $quit);
137137
}
138138

139139
public function warning($messages, $quit = false)
140140
{
141-
$this->block($messages, 'WARNING', 'warning', $quit);
141+
$this->block($messages, 'WARNING', Style::WARNING, $quit);
142142
}
143143

144144
public function danger($messages, $quit = false)
145145
{
146-
$this->block($messages, 'DANGER', 'danger', $quit);
146+
$this->block($messages, 'DANGER', Style::DANGER, $quit);
147147
}
148148

149149
public function error($messages, $quit = false)
150150
{
151-
$this->block($messages, 'ERROR', 'error', $quit);
151+
$this->block($messages, 'ERROR', Style::ERROR, $quit);
152152
}
153153

154154
public function notice($messages, $quit = false)
155155
{
156-
$this->block($messages, 'NOTICE', 'comment', $quit);
156+
$this->block($messages, 'NOTICE', Style::COMMENT, $quit);
157157
}
158158

159159
/**
@@ -184,7 +184,7 @@ public function write($messages = '', $nl = true, $quit = false)
184184
$messages = implode($nl ? PHP_EOL : '', $messages);
185185
}
186186

187-
$messages = $this->getColor()->format($messages);
187+
$messages = $this->getStyle()->format($messages);
188188

189189
if (false === @fwrite($this->outputStream, $messages . ($nl ? PHP_EOL : ''))) {
190190
// should never happen
@@ -209,7 +209,7 @@ public function write($messages = '', $nl = true, $quit = false)
209209
*/
210210
public function err($text = '', $nl = true)
211211
{
212-
$text = $this->getColor()->format($text);
212+
$text = $this->getStyle()->format($text);
213213

214214
fwrite($this->errorStream, $text . ($nl ? "\n" : null));
215215

@@ -221,15 +221,15 @@ public function err($text = '', $nl = true)
221221
/////////////////////////////////////////////////////////////////
222222

223223
/**
224-
* @return Color
224+
* @return Style
225225
*/
226-
public function getColor()
226+
public function getStyle()
227227
{
228-
if (!$this->color) {
229-
$this->color = new Color;
228+
if (!$this->style) {
229+
$this->style = new Style;
230230
}
231231

232-
return $this->color;
232+
return $this->style;
233233
}
234234

235235
/**

src/color/Style.php renamed to src/style/Color.php

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
* @todo unused
77
*/
88

9-
namespace inhere\console\color;
9+
namespace inhere\console\style;
1010

1111
/**
12-
* @link https://github.com/ventoviro/windwalker-IO
12+
* Class Color
13+
* @package inhere\console\style
1314
*/
14-
final class Style
15+
final class Color
1516
{
1617
/**
1718
* Foreground base value
@@ -26,22 +27,23 @@ final class Style
2627
const BG_BASE = 40;
2728

2829
// 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;
30+
const BLACK = 'black';
31+
const RED = 'red';
32+
const GREEN = 'green';
33+
const YELLOW = 'yellow'; // BROWN
34+
const BLUE = 'blue';
35+
const MAGENTA = 'magenta';
36+
const CYAN = 'cyan';
37+
const WHITE = 'white';
38+
const NORMAL = 'normal';
3739

3840
// 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; // 颠倒的 交换背景色与前景色
41+
const BOLD = 'bold'; // 加粗
42+
const FUZZY = 'fuzzy'; // 模糊(不是所有的终端仿真器都支持)
43+
const ITALIC = 'italic'; // 斜体(不是所有的终端仿真器都支持)
44+
const UNDERSCORE = 'underscore'; // 下划线
45+
const BLINK = 'blink'; // 闪烁
46+
const REVERSE = 'reverse'; // 颠倒的 交换背景色与前景色
4547

4648
//////////////////////////////////////////// Color Style ////////////////////////////////////////////
4749

@@ -57,7 +59,7 @@ final class Style
5759
'magenta' => 5, // 洋红色 洋红 品红色
5860
'cyan' => 6, // 青色 青绿色 蓝绿色
5961
'white' => 7,
60-
'normal' => 9
62+
'normal' => 9,
6163
);
6264

6365
/**
@@ -185,13 +187,13 @@ public function __construct($fg = '', $bg = '', array $options = [])
185187
*/
186188
public function __toString()
187189
{
188-
return $this->toString();
190+
return $this->toStyle();
189191
}
190192

191193
/**
192194
* Get the translated color code.
193195
*/
194-
public function toString()
196+
public function toStyle()
195197
{
196198
$values = [];
197199

src/color/LiteColor.php renamed to src/style/LiteStyle.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
* Time: 下午7:45
77
*/
88

9-
namespace inhere\console\color;
9+
namespace inhere\console\style;
10+
1011
use inhere\console\Helper;
1112

1213
/**
13-
* Class LiteColor
14+
* Class LiteStyle
1415
* @package inhere\console\color
1516
*/
16-
class LiteColor
17+
class LiteStyle
1718
{
1819
const NORMAL = 0;
1920

@@ -74,6 +75,10 @@ class LiteColor
7475
* @param string|int|array $style
7576
* @return string
7677
*/
78+
public static function add($text, $style = self::NORMAL)
79+
{
80+
return self::render($text, $style);
81+
}
7782
public static function render($text, $style = self::NORMAL)
7883
{
7984
if (!Helper::isSupportColor()) {

0 commit comments

Comments
 (0)