56 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			56 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 CYAN          = 5;
 | 
						|
    const MAGENTA       = 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_CYAN       = 13;
 | 
						|
    const BR_MAGENTA    = 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;
 | 
						|
 | 
						|
    }
 | 
						|
 | 
						|
} |