php-shell/lib/Style.php
Christopher Vagnetoft 5a45ca9c46 Rewrite, cleanup and bugfixes
* More events added, constants cleaned up
* Events now handled using noccylabs/tinyevent
* Fixed magenta/cyan mixup in style
* Fixed LineRead not resetting history pointer on command
2017-01-23 23:28:12 +01:00

57 lines
1.3 KiB
PHP

<?php
namespace NoccyLabs\Shell;
class Style
{
const NONE = null;
const BLACK = 0;
const RED = 1;
const GREEN = 2;
const YELLOW = 3;
const BLUE = 4;
const MAGENTA = 5;
const CYAN = 6;
const WHITE = 7;
const GRAY = 8;
const BR_RED = 9;
const BR_GREEN = 10;
const BR_YELLOW = 11;
const BR_BLUE = 12;
const BR_MAGENTA = 13;
const BR_CYAN = 14;
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;
}
}