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
This commit is contained in:
66
console.php
66
console.php
@@ -118,6 +118,9 @@ class console
|
|||||||
// {{{
|
// {{{
|
||||||
{
|
{
|
||||||
exec ("stty $this->initSttyState");
|
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
|
/** This function return an array with each char, but supports UTF-8
|
||||||
* @param string $string The string to explode
|
* @param string $string The string to explode
|
||||||
* @param integer $split_length The number of chars in each split
|
* @param integer $split_length The number of chars in each split
|
||||||
|
|||||||
Reference in New Issue
Block a user