diff --git a/console.php b/console.php index 76a6a92..f62095f 100644 --- a/console.php +++ b/console.php @@ -118,6 +118,9 @@ class console // {{{ { exec ("stty $this->initSttyState"); + $this->colorReset (); + $this->textUnderline (false); + $this->textBold (false); } // }}} @@ -859,6 +862,69 @@ class console } // }}} + /** Set the text color + * @param integer $colorNum The color number to use + */ + public function colorText ($colorNum) + // {{{ + { + if (! is_int ($colorNum)) + $this->consoleException ("ColorNum provided to colorText is not an ". + "integer"); + echo "\033[38;5;${colorNum}m"; + } + // }}} + + /** Set the background text color + * @param integer $colorNum The color number to use + */ + public function colorBackgroundText ($colorNum) + // {{{ + { + if (! is_int ($colorNum)) + $this->consoleException ("ColorNum provided to colorBackgroundText not ". + "an integer"); + echo "\033[48;5;${colorNum}m"; + } + // }}} + + /** Reset the colors + */ + public function colorReset () + // {{{ + { + echo "\033[0m"; + } + // }}} + + /** Underline the text + * @param boolean $underline True to underline, false to remove the underline + */ + public function textUnderline ($underline) + // {{{ + { + if ($underline === false) + $underline = 2; + else + $underline = ""; + echo "\033[${underline}4m"; + } + // }}} + + /** Bold the text + * @param boolean $bold True to bold, false to remove the bold + */ + public function textBold ($bold) + // {{{ + { + if ($bold === false) + $bold = 2; + else + $bold = ""; + echo "\033[${bold}1m"; + } + // }}} + /** This function return an array with each char, but supports UTF-8 * @param string $string The string to explode * @param integer $split_length The number of chars in each split