travail / term-ansicolor
travail/term-ansicolor
This package is auto-updated.
Last update: 2024-09-14 19:42:04 UTC
README
名称
\Term\ANSIColor - 使用ANSI转义序列进行彩色屏幕输出。
概要
use \Term\ANSIColor; require_once '/path/to/vendor/autoload.php'; // Get a colored string echo ANSIColor::colored("Yellow text\n", 'yellow'); echo ANSIColor::colored("Normal text on magenta\n", null, 'magenta'); echo ANSIColor::colored("Underscored text\n", null, null, 'underscore'); echo ANSIColor::colored("Red on cyan\n", 'red', 'cyan'); echo ANSIColor::colored("Blinking blue text on light gray\n", 'blue', 'light_gray', 'blink'); // Get a colored string by an alias ANSIColor::setAlias('debug', 'red', 'light_gray'); echo ANSIColor::colored("[DEBUG] Debug message in red on light_gray\n" , 'debug'); ANSIColor::setAlias('error', 'red', 'black'); echo ANSIColor::colored("[ERROR] Error message in red on black\n" , 'error');
安装
要将此软件包安装到您的项目中,请通过composer添加以下片段到您的composer.json
文件。然后运行composer install
。
"require": {
"travail/term-ansicolor": "dev-master"
}
如果您想从github安装,请添加以下内容
"repositories": [
{
"type": "vcs",
"url": "git@github.com:travail/php-Term-ANSIColor.git"
}
]
方法
colored
string colored(string $text, string $foreground_color, string $background_color, string $attribute)
返回一个彩色文本,或者如果传递了不存在的$foreground_color
、$background_color
或$attribute
,则返回Exception
。
setAlias
array setAlias(string $alias, string $foreground_color, string $background_color, string $attribute)
为标准颜色和属性设置别名。
getAlias
array getAlias([string $alias = ''])
如果传递了$alias
,则返回一个可用的别名数组;如果没有传递$alias
,则返回所有别名数组,或者如果传递了不存在的$alias
,则返回Exception
。
getForegroundColors
array getForegroundColors(void)
返回定义的前景色数组。
array(
'black' => '0;30',
'dark_gray' => '1;30',
'blue' => '0;34',
'light_blue' => '1;34',
'green' => '0;32',
'light_green' => '1;32',
'cyan' => '0;36',
'light_cyan' => '1;36',
'red' => '0;31',
'light_red' => '1;31',
'purple' => '0;35',
'light_purple'=> '1;35',
'brown' => '0;33',
'yellow' => '1;33',
'light_gray' => '0;37',
'white' => '1;37',
);
getBackgroundColors
array getBackgroundColors(void)
返回定义的背景色数组。
array(
'black' => '40',
'red' => '41',
'green' => '42',
'yellow' => '43',
'blue' => '44',
'magenta' => '45',
'cyan' => '46',
'light_gray' => '47',
);
getAttributes
array getAttributes(void)
返回定义的属性数组。
array(
'normal' => '0',
'bold' => '1',
'underscore' => '4',
'blink' => '5',
'reverse' => '7',
'concealed' => '8',
);
作者
travail
许可
此库是免费软件。您可以在与PHP相同的条款下重新分发或修改它。