11<?php declare (strict_types=1 );
22/**
3- * Created by PhpStorm.
3+ * This file is part of toolkit/cli-utils.
4+ *
5+ * @link https://github.com/inhere
6+ * @author https://github.com/inhere
7+ * @license MIT
48 */
59
610namespace Toolkit \Cli ;
@@ -35,38 +39,38 @@ class ColorCode
3539 public const BG_EXTRA = 100 ;
3640
3741 // color
38- public const BLACK = 'black ' ;
42+ public const BLACK = 'black ' ;
3943
40- public const RED = 'red ' ;
44+ public const RED = 'red ' ;
4145
42- public const GREEN = 'green ' ;
46+ public const GREEN = 'green ' ;
4347
44- public const YELLOW = 'yellow ' ; // BROWN
48+ public const YELLOW = 'yellow ' ; // BROWN
4549
46- public const BLUE = 'blue ' ;
50+ public const BLUE = 'blue ' ;
4751
4852 public const MAGENTA = 'magenta ' ;
4953
50- public const CYAN = 'cyan ' ;
54+ public const CYAN = 'cyan ' ;
5155
52- public const WHITE = 'white ' ;
56+ public const WHITE = 'white ' ;
5357
54- public const NORMAL = 'normal ' ;
58+ public const NORMAL = 'normal ' ;
5559
5660 // color option
57- public const BOLD = 'bold ' ; // 加粗
61+ public const BOLD = 'bold ' ; // 加粗
5862
59- public const FUZZY = 'fuzzy ' ; // 模糊(不是所有的终端仿真器都支持)
63+ public const FUZZY = 'fuzzy ' ; // 模糊(不是所有的终端仿真器都支持)
6064
61- public const ITALIC = 'italic ' ; // 斜体(不是所有的终端仿真器都支持)
65+ public const ITALIC = 'italic ' ; // 斜体(不是所有的终端仿真器都支持)
6266
6367 public const UNDERSCORE = 'underscore ' ; // 下划线
6468
65- public const BLINK = 'blink ' ; // 闪烁
69+ public const BLINK = 'blink ' ; // 闪烁
6670
67- public const REVERSE = 'reverse ' ; // 颠倒的 交换背景色与前景色
71+ public const REVERSE = 'reverse ' ; // 颠倒的 交换背景色与前景色
6872
69- public const CONCEALED = 'concealed ' ; // 隐匿的
73+ public const CONCEALED = 'concealed ' ; // 隐匿的
7074
7175 /**
7276 * @var array Known color list
@@ -87,13 +91,13 @@ class ColorCode
8791 * @var array Known option code
8892 */
8993 public const KNOWN_OPTIONS = [
90- 'bold ' => self ::BOLD , // 加粗
91- 'fuzzy ' => self ::FUZZY , // 模糊(不是所有的终端仿真器都支持)
92- 'italic ' => self ::ITALIC , // 斜体(不是所有的终端仿真器都支持)
93- 'underscore ' => self ::UNDERSCORE , // 下划线
94- 'blink ' => self ::BLINK , // 闪烁
95- 'reverse ' => self ::REVERSE , // 颠倒的 交换背景色与前景色
96- 'concealed ' => self ::CONCEALED , // 隐匿的
94+ 'bold ' => Color ::BOLD , // 加粗
95+ 'fuzzy ' => Color ::FUZZY , // 模糊(不是所有的终端仿真器都支持)
96+ 'italic ' => Color ::ITALIC , // 斜体(不是所有的终端仿真器都支持)
97+ 'underscore ' => Color ::UNDERSCORE , // 下划线
98+ 'blink ' => Color ::BLINK , // 闪烁
99+ 'reverse ' => Color ::REVERSE , // 颠倒的 交换背景色与前景色
100+ 'concealed ' => Color ::CONCEALED , // 隐匿的
97101 ];
98102
99103 /**
@@ -140,7 +144,7 @@ public static function make($fg = '', $bg = '', array $options = [], bool $extra
140144 * @throws InvalidArgumentException
141145 * @throws RuntimeException
142146 */
143- public static function fromString ($ string )
147+ public static function fromString (string $ string )
144148 {
145149 $ extra = false ;
146150 $ options = [];
@@ -189,35 +193,26 @@ public function __construct($fg = '', $bg = '', array $options = [], bool $extra
189193 {
190194 if ($ fg ) {
191195 if (!isset (self ::KNOWN_COLORS [$ fg ])) {
192- throw new InvalidArgumentException (sprintf (
193- 'Invalid foreground color "%1$s" [%2$s] ' ,
194- $ fg ,
195- implode (', ' , self ::getKnownColors ())
196- ));
196+ throw new InvalidArgumentException (sprintf ('Invalid foreground color "%1$s" [%2$s] ' , $ fg ,
197+ implode (', ' , self ::getKnownColors ())));
197198 }
198199
199200 $ this ->fgColor = ($ extra ? self ::FG_EXTRA : self ::FG_BASE ) + self ::KNOWN_COLORS [$ fg ];
200201 }
201202
202203 if ($ bg ) {
203204 if (!isset (self ::KNOWN_COLORS [$ bg ])) {
204- throw new InvalidArgumentException (sprintf (
205- 'Invalid background color "%1$s" [%2$s] ' ,
206- $ bg ,
207- implode (', ' , self ::getKnownColors ())
208- ));
205+ throw new InvalidArgumentException (sprintf ('Invalid background color "%1$s" [%2$s] ' , $ bg ,
206+ implode (', ' , self ::getKnownColors ())));
209207 }
210208
211209 $ this ->bgColor = ($ extra ? self ::BG_EXTRA : self ::BG_BASE ) + self ::KNOWN_COLORS [$ bg ];
212210 }
213211
214212 foreach ($ options as $ option ) {
215213 if (!isset (self ::KNOWN_OPTIONS [$ option ])) {
216- throw new InvalidArgumentException (sprintf (
217- 'Invalid option "%1$s" [%2$s] ' ,
218- $ option ,
219- implode (', ' , self ::getKnownOptions ())
220- ));
214+ throw new InvalidArgumentException (sprintf ('Invalid option "%1$s" [%2$s] ' , $ option ,
215+ implode (', ' , self ::getKnownOptions ())));
221216 }
222217
223218 $ this ->options [] = $ option ;
@@ -242,6 +237,8 @@ public function toString(): string
242237
243238 /**
244239 * Get the translated color code.
240+ *
241+ * @return string
245242 */
246243 public function toStyle (): string
247244 {
0 commit comments