Source for file Colour.php
Documentation is available at Colour.php
class PHP_Shell_Extensions_Colour implements PHP_Shell_Extension {
static protected $instance;
const C_RESET = "\033[0m";
const C_BLACK = "\033[0;30m";
const C_RED = "\033[0;31m";
const C_GREEN = "\033[0;32m";
const C_BROWN = "\033[0;33m";
const C_BLUE = "\033[0;34m";
const C_PURPLE = "\033[0;35m";
const C_CYAN = "\033[0;36m";
const C_LIGHT_GRAY = "\033[0;37m";
const C_GRAY = "\033[1;30m";
const C_LIGHT_RED = "\033[1;31m";
const C_LIGHT_GREEN = "\033[1;32m";
const C_YELLOW = "\033[1;33m";
const C_LIGHT_BLUE = "\033[1;34m";
const C_LIGHT_PURPLE = "\033[1;35m";
const C_LIGHT_CYAN = "\033[1;36m";
const C_WHITE = "\033[1;37m";
* @see registerColourScheme
protected $colour_scheme;
public function register () {
$opt = PHP_Shell_Options ::getInstance ();
$opt->registerOption ("background", $this, "optSetBackground");
$opt->registerOptionAlias ("bg", "background");
$this->registerColourScheme (
"default" => "", "value" => "",
"exception" => "", "reset" => ""));
$this->registerColourScheme (
"default" => self ::C_YELLOW ,
"value" => self ::C_WHITE ,
"exception" => self ::C_PURPLE ));
$this->registerColourScheme (
"default" => self ::C_BLACK ,
"exception" => self ::C_RED ));
public function optSetBackground ($key, $value) {
print (':set '. $key. ' needs a colour-scheme, e.g. :set '. $key. '=dark');
if (false == $this->applyColourScheme ($value)) {
print ('setting colourscheme failed: colourscheme '. $value. ' is unknown');
* get a colour for the shell
* @param string $type one of (value|exception|reset|default)
* @return string a colour string or a empty string
public function getColour ($type) {
return isset ($this->colour[$type]) ? $this->colour[$type] : '';
* apply a colour scheme to the current shell
* @param string $scheme name of the scheme
* @return false if colourscheme is not known, otherwise true
public function applyColourScheme ($scheme) {
if (!isset ($this->colour_scheme[$scheme])) return false;
$this->colour = $this->colour_scheme[$scheme];
* registers a colour scheme
* @param string $scheme name of the colour scheme
* @param array a array of colours
public function registerColourScheme ($scheme, $colours) {
/* set a reset colour if it is not supplied from the outside */
if (!isset ($colours["reset"])) $colours["reset"] = self ::C_RESET;
$this->colour_scheme[$scheme] = $colours;
Documentation generated on Mon, 11 Mar 2019 14:40:32 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|