Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| CliOutput | |
0.00% |
0 / 18 |
|
0.00% |
0 / 4 |
182 | |
0.00% |
0 / 1 |
| setColor | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
30 | |||
| setUseColor | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| write | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
42 | |||
| writeLine | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Dynart\Micro; |
| 4 | |
| 5 | class CliOutput { |
| 6 | |
| 7 | const COLOR_OFF = "\033[0m"; |
| 8 | |
| 9 | const BLACK = 0; |
| 10 | const DARK_RED = 1; |
| 11 | const DARK_GREEN = 2; |
| 12 | const DARK_YELLOW = 3; |
| 13 | const DARK_BLUE = 4; |
| 14 | const DARK_PURPLE = 5; |
| 15 | const DARK_CYAN = 6; |
| 16 | const GRAY = 7; |
| 17 | const DARK_GRAY = 8; |
| 18 | const RED = 9; |
| 19 | const GREEN = 10; |
| 20 | const YELLOW = 11; |
| 21 | const BLUE = 12; |
| 22 | const PURPLE = 13; |
| 23 | const CYAN = 14; |
| 24 | const WHITE = 15; |
| 25 | |
| 26 | protected $color = null; |
| 27 | protected $bgColor = null; |
| 28 | protected $useColor = true; |
| 29 | |
| 30 | public function setColor($color, $bgColor = null) { |
| 31 | if (is_int($color)) { |
| 32 | $this->color = "\033[" . ($color < 8 ? 30 + $color : 90 + $color - 8) . "m"; |
| 33 | } else { |
| 34 | $this->color = null; |
| 35 | } |
| 36 | if (is_int($bgColor)) { |
| 37 | $this->bgColor = "\033[".($bgColor < 8 ? 40 + $bgColor : 100 + $bgColor - 8)."m"; |
| 38 | } else { |
| 39 | $this->bgColor = null; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | public function setUseColor(bool $value): void { |
| 44 | $this->useColor = $value; |
| 45 | } |
| 46 | |
| 47 | public function write(string $text) { |
| 48 | if ($this->useColor) { |
| 49 | if ($this->bgColor) { |
| 50 | echo $this->bgColor; |
| 51 | } |
| 52 | if ($this->color) { |
| 53 | echo $this->color; |
| 54 | } |
| 55 | echo $text; |
| 56 | if ($this->color || $this->bgColor) { |
| 57 | echo self::COLOR_OFF; |
| 58 | } |
| 59 | } else { |
| 60 | echo $text; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | public function writeLine(string $text) { |
| 65 | $this->write($text); |
| 66 | echo "\n"; |
| 67 | } |
| 68 | } |