2016-11-01 14:12:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace NoccyLabs\Shell;
|
|
|
|
|
|
|
|
class Style
|
|
|
|
{
|
|
|
|
const NONE = null;
|
|
|
|
|
|
|
|
const BLACK = 0;
|
|
|
|
const RED = 1;
|
|
|
|
const GREEN = 2;
|
|
|
|
const YELLOW = 3;
|
|
|
|
const BLUE = 4;
|
2017-01-23 22:28:12 +00:00
|
|
|
const MAGENTA = 5;
|
|
|
|
const CYAN = 6;
|
2016-11-01 14:12:11 +00:00
|
|
|
const WHITE = 7;
|
2017-01-23 22:28:12 +00:00
|
|
|
|
2016-11-01 14:12:11 +00:00
|
|
|
const GRAY = 8;
|
|
|
|
const BR_RED = 9;
|
|
|
|
const BR_GREEN = 10;
|
|
|
|
const BR_YELLOW = 11;
|
|
|
|
const BR_BLUE = 12;
|
2017-01-23 22:28:12 +00:00
|
|
|
const BR_MAGENTA = 13;
|
|
|
|
const BR_CYAN = 14;
|
2016-11-01 14:12:11 +00:00
|
|
|
const BR_WHITE = 15;
|
|
|
|
|
|
|
|
const A_INTENSE = 1;
|
|
|
|
const A_UNDERLINE = 4;
|
|
|
|
const A_INVERSE = 7;
|
|
|
|
|
|
|
|
protected $fg = self::NONE;
|
|
|
|
|
|
|
|
protected $bg = self::NONE;
|
|
|
|
|
|
|
|
public function __construct($fg=self::NONE, $bg=self::NONE)
|
|
|
|
{
|
|
|
|
$this->fg = $fg;
|
|
|
|
$this->bg = $bg;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __invoke($string)
|
|
|
|
{
|
|
|
|
$pre = null; $post = null;
|
|
|
|
if ($this->fg !== self::NONE) {
|
|
|
|
$pre.= "\e[".(($this->fg > 7)?(90+($this->fg-8)):(30+$this->fg))."m";
|
|
|
|
$post.= "\e[39m";
|
|
|
|
}
|
|
|
|
if ($this->bg !== self::NONE) {
|
|
|
|
$pre.= "\e[".(($this->bg > 7)?(100+($this->bg-8)):(40+$this->bg))."m";
|
|
|
|
$post.= "\e[49m";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $pre . $string . $post;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|