From 429caff3475e4e42619bdebe9f45ff5ea3a97c18 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Sun, 8 Jul 2018 18:23:48 +0000 Subject: [PATCH] console : Add color support console : Add bold and underline text support git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4277 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- console.php | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) 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