33 lines
906 B
PHP
33 lines
906 B
PHP
<?php
|
|
|
|
namespace Mcnd\CLI\Lib;
|
|
|
|
trait ColorMappingTrait
|
|
{
|
|
public static function mapFrom(string $name) : ? self
|
|
{
|
|
return [
|
|
'black' => self::Black,
|
|
'red' => self::Red,
|
|
'green' => self::Green,
|
|
'yellow' => self::Yellow,
|
|
'blue' => self::Blue,
|
|
'magenta' => self::Magenta,
|
|
'cyan' => self::Cyan,
|
|
'lightgray' => self::LightGray,
|
|
'darkgray' => self::DarkGray,
|
|
'lightred' => self::LightRed,
|
|
'lightgreen' => self::LightGreen,
|
|
'lightyellow' => self::LightYellow,
|
|
'lightblue' => self::LightBlue,
|
|
'lightmagenta' => self::LightMagenta,
|
|
'lightcyan' => self::LightCyan,
|
|
'white' => self::White,
|
|
][$name] ?? null;
|
|
}
|
|
|
|
public function output() : string
|
|
{
|
|
return "\e[{$this->value}m";
|
|
}
|
|
} |